Upgrading Sonarqube 7.9.1 to 8.9.6

We are facing issues when upgrading from 7.9.1 to 8.9.6. We are using Azure Postgres Service and the version is 10.19. After the upgrade the database migration fails due to some tables already existing. Do we need to perform any activity on the fresh database before restoring production database?

Hi,

Unfortunately, you probably are going to have to manually address the DB migration errors you’re seeing. Can you share what they are?

 
Ann

Hi,

We had errors saying some of the tables already exist. I have manually removed those tables and the db migration completed. I have attached the logs. Now the application is showing some of the projects are unavailable

2022.02.01 20:40:00 INFO  web[][DbMigrations] #4119 'Create table 'app_branch_project_branch''...
2022.02.01 20:40:00 ERROR web[][DbMigrations] #4119 'Create table 'app_branch_project_branch'': failure | time=10ms
2022.02.01 20:40:00 ERROR web[][DbMigrations] Executed DB migrations: failure | time=138ms
2022.02.01 20:40:00 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=193ms
2022.02.01 20:40:00 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 #4119 'Create table 'app_branch_project_branch'' 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 TABLE app_branch_project_branch (uuid VARCHAR (40) NOT NULL,application_uuid VARCHAR (40) NOT NULL,application_branch_uuid VARCHAR (40) NOT NULL,project_uuid VARCHAR (40) NOT NULL,project_branch_uuid VARCHAR (40) NOT NULL,created_at BIGINT NOT NULL)
	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.v86.CreateApplicationBranchProjs.execute(CreateApplicationBranchProjs.java:38)
	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 "app_branch_project_branch" already exists
	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: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
2022.02.01 20:40:50 INFO  web[][o.s.p.ProcessEntryPoint] Gracefully stopping process
2022.02.01 20:40:50 INFO  web[][o.s.s.app.WebServer] WebServer stopped
![Screenshot 2022-02-04 at 11-33-50 Background Tasks - Administration|690x16](upload://1VHkObvwqZvsq6KE0H4b9PibGyJ.png)

Hi,

Thanks for sharing your log.

That sounds like progressive re-indexing. Rather than keeping the app unavailable while all the Elasticsearch indexes are rebuilt, we expose the interface and make projects available as their data is reindexed.

 
Ann

We deleted the es7 directory and tried to reindex the application, but the projects are still unavailable. Could this be from manually dropping each table that already existed?

Hi,

At this point, I’m not sure. It might be best to restore the DB backup you took before upgrading & wait for help.

 
Ann