Postgres Database upgrading Fails when Upgrading Sonarqube

After backing up my postgres database and installing the newer version (8.3) on my sonarqube centOS AWS server, I followed the steps shown on the sonarqube site by upgrading using the sonarqube latest docker image.

when i get to the step where I go to the go the http://yourSonarQubeServerURL/setup. I get this error.
image

2020.05.06 20:10:09 INFO  web[][DbMigrations] #3002 'Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique'...
2020.05.06 20:10:09 ERROR web[][DbMigrations] #3002 'Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique': failure | time=14ms
2020.05.06 20:10:09 ERROR web[][DbMigrations] Executed DB migrations: failure | time=60ms
2020.05.06 20:10:09 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=90ms
2020.05.06 20:10:09 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 #3002 'Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique' 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 INDEX rule_id_deprecated_rule_keys ON deprecated_rule_keys (rule_id)
        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.MakeDeprecatedRuleKeysRuleIdIndexNonUnique.execute(MakeDeprecatedRuleKeysRuleIdIndexNonUnique.java:47)
        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: relation "deprecated_rule_keys" does not exist
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2578)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2313)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:331)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:448)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:369)
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:310)
        at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:296)
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:273)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:268)
        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

please what do I have to do to get this resolved?

Any help will be greatly appreciated.

Hi,

Errors at upgrade about missing tables/indices/etc seem to pretty much always go back to a JDBC URL configuration error with the new version. Can you double-check this against your previous version’s configuration?

 
Ann

thank you or your response. after resolving the database issue. We tried upgrading to new sonarqube 7.9, and now after looking at the logs we get the below error.

2020.05.07 20:40:11 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:80)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
        at com.sun.proxy.$Proxy30.selectByName(Unknown Source)
        at org.sonar.db.qualitygate.QualityGateDao.selectByName(QualityGateDao.java:48)
        at org.sonar.server.qualitygate.RegisterQualityGates.start(RegisterQualityGates.java:87)
        at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
        at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
        at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
        at org.picocontainer.behaviors.Stored.start(Stored.java:110)
        at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
        at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
        at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
        at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
        at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:47)
        at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:83)
        at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:46)
        at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:80)
        at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:196)
        at org.sonar.server.platform.Platform.access$400(Platform.java:46)
        at org.sonar.server.platform.Platform$1.lambda$doRun$1(Platform.java:121)
        at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
        at org.sonar.server.platform.Platform$1.doRun(Platform.java:121)
        at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
        at java.base/java.lang.Thread.run(Unknown Source)
2020.05.07 20:40:11 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process
2020.05.07 20:40:11 INFO  web[][o.s.s.n.NotificationDaemon] Notification service stopped
2020.05.07 20:40:11 INFO  app[][o.s.a.SchedulerImpl] Process[web] is stopped
2020.05.07 20:40:11 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 143
2020.05.07 20:40:11 INFO  app[][o.s.a.SchedulerImpl] Process[es] is stopped
2020.05.07 20:40:11 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2020.05.07 20:40:11 INFO  es[][o.e.n.Node] stopping ...

please do you by chance know what could be causing it? and where can we go to try to fix this?

thank you.

Hi,

Where did you start your upgrade journey? Could it be that you have projects unanalyzed since 5.6? The specific error is different in this thread, but it strikes a chord:

 
Ann