Rebuilding Ancestor Table fails with duplicate key value violation
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
While rebuilding Ancestor table in Confluence, the following error is noticed.
2020-08-05 21:25:25,308 ERROR [http-nio-8080-exec-4] [confluence.pages.ancestors.HibernatePageAncestorManager] addAncestorsToTableForDescendant Couldn't execute statement
-- referer: https://confluence/admin/permissions/pagepermsadmin.action | url: /admin/permissions/rebuild_ancestor_table.action | traceId: c9365ae3379de36f | userName: admin | action: rebuild_ancestor_table
org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
.
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "idx_16387908_primary"
Detail: Key (descendentid, ancestorposition)=(729820032, 0) already exists.
Resolution
This error can happen due to issues with page tree moves in Confluence resulting in duplicates in Ancestor table. To resolve this issue go through the following steps.
- Stop Confluence on all nodes
- Take backup of the database of Confluence
Delete all contents from the
confancestors
tabletruncate table confancestors;
Start Confluence on only one node
Access Confluence Administration UI
Go to Cog icon > General configuration
Go to Logging and Profiling
Add the following entry and set the logging level to
DEBUG
com.atlassian.confluence.pages.ancestors.HibernatePageAncestorManager
Access
<Confluence Base URL>/admin/permissions/pagepermsadmin.action
and click on the Rebuild ancestor tableFollow the rebuild process through the application log --
atlassian-confluence.log
The following entry indicates the rebuild started
2020-08-07 15:19:19,613 INFO [http-nio-6740-exec-8] [confluence.pages.ancestors.HibernatePageAncestorManager] rebuild Started
The following entry indicates it completed
2020-08-07 15:19:19,637 INFO [http-nio-6740-exec-8] [confluence.pages.ancestors.HibernatePageAncestorManager] rebuild Complete!