Duplicate key in table, or Table not found errors in Schema Update section of Startup process

Still need help?

The Atlassian Community is here for you.

Ask the community

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

When upgrading Bamboo, you see INFO and ERROR lines such as the following in the atlassian-bamboo.log

2017-03-28 09:48:22,618 INFO [localhost-startStop-1] [DatabaseMetaData] HHH000262: Table not found: QUICK_FILTERS
...
2017-03-28 09:48:25,175 ERROR [localhost-startStop-1] [SchemaUpdate] HHH000388: Unsuccessful: alter table BRS_CONSUMED_SUBSCRIPTION add constraint FK_l4tpi519m59qhdvh4qx2cjp2n foreign key (CONSUMER_RESULTSUMMARY_ID) references BUILDRESULTSUMMARY (BUILDRESULTSUMMARY_ID)
2017-03-28 09:48:25,175 ERROR [localhost-startStop-1] [SchemaUpdate] Can't write; duplicate key in table '#sql-1620_1fb7d'


Cause

Bamboo does a schema check (and auto correct) on every startup to ensure its integrity. A fixed set of commands are run and afterwards, if the database is configured correctly, the errors may still appear.


Validation

You can validate that the foreign keys are already in the tables to ensure everything is correct as per the error above. And then, you can safely ignore these errors

  1. Locate an unsuccessful alter command in the logs:

    alter table BRS_CONSUMED_SUBSCRIPTION add constraint FK_l4tpi519m59qhdvh4qx2cjp2n foreign key (CONSUMER_RESULTSUMMARY_ID) references BUILDRESULTSUMMARY (BUILDRESULTSUMMARY_ID)
  2. Run the following command in the Bamboo database:

    show create table BRS_CONSUMED_SUBSCRIPTION;
  3. Look for a line in the output referring to the constraint being added:

    ...
    CONSTRAINT `FK_l4tpi519m59qhdvh4qx2cjp2n` FOREIGN KEY (`CONSUMER_RESULTSUMMARY_ID`) REFERENCES `buildresultsummary` (`BUILDRESULTSUMMARY_ID`)
    ...


To check the remaining Table not found errors, you can run queries using the tables listed in the errors. Below are some examples based on database type:

MySQL

show tables like 'QUICK_FILTERS';


PostgreSQL

\dt 'QUICK_FILTERS'


MS SQL

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
           WHERE TABLE_NAME = N'QUICK_FILTERS')
BEGIN
  PRINT 'Table Exists'
END


Oracle

SHOW TABLES LIKE 'QUICK_FILTERS';




Last modified on Apr 18, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.