Could not add SSH key to Project and Repository
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
Adding SSH key to Project and Repository Access key will fail with following appears in the atlassian-bitbucket.log
2019-02-14 08:20:30,283 ERROR [http-nio-7990-exec-5] @9W2ADRx500x81x0 xxxx xxx.xxx.xxx.xxx "POST /mvc/error500 HTTP/1.1" c.a.s.i.web.ErrorPageController There was an unhandled exception loading [/plugins/servlet/ssh/projects/TEST/keys/add]
com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library:
Database:
- name:PostgreSQL
- version:10.4 (Ubuntu 10.4-0ubuntu0.18.04)
- minor version:4
- major version:10
Driver:
- name:PostgreSQL Native Driver
- version:PostgreSQL 9.4.1211
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "AO_FB71B4_SSH_PUBLIC_KEY_pkey"
Detail: Key ("ENTITY_ID")=(22) already exists.
Cause
Sequence out of sync with the current data
Resolution
- Shutdown Bitbucket Server
Run the following SQL to find the max ID number:
SELECT MAX(public."AO_FB71B4_SSH_PUBLIC_KEY"."ENTITY_ID") FROM public."AO_FB71B4_SSH_PUBLIC_KEY";
From the above result, run the following SQL to fix it:
ALTER SEQUENCE public."AO_FB71B4_SSH_PUBLIC_KEY_ENTITY_ID_seq" RESTART WITH <above result + 1>;
Replace <above result + 1> with the result from Step 3 plus 1
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.
- Restart Bitbucket Server