An error stating "multiple primary keys for table 'plugin_setting' are not allowed" occurs during the startup of Bitbucket Data Center.
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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:
When launching a new Bitbucket instance, the startup fails with the following error.
2024-11-18 21:26:37,574 WARN [spring-startup] o.s.w.c.s.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'crowdAliasDao': Unsatisfied dependency expressed through method 'setSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [stash-context.xml]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for changeset liquibase/r3_2/upgrade.xml::STASHDEV-6754-5::jhinch:
Reason: liquibase.exception.DatabaseException: ERROR: multiple primary keys for table "plugin_setting" are not allowed [Failed SQL: (0) ALTER TABLE public.plugin_setting ADD CONSTRAINT pk_plugin_setting PRIMARY KEY (id)]
Environment:
The solution has been validated in Bitbucket Data Center 9.2.1 but may apply to other versions.
This only affects Bitbucket Data Center running with:
- Enterprise Database Postgres(EDB Postgres) 15.8
Diagnosis:
The atlassian-bitbucket.log
will have the following events.
2024-11-18 21:26:30,320 INFO [spring-startup] c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory /var/atlassian/application-data/bitbucket
2024-11-18 21:26:32,543 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase About to apply 2 database upgrade tasks.
2024-11-18 21:26:32,589 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Upgrade complete. Applied 2 changesets.
2024-11-18 21:26:32,888 INFO [spring-startup] c.a.s.internal.home.HomeLockAcquirer Successfully acquired lock on home directory /var/atlassian/application-data/bitbucket/shared
2024-11-18 21:26:33,820 WARN [spring-startup] com.hazelcast.instance.impl.Node [192.168.XX.XX]:5701 [bitbucket] [5.2.5] No join method is enabled! Starting standalone.
2024-11-18 21:26:34,894 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase About to apply 803 database upgrade tasks.
2024-11-18 21:26:34,962 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 5 of 803
2024-11-18 21:26:35,053 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 10 of 803
2024-11-18 21:26:35,134 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 15 of 803
2024-11-18 21:26:35,208 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 20 of 803
.
.
2024-11-18 21:26:37,477 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 340 of 803
2024-11-18 21:26:37,521 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 345 of 803
2024-11-18 21:26:37,551 INFO [spring-startup] c.a.s.i.l.d.ExtendedSpringLiquibase Applying changeset 350 of 803
2024-11-18 21:26:37,574 WARN [spring-startup] o.s.w.c.s.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'crowdAliasDao': Unsatisfied dependency expressed through method 'setSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [stash-context.xml]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for changeset liquibase/r3_2/upgrade.xml::STASHDEV-6754-5::jhinch:
Reason: liquibase.exception.DatabaseException: ERROR: multiple primary keys for table "plugin_setting" are not allowed [Failed SQL: (0) ALTER TABLE public.plugin_setting ADD CONSTRAINT pk_plugin_setting PRIMARY KEY (id)]
Cause:
- Typically, during the initial startup of Bitbucket 9.2.1, 874 Liquibase change sets are applied. However, in this particular case, only 803 are detected.
- The reason some of the change sets are being skipped is that the changesets are defined for the supported Postgres database and not the EDB Postgres database.
- As outlined in the Liquibase documentation, Postgres and EDB Postgres use different DBMS short names. Consequently, any change set specifically released for Postgres with the DBMS set as "postgresql" will not execute on the EDB database. This is why the total number of change sets applied to EDB is lower than the actual number of change sets applied on PostgreSQL.
For example, the changeset with ID STASHDEV-6754-4b, which contains a statement to drop the primary key on the 'key_name' and 'namespace' columns from the 'plugin_setting' table, is specified for the DBMS "postgresql" and therefore is not executed in the EDB Postgres database.
Because the changeset STASHDEV-6754-4b wasn't applied, the subsequent changeset, STASHDEV-6754-5, which includes a statement to add a primary key to the 'id' column of the 'plugin_setting' table, could not be executed due to the database restriction that prevents a table from having multiple primary keys.
Solution:
- Currently, Bitbucket Data Center does not support the EDB Postgres database, which is why change sets are not released for it. Although there is a feature request BSERV-13227 to include EDB Postgres as a supported database, it's recommended to use one of the currently supported database types.
- In case of any confusion, kindly reach out to Atlassian support.