Error upgrading 7.9.4 to 8.7.0.41497 (Developer Edition)

Hi,

I am trying to upgrade from 7.9.4 to 8.7.0.41497 on a Linux host with Postgres as database. I got the generic error failed message and found the following details:

2021.03.15 18:52:08 INFO  web[][o.s.s.p.Platform] Database needs to be migrated. Please refer to https://docs.sonarqube.org/latest/setup/upgrading
2021.03.15 18:52:08 INFO  web[][o.s.s.p.w.MasterServletFilter] Initializing servlet filter org.sonar.server.platform.web.WebServiceFilter@1f8138b4 [pattern=UrlPattern{inclusions=[/api/system/migrate_db.*, ...], exclusions=[/api/components/update_key, ...]}]
2021.03.15 18:52:08 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2021.03.15 18:52:10 INFO  web[][o.s.s.p.d.m.DatabaseMigrationImpl] Starting DB Migration and container restart
2021.03.15 18:52:10 INFO  web[][DbMigrations] Executing DB migrations...
2021.03.15 18:52:10 INFO  web[][DbMigrations] #3545 'Add index on 'metric_uuid' column of 'LIVE_MEASURES' table'...
2021.03.15 18:52:21 ERROR web[][DbMigrations] #3545 'Add index on 'metric_uuid' column of 'LIVE_MEASURES' table': failure | time=10917ms
2021.03.15 18:52:21 ERROR web[][DbMigrations] Executed DB migrations: failure | time=10917ms
2021.03.15 18:52:21 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=10964ms
2021.03.15 18:52:21 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 #3545 'Add index on 'metric_uuid' column of 'LIVE_MEASURES' 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(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_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.v84.metrics.livemeasures.AddIndexOnMetricUuidOfLiveMeasuresTable.execute(AddIndexOnMetricUuidOfLiveMeasuresTable.java:43)
    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_uuid)=(AW62FGO6kEwA8X5K7Ar-, 141) is duplicated.
    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:473)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
    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

I also found this: https://jira.sonarsource.com/browse/SONAR-12282
But that does not seem to be the issue:
sqdb=> select
sqdb-> p.kee,p.“name”
sqdb-> from
sqdb-> projects p
sqdb-> where
sqdb-> p.qualifier = ‘TRK’
sqdb-> and p.scope = ‘PRJ’
sqdb-> and exists (
sqdb(> select
sqdb(> pm.component_uuid, pm.metric_id, count(1)
sqdb(> from
sqdb(> project_measures pm
sqdb(> inner join snapshots s on
sqdb(> s.component_uuid = p.uuid
sqdb(> and s.islast = true
sqdb(> where
sqdb(> pm.analysis_uuid = s.uuid
sqdb(> group by
sqdb(> pm.component_uuid, pm.metric_id
sqdb(> having
sqdb(> count(1) > 1
sqdb(> );
kee | name
-----±-----
(0 rows)

So I am not sure what the next step is. And we only have 3 projects in the database and they absolutely have been analysed in 7.9.4. Or could the cause be in old branches and how are we going to find out?

Hi @elissen ,

Welcome to SonarSource Community! :sonarsource:

See if this thread helps: Cannot upgrade to SonarQube version 8.4, since the DB migrations: failure

Joe

Thank you Joe, that worked.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.