SonarQube does not start after update - ERROR web[][DbMigrations] #6006 'Drop 'user_managed' column

Make sure to tell us:

  • What version are you upgrading from?
    8.9 LTS (Enterprise)
  • System information (Operating system, Java version, Database provider/version)
    Windows Server 2016, Java 17, MS SQL Server 2022 Standard
  • What’s the issue you’re facing?
    Database migration failed
023.03.24 13:36:49 INFO  web[][o.s.s.p.d.m.s.MassUpdate] 0 rows processed (0 items/sec)
2023.03.24 13:36:49 INFO  web[][DbMigrations] #6005 'Drop custom metrics data from 'metrics' table': success | time=19ms
2023.03.24 13:36:49 INFO  web[][DbMigrations] #6006 'Drop 'user_managed' column from 'metrics' table'...
2023.03.24 13:36:49 ERROR web[][DbMigrations] #6006 'Drop 'user_managed' column from 'metrics' table': failure | time=71ms
2023.03.24 13:36:49 ERROR web[][DbMigrations] Executed DB migrations: failure | time=1655ms
2023.03.24 13:36:49 WARN  web[][o.s.c.a.AnnotationConfigApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd-org.sonar.server.platform.db.migration.AutoDbMigration': Initialization of bean failed; nested exception is org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #6006 'Drop 'user_managed' column from 'metrics' table' failed
2023.03.24 13:36:49 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd-org.sonar.server.platform.db.migration.AutoDbMigration': Initialization of bean failed; nested exception is org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #6006 'Drop 'user_managed' column from 'metrics' table' failed
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:187)
	at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:80)
	at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:196)
	at org.sonar.server.platform.PlatformImpl.startSafeModeContainer(PlatformImpl.java:188)
	at org.sonar.server.platform.PlatformImpl.doStart(PlatformImpl.java:90)
	at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:44)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4764)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5222)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1383)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:430)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486)
	at org.sonar.server.app.EmbeddedTomcat.start(EmbeddedTomcat.java:72)
	at org.sonar.server.app.WebServer.start(WebServer.java:55)
	at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:97)
	at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:81)
	at org.sonar.server.app.WebServer.main(WebServer.java:104)
Caused by: org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #6006 'Drop 'user_managed' column from 'metrics' 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:422)
	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:66)
	at org.sonar.server.platform.db.migration.AutoDbMigration.start(AutoDbMigration.java:40)
	at org.sonar.core.platform.StartableBeanPostProcessor.postProcessBeforeInitialization(StartableBeanPostProcessor.java:33)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
	... 43 common frames omitted
Caused by: java.lang.IllegalStateException: Fail to execute ALTER TABLE metrics DROP CONSTRAINT DF__metrics__user_ma__5165187F
	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.step.DropColumnChange.execute(DropColumnChange.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)
	... 52 common frames omitted
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 'DF__metrics__user_ma__5165187F' is not a constraint.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:265)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1676)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:907)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:802)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7627)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3916)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:268)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:242)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:775)
	at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
	at org.sonar.server.platform.db.migration.step.DdlChange$ContextImpl.execute(DdlChange.java:91)
	... 57 common frames omitted
2023.03.24 13:36:49 INFO  web[][c.z.h.HikariDataSource] HikariPool-1 - Shutdown initiated...
2023.03.24 13:36:49 INFO  web[][c.z.h.HikariDataSource] HikariPool-1 - Shutdown completed.
2023.03.24 13:36:49 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2023.03.24 13:36:49 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process

Thanks in advance,
Kenneth

I unsuccessful tried to drop the constrain manually as stated in other similar threads:

Migration error when upgrading to 9.7.1 - SonarQube - Sonar Community (sonarsource.com)

DB Migration issues during Upgrade from 8.9.10 LTS to 9.9 LTS - SonarQube / 9.9 LTS Upgrade - Sonar Community (sonarsource.com)

Hello,

Thanks for reaching out. I see you have already found posts with a similar issue. Have you tried to identify the constraints with the query I mention here?

Can you explain how the query failed? Was the constraint not found or did you encounter other errors? Thanks.

I found the root cause for my issue. The MS SQL user’s Default DB schema was incorrectly so it tried to migrate to sonar database under the DBO schema instead of the DB_Owner. Setting the Default DB Schema to DB_Owner for for db user solved the problem.

1 Like