How to Remove all Previous Versions of a Page Manually in the Database Using SQL Commands

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.


  • Due to the Bug  CONF-29166 - Getting 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.


  1. Shut Down Confluence

  2. First, you must get the page name you would like to remove. Simply copy the page name exactly the same way it is written.

  3. 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
  4. 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.:

    Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

    (info) The following SQL has not been tested in Confluence 5.7 and above

    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;
  5. Update this current version to become version 1

  6. 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

  7. 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


Last modified on Mar 7, 2017

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.