Bitbucket - DataStoreException: A database error has occurred - index contains unexpected zero page at block
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
Summary
An operation fails (perhaps in the UI) and the following (or something similar) is seen in the logs:
XXXX-XX-XX XX:XX:XX,XXX ERROR [http-nio-7990-exec-74] X555555 *<request_ID> <user> <ip>,<ip> "POST /projects/<proj>/repos/<repo>/pull-requests HTTP/1.1" c.a.s.i.w.pull.PullRequestController Exception occurred
com.atlassian.bitbucket.DataStoreException: A database error has occurred.
...
Caused by: java.sql.BatchUpdateException: Batch entry 7 insert into bb_pr_commit (commit_id, pr_id) values ('<hash>', <value>) was aborted: ERROR: index "idx_bb_pr_commit_commit_id" contains unexpected zero page at block <block_num>
Hint: Please REINDEX it. Call getNextException to see other errors in the batch.
Environment
Postgres
Cause
Index has become corrupt in Postgres DB.
Solution
- Implement a maintenance window
- Perform full backup of database for safety
- Shutdown any application connected to the database
- Reindex the index as the Postgres database hints
- Start applications and ensure the issue has been resolved
In this case it is best to confer with a DBA but the actual SQL used thus far (and in the case of the example above):
REINDEX INDEX idx_bb_pr_commit_commit_id;