Cannot create new Space due to "duplicate key value violates unique constraint [tablename]_pkey" error
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
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.
*Fisheye および Crucible は除く
要約
New Spaces cannot be created on Confluence, using either the Blank space option or any of the default blueprints.
If this error is preventing new pages from being created as well, there is another similar problem that can cause this - please see:
診断
Checking the atlassian-confluence.log
file, the following message (or similar) can be seen:
2020-05-20 16:06:32,009 ERROR [http-nio-9090-exec-12] [engine.jdbc.spi.SqlExceptionHelper] logExceptions ERROR: duplicate key value violates unique constraint "os_propertyentry_pkey"
Detail: Key (entity_name, entity_id, entity_key)=(confluence_ContentEntityObject, 0, confluence.inline.tasks.sequence.last) already exists.
– referer: https://confluence.url | url: /confluence/rest/create-dialog/1.0/space-blueprint/create-space | traceId: 06628717af98cdcb | userName: username
That error indicates there is a duplicate record on a particular table - this can vary depending on the error message, but it will generally indicate what is the affected table ("os_propertyentry") and the duplicate record ((entity_name, entity_id, entity_key)=(confluence_ContentEntityObject, 0, confluence.inline.tasks.sequence.last)).
原因
There is a duplicate record (or multiple duplicates) on the table mentioned by the error message, which is preventing the new Space from being created, due to this problem on the database side.
ソリューション
Based on this information from the error message on the logs, run a query on the affected database table, to check for any duplicated records.
Stop Confluence and backup your database before running any data manipulation queries, on the Confluence database
Following the example from the above log snippet:
select entity_name, entity_id, entity_key FROM OS_PROPERTYENTRY group by entity_name, entity_id, entity_key having count(*) > 1;
This will return all records on this table that have those duplicated values. For each of the duplicated records from the above query, run another select query, to find all records of that particular kind that are duplicates:
select * FROM OS_PROPERTYENTRY where
(entity_name = 'entity_name_from_above_query' and entity_id = 'entity_id_from_above_query' and entity_key = 'entity_key_from_above_query')
This will return all individual duplicate records. Please compare the duplicate records' values for all columns, as there can be two possible cases here:
- There's a different value (or more) on some particular column
- All values on all columns are identical
For the first case, where there is some differing value on a particular column, remove all of the duplicates except for one. As a general rule, keep the one record that has the highest value, on the column where the different values appear.
For the second case, it's not possible to remove just one of the duplicates, as we can only remove all of the records at once since they're identical. Remove all of the identical records, and then add one of them back manually to the table, afterwards.
Once the duplicated records are dealt with, start Confluence, and creating Spaces should be possible once more.