Unable to upgrade from version 7.0 to 8.9.5

which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension): Version 7.0
what are you trying to achieve: Trying to upgrade to v8.9.5
what have you tried so far to achieve this:
Our v7.0 instance was connected to mysql DB and we successfully migrated it to postgresql.
We also checked that all the project, users, scan, quality profile and quality gates related was perfect.

Now when trying to upgrade to v8.9.5 we are facing issues while the DB migration is happening

I believe someone can help on this. as this is for overcoming the log4j vulnerability issue.

2021.12.20 06:20:17 DEBUG web[o.s.s.a.TomcatAccessLog] Tomcat is started
2021.12.20 06:20:17 INFO web[o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2021.12.20 06:22:21 INFO web[o.s.s.p.d.m.DatabaseMigrationImpl] Starting DB Migration and container restart
2021.12.20 06:22:21 INFO web[DbMigrations] Executing DB migrations…
2021.12.20 06:22:21 INFO web[DbMigrations] #3002 ‘Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique’…
2021.12.20 06:22:21 ERROR web[DbMigrations] #3002 ‘Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique’: failure | time=15ms
2021.12.20 06:22:21 ERROR web[DbMigrations] Executed DB migrations: failure | time=17ms
2021.12.20 06:22:21 ERROR web[o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=87ms
2021.12.20 06:22: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 #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(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
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: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
2021.12.20 06:24:12 INFO web[o.s.p.ProcessEntryPoint] Gracefully stopping process
2021.12.20 06:24:12 DEBUG web[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection manager is shutting down
2021.12.20 06:24:12 DEBUG web[o.a.h.i.n.c.PoolingNHttpClientConnectionManager] Connection manager shut down
2021.12.20 06:24:12 DEBUG web[o.s.s.a.TomcatAccessLog] Tomcat is stopped
2021.12.20 06:24:12 INFO web[o.s.s.app.WebServer] WebServer stopped

Hi!

You can’t upgrade from 7.0 to 8.9.5 directly. First you need to upgrade to SonarQube 7.9.6 (the former LTS version) and then upgrade to 8.9.5 (the current LTS).

It’s explained on the docs:

Migration path

(…) However, if there are one or multiple LTS versions in your migration path, you must first migrate to each intermediate LTS and then to your target version, as shown in Example 3 below.

Example 1 – From 8.1 > 9.0, the migration path is 8.1 > 8.9.1 LTS > 9.0
Example 2 – From 8.2 > 8.9 LTS, the migration path is 8.2 > the latest 8.9 LTS patch.
Example 3 – From 6.7.7 LTS > 8.9 LTS, the migration path is 6.7.7 LTS > 7.9.6 LTS > the latest 8.9 LTS patch.