SonarQube Execution of migration step #1 'Create initial schema' failed

SonarQube version 8.6.0.39681

I’m trying to move SonarQube to different server. Following locations were moved as is
/opt/sonarqube/data
/opt/sonarqube/extensions
/opt/sonarqube/lib/bundled-plugins
/opt/sonarqube/conf
/opt/sonarqube/logs
All data from postgres 11 database used by SonarQube was exported to dump and imported in new postgres 11 database.

It looks like SonarQube is ignoring all existing data in database and trying to recreate everything because upon start I’m getting following errors:

org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #1 'Create initial schema' 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 org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl$$Lambda$452/0x0000000050e3c5c0.accept(Unknown Source)
  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.AutoDbMigration.start(AutoDbMigration.java:40)
  at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
  at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
  at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
  at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
  at org.picocontainer.behaviors.Stored.start(Stored.java:110)
  at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
  at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
  at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
  at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
  at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
  at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:213)
  at org.sonar.server.platform.PlatformImpl.startSafeModeContainer(PlatformImpl.java:205)
  at org.sonar.server.platform.PlatformImpl.doStart(PlatformImpl.java:105)
  at org.sonar.server.platform.PlatformImpl.doStart(PlatformImpl.java:96)
  at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:44)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4689)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5155)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
  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:836)

Caused by: java.lang.IllegalStateException: Fail to execute CREATE TABLE active_rule_parameters (id SERIAL NOT NULL,active_rule_id INTEGER NOT NULL,rules_parameter_id INTEGER NOT NULL,value VARCHAR (4000) NULL,rules_parameter_key VARCHAR (128) NULL, CONSTRAINT pk_active_rule_parameters PRIMARY KEY (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.v00.CreateInitialSchema.createActiveRuleParameters(CreateInitialSchema.java:156)
  at org.sonar.server.platform.db.migration.version.v00.CreateInitialSchema.execute(CreateInitialSchema.java:88)
  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)
  ... 30 common frames omitted

Caused by: org.postgresql.util.PSQLException: ERROR: relation "active_rule_parameters" already exists
  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)
  2022-06-30T14:12:59.410+02:00	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:91)
  2022-06-30T14:12:59.410+02:00	... 36 common frames omitted

Is there any way around this?

Hi,

Welcome to the community!

You should make sure SonarQube is connected to the right database and schema. It’s trying to do the initial DB setup because it’s connected to a schema that doesn’t already look like it’s set up.

 
HTH,
Ann

What does it mean “doesnt already look like it’s set up”. The error message would suggest extact opposite of that, “ERROR: relation “active_rule_parameters” already exists”. If it was empty schema then initial setup should just go throught and I wouldn’t see my data.

Hi,

I’m looking at the initial error, which indicates that SonarQube is trying to initialize its database.

There is something in the schema, but not what SonarQube is expecting to see.

Can you verify that

  • your db dump was fully and correctly imported into the new DB
  • SonarQube is connecting to the correct schema?

 
Ann

How could I verify that? How do I determine what is SonarQube “expecting”? All the tables exist in schema and that is causing it to break, if I drop the one in error message it just fails on another.

Hi,

Can you verify that SonarQube is connecting to the correct schema? Is the schema name in the connection string?

Have you modified the DB manually in any way since you restored the dump? If so, it may be best to wipe out the schema and re-restore the backup, then verify that SonarQube is configured to connect to the correct schema and try again.

 
Ann