How to Remove all Previous Versions of a Page Manually in the Database Using SQL Commands
This article only applies to the Atlassian server platform. Learn more about the differences between cloud and server.
- Due to the Bug - CONF-29166Getting issue details... STATUS (Unable to delete blog version), Currently there is no way to delete old version of a blog page through UI.
- You would like to bulk remove previous versions of a page
If you are unsure how to deal with the database, contact your DBA. Make sure to have the database backed up completely before going further. These SQL commands were tested in some environments and they worked as intended, however it might not work in specific cases and newer versions of confluence as new constraints as changes may be done to confluence database structure. As such, a database backup is mandatory in case something goes wrong and you need to revert.
Shut Down Confluence
First, you must get the page name you would like to remove. Simply copy the page name exactly the same way it is written.
- Obtain the number of the current version of the blog post. This is the version that you would like to save. This is obtainable by going to the Blog Page > Tools > Page History > Take note of the "current" version
Run the following queries in the database, in order, since the database contain constraints which will prevent foreign keys and primary keys to be violated if you try to remove one which is mentioned on another table. Replace the <page name> with the actual page name you have copied before.:
create table TEMP_CONTENT like CONTENT; insert into TEMP_CONTENT SELECT * FROM content WHERE TITLE = '<page name>' AND VERSION != <current version number>; delete from links where contentid in (select tc.CONTENTID from TEMP_CONTENT tc); delete from imagedetails where attachmentid in(select attachmentid from attachments where pageid in (select tc.CONTENTID from TEMP_CONTENT tc)); delete from attachments where pageid in (select tc.CONTENTID from TEMP_CONTENT tc); delete from notifications where contentid in (select tc.CONTENTID from TEMP_CONTENT tc); delete from confancestors where descendentid in (select tc.CONTENTID from TEMP_CONTENT tc); delete from bodycontent where contentid in (select tc.CONTENTID from TEMP_CONTENT tc); delete from CONTENT where CONTENTID in (select tc.CONTENTID from TEMP_CONTENT tc); drop table TEMP_CONTENT;
Update this current version to become version 1
UPDATE CONTENT SET VERSION = 1 WHERE TITLE = '<page name>'
Lastly, check if the operation is complete from the following SQL query:
SELECT * FROM CONTENT where TITLE = '<page name>'
* This should return with one value, with version = 1
- Restart Confluence for the changes to take effect.
For example, Below is a situation where a blog with the name "Test 584 Blog" with 5 versions, and you would like to delete all 4 versions before version 5:
Therefore, replace <page name> with Test 584 Blog and replace <current version number> with 5 in the SQL query given in "Workaround" section