Database Migration Failed 10.3 -> 10.8.1.101195

We are upgrading sonarqube Enterprise from 10.3 to 10.8

During the migration, the process froze for hours at:

web[][DbMigrations] 4/65 #104003 'Populate 'rule_tags' table'...

After waiting, I restarted the sonarqube service, which allowed the migration to continue.

However, the migration again halted again for more than 15 hours, leaving me no choice but to restart the service:
Error:

2025.02.28 22:02:44 INFO  web[][DbMigrations] 42/62 #108006 'Migrate the content of 'live_measures' to 'measures' for portfolios'...
2025.02.28 22:02:44 INFO  web[][o.s.s.p.d.m.v.v.AbstractMigrateLiveMeasuresToMeasures] Starting the migration of 21 portfolios (total number of portfolios: 21)
2025.02.28 22:17:44 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 0 rows processed (0 items/sec)
2025.02.28 22:18:44 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 0 rows processed (0 items/sec)
2025.02.28 22:19:44 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 0 rows processed (0 items/sec)
2025.02.28 22:20:44 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 0 rows processed (0 items/sec)
2025.02.28 22:21:26 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 21 rows processed (0 items/sec)
2025.02.28 22:21:26 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 11428 rows processed (190 items/sec)

However, this time, restarting the service created duplicate records in the measures table, leading to a failure when attempting to add the Primary Key.

2025.03.01 12:17:34 INFO  web[][DbMigrations] 1/21 #108006 'Migrate the content of 'live_measures' to 'measures' for portfolios': success | time=3743ms
2025.03.01 12:17:34 INFO  web[][DbMigrations] 2/21 #108007 'Create primary key on 'measures' table'...
2025.03.01 12:17:35 ERROR web[][DbMigrations] 2/21 #108007 'Create primary key on 'measures' table': failure | time=1408ms
2025.03.01 12:17:35 ERROR web[][DbMigrations] Executed 1/21 DB migrations: failure | time=5155ms
2025.03.01 12:17:35 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=5216ms


org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #108007 'Create primary key on 'measures' table' failed
        at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:112)
        at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:97)
Caused by: java.lang.IllegalStateException: Fail to execute ALTER TABLE measures ADD CONSTRAINT pk_measures PRIMARY KEY (component_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)
Caused by: org.postgresql.util.PSQLException: ERROR: could not create unique index "pk_measures"
  Detail: Key (component_uuid)=(AZUY7nPnbvgAjB18WEXT) is duplicated.
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2733)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2420)

also i can’t see any Java heap error

sonar.web.javaOpts=-Xmx4g -Xms4g -XX:+HeapDumpOnOutOfMemoryError
sonar.ce.javaOpts=-Xmx4g -Xms2g -XX:+HeapDumpOnOutOfMemoryError

Hello @zeeshan50522,

Unfortunately, this migration is not fully reentrant. Step #108003 is particularly lengthy, and it must not be stopped and restarted in the middle.
Are you sure it was frozen? It can take a long time on large instances, but you should still see logs with the progress.

In any case, at this point your best option is to restore your backup and restart the upgrade, making sure not to stop it in the middle. It can be a good idea to increase your memory settings for the upgrade (sonar.web.javaOpts).

Note that I recommend upgrading directly to the LTA 2025.1.1 if possible (release this or next week), particularly if you use the dependency-check third-party plugin.

1 Like