How to Remove a Page Manually in the Database Using SQL Commands

Still need help?

The Atlassian Community is here for you.

Ask the community

Scenario

These SQL commands might be helpful in order to remove pages which are not working or causing instability to confluence. Please try to remove the page from confluence interface first before attempting these.


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.

Resolution

Please note this queries will only work when:

  • The title of the page has not changed across versions.
  • There is no other page with the same title in your Confluence instance.

Please create a full database backup prior to run any queries against your database

  1. First, you must get the page name you would like to remove. Simply copy the page name exactly the same way is written.
  2. Run the SQL commands below, 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.

    delete from USERCONTENT_RELATION where TARGETCONTENTID in (select CONTENTID from CONTENT where title like "<Page_title>");
    delete from links where contentid in (select contentid from content where title like "<Page_title>");
    delete from attachmentdata where attachmentid in (SELECT c.contentid FROM content c where title like "<Page_title>");
    DELETE FROM contentproperties WHERE contentid IN (SELECT contentid FROM content WHERE contentid IN (SELECT contentid FROM content WHERE contenttype = 'ATTACHMENT' AND pageid IN (SELECT c.contentid FROM content c where title like "<Page_title>")));
    delete from notifications where contentid in (select contentid from content where title like "<Page_title>");
    delete from confancestors where descendentid in (select contentid from content where title like "<Page_title>");
    delete from bodycontent where contentid in (select contentid from content where title like "<Page_title>");
    delete from OS_PROPERTYENTRY where entity_id in (select contentid from content where title like "<Page_title>");
    delete from CONTENT_LABEL where CONTENTID in (select contentid from content where title like "<Page_title>");
    delete from CONTENTPROPERTIES where CONTENTID in (select contentid from content where title like "<Page_title>");
    DELETE FROM content_label WHERE contentid IN (SELECT contentid FROM content where title like "<Page_title>");
    Delete from content where prevver in ( select xid from (select c.contentid as xid from content c where title = "<Page_title>") AS x);
    Delete from content where pageid in ( select xid from (select c.contentid as xid from content c where title = "<Page_title>" and prevver is not null) AS x);
    Delete from content where contentid in (select xid from (select c.contentid as xid from content c where pageid in (select contentid from content where title="<Page_title>"))as x);
    Delete from content where contentid in (select xid from (select c.contentid as xid from content c where pageid in (select contentid from content where title="<Page_title>"))as x);
    delete from content where title ="<Page_title>";
    
    
  3. Restart Confluence for the changes to take effect.
  4. Reindex Confluence to remove the page from search index and from links in JIRA issues.

Last modified on Nov 2, 2018

Was this helpful?

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