Error "duplicate key value violates unique constraint "pk_repository_access"" occurs in Bitbucket Server logs

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

Summary

A database error similar to duplicate key value violates unique constraint "pk_repository_access" occurs in the Bitbucket Server logs, potentially repeatedly.

Environment

Bitbucket Server or Data Center of any version

Diagnosis

The <BitbucketHome>/log/atlassian-bitbucket.log file shows an error such as the following:

1 2022-07-04 11:00:25,910 ERROR [https-jsse-nio-8201-exec-37] username *1OTT051x660x1167503x4 1upwues 128.28.52.10,130.39.32.36 "GET /projects/PROJ/repos/repo/browse/file HTTP/1.1" o.h.e.jdbc.spi.SqlExceptionHelper Batch entry 0 insert into repository_access (last_accessed, repository_id, user_id) values (1656903625885, 14259, 45766) was aborted: ERROR: duplicate key value violates unique constraint "pk_repository_access"

Often this error is logged repeatedly. You may find that the username in that log message is often or always the same, and the user is actually a service or bot user that is used for automated or programmatic access to data in Bitbucket Server.

Cause

This log message is typically the result of concurrent access to a repository by a Bitbucket Server user used in automation or CI/CD solutions, leading to a race condition which attempts to write a row to the database that was already written.

Solution

This log message can safely be ignored as long as the username in the log message is one of a non-human user used in automation. If the username is one of a human user, contact Atlassian Support for analysis.

Updated on March 13, 2025

Still need help?

The Atlassian Community is here for you.