Upgrade sonarqube from 6.7.7 to 7.9.1 Failed

I am trying to upgrade sonarqube from 6.7.7 to 7.9.1 which use postgres 9.6 as database

Error is as shown below :

org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #1942 ‘Add live_measures.metric_id index’ 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 java.base/java.lang.Iterable.forEach(Iterable.java:75)
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(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Fail to execute CREATE UNIQUE INDEX live_measures_component ON live_measures (component_uuid, metric_id)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:97)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:77)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:117)
at org.sonar.server.platform.db.migration.version.v70.AddLiveMeasuresMetricIndex.execute(AddLiveMeasuresMetricIndex.java:44)
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: could not create unique index “live_measures_component”
Detail: Key (component_uuid, metric_id)=(0c965cd6-564d-4e29-a384-9e73562a190a, 106) is duplicated.
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:266)
at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:82)
… 14 common frames omitted

I have seen the previous thread - Upgrade from 6.7.3 to 7.9 (LTS) -> Fail to execute CREATE UNIQUE INDEX live_measures_component

And also attempted the workaround but query in workaround gives no result.
Additionally, I manually scanned the UI to find unscanned projects and deleted them but still getting the same error.

Hello,

I see you already posted in the right thread : look for the post marked as solution

Hi Pierre,

I did try to use the workaround from “the post marked as solution”. But as mentioned above I tried to run the query which gave me 0 result.
Also, I manually scanned the UI to find unscanned projects and deleted them but still getting the same error when attempted the upgrade

Have you try to re-analyse your projects that where not analysed since SQ 5.6 ?

I was avoiding to go through the whole upgrade cycle again.

But I noticed the component_uuid, metric_id mentioned in the log and ran the query with those parameters which was a file and not project (hence the query returned zero result).
And Once I deleted the project which contained that file (the project was scanned but had a file that was not scanned). I could complete the database migration and upgrade.