Sonarqube upgrade to 8.9 failed during database migration

Make sure to tell us:

  • What version are you upgrading from? 7.9.3 LTS to 8.9LTS
  • System information (Operating system, Java version, Database provider/version): EC2-Ubuntu, Running in Docker container. RDS Postgres
  • What’s the issue you’re facing? Hi Team,
    I am upgrading my sonarqube running in a Docker from 7.9.3 to 8.9 version (have plan to upgrade to 9.9 too). Post technical upgrade when I click upgrade database, It fails in few seconds with error
    Upgrade Failed
    Database connection cannot be established. Please check database status and JDBC settings.

strange thing is I was able to upgrade earlier, but from same snapshot when i restore a new db it is failing.

web.log is given below

2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerFileSystemImpl] SonarQube home: /opt/sonarqube
2023.10.25 14:06:15 INFO  web[][o.s.s.u.SystemPasscodeImpl] System authentication by passcode is disabled
2023.10.25 14:06:15 WARN  web[][o.s.s.p.DatabaseServerCompatibility] The database must be manually upgraded. Please backup the database and browse /setup. For more information: https://docs.sonarqube.org/latest/setup/upgrading
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin C# Code Quality and Security / 8.22.0.31243 / e3cee7838d992e31dcdd90cf4f7406bb20535e8e
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin CSS Code Quality and Security / 1.4.2.2002 / faa7d4f1407df67df7ada53caf677ab783721173
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Flex Code Quality and Security / 2.6.1.2564 / bb723840701bda72510b7a47742811d20daad331
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Go Code Quality and Security / 1.8.3.2219 / d6ad7a5a47fc4785d2e80918fb7424be46e38a7f
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin HTML Code Quality and Security / 3.4.0.2754 / 38f7ff864ae15152c9f1efc3014594f7e7ca7b6e
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin JaCoCo / 1.1.1.1157 / 83478572b9f23efac29de15e30c7758bbb0c0e47
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Java Code Quality and Security / 6.15.1.26025 / 1b1e96715bfa9f6a4ae24e95cc5b91f0edce609f
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin JavaScript/TypeScript Code Quality and Security / 7.4.4.15624 / 481b2e69339b016b5d7d1eb27f0abf20dd6bd961
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Kotlin Code Quality and Security / 1.8.3.2219 / d6ad7a5a47fc4785d2e80918fb7424be46e38a7f
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin PHP Code Quality and Security / 3.17.0.7439 / 44c7760147080c157fa0ff579772f92d3c8e1ebf
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Python Code Quality and Security / 3.4.1.8066 / 22139ec73fb2f32044f66477ea52734415683668
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Ruby Code Quality and Security / 1.8.3.2219 / d6ad7a5a47fc4785d2e80918fb7424be46e38a7f
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin Scala Code Quality and Security / 1.8.3.2219 / d6ad7a5a47fc4785d2e80918fb7424be46e38a7f
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin VB.NET Code Quality and Security / 8.22.0.31243 / e3cee7838d992e31dcdd90cf4f7406bb20535e8e
2023.10.25 14:06:15 INFO  web[][o.s.s.p.ServerPluginManager] Deploy plugin XML Code Quality and Security / 2.2.0.2973 / 16002945f0725643a7b42f090572795dd8b72a0f
2023.10.25 14:06:17 INFO  web[][o.s.s.p.d.m.c.PostgresCharsetHandler] Verify that database charset supports UTF8
2023.10.25 14:06:17 INFO  web[][o.s.s.p.Platform] Database needs to be migrated. Please refer to https://docs.sonarqube.org/latest/setup/upgrading
2023.10.25 14:06:17 INFO  web[][o.s.s.p.w.MasterServletFilter] Initializing servlet filter org.sonar.server.platform.web.WebServiceFilter@4a3d0daf [pattern=UrlPattern{inclusions=[/api/system/migrate_db.*, ...], exclusions=[/api/components/update_key, ...]}]
2023.10.25 14:06:17 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2023.10.25 14:09:24 INFO  web[][o.s.s.p.d.m.DatabaseMigrationImpl] Starting DB Migration and container restart
2023.10.25 14:09:24 INFO  web[][DbMigrations] Executing DB migrations...
2023.10.25 14:09:24 INFO  web[][DbMigrations] #3001 'Create ProjectQualityGates table'...
2023.10.25 14:09:24 ERROR web[][DbMigrations] #3001 'Create ProjectQualityGates table': failure | time=28ms
2023.10.25 14:09:24 ERROR web[][DbMigrations] Executed DB migrations: failure | time=30ms
2023.10.25 14:09:24 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=138ms
2023.10.25 14:09:24 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #3001 'Create ProjectQualityGates table' failed
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
	at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
	at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:68)
	at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
	at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Fail to execute CREATE TABLE project_qgates (project_uuid VARCHAR (40) NOT NULL,quality_gate_uuid VARCHAR (40) NOT NULL, CONSTRAINT pk_project_qgates PRIMARY KEY (project_uuid))
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:106)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:86)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:128)
	at org.sonar.server.platform.db.migration.version.v80.CreateProjectQualityGatesTable.execute(CreateProjectQualityGatesTable.java:55)
	at org.sonar.server.platform.db.migration.step.DdlChange.execute(DdlChange.java:45)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
	... 9 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: role "owner-sonarqubedb" does not exist
  Where: SQL statement "ALTER TABLE public.project_qgates OWNER TO "owner-sonarqubedb""
PL/pgSQL function trg_create_set_owner() line 9 at EXECUTE
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:279)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:194)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:194)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:91)
	... 14 common frames omitted

Hi @sonaruser12.

Let me start with the dumb question. :slight_smile: Did you check whether the role exists in your RDS instance? From the error message: ERROR: role "owner-sonarqubedb" does not exist

If I understood correctly, this happens when you try with a brand-new instance. I would double check privileges on this new instance: you need to use the superuser to execute an ALTER TABLE ... OWNER TO ....

Can you please also explain better how you are trying to accomplish this upgrade to a new instance and the use case?

1 Like