Sonarqube 8.9 duplicate key value violates unique constraint

We are using 8.9version and have db patching done. Since then sonarqube isn’t able to start failing with

2022.05.02 06:54:30 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile apex/Sonar way
2022.05.02 06:54:30 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile plsql/Sonar way
2022.05.02 06:54:30 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uniq_profile_rule_uuids"
  Detail: Key (profile_uuid, rule_uuid)=(AXpfnwbarWRV8oV6Rll-, 2633) already exists.
### The error may exist in org.sonar.db.qualityprofile.ActiveRuleMapper
### The error may involve org.sonar.db.qualityprofile.ActiveRuleMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into active_rules (       uuid,       profile_uuid,       rule_uuid,       failure_level,       inheritance,       created_at,       updated_at     ) values (       ?,       ?,       ?,       ?,       ?,       ?,       ?     )
### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uniq_profile_rule_uuids"
  Detail: Key (profile_uuid, rule_uuid)=(AXpfnwbarWRV8oV6Rll-, 2633) already exists.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy62.insert(Unknown Source)
	at org.sonar.db.qualityprofile.ActiveRuleDao.insert(ActiveRuleDao.java:106)
	at org.sonar.server.qualityprofile.RuleActivator.doInsert(RuleActivator.java:262)
	at org.sonar.server.qualityprofile.RuleActivator.persist(RuleActivator.java:232)
	at org.sonar.server.qualityprofile.RuleActivator.doActivate(RuleActivator.java:132)
	at org.sonar.server.qualityprofile.RuleActivator.activate(RuleActivator.java:77)
	at org.sonar.server.qualityprofile.BuiltInQProfileUpdateImpl.update(BuiltInQProfileUpdateImpl.java:73)
	at org.sonar.server.qualityprofile.RegisterQualityProfiles.update(RegisterQualityProfiles.java:132)
	at org.sonar.server.qualityprofile.RegisterQualityProfiles.lambda$start$1(RegisterQualityProfiles.java:93)
	at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at org.sonar.server.qualityprofile.RegisterQualityProfiles.start(RegisterQualityProfiles.java:88)
	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.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:49)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:87)
	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:84)
	at org.sonar.server.platform.PlatformImpl.executeStartupTasks(PlatformImpl.java:198)
	at org.sonar.server.platform.PlatformImpl.access$400(PlatformImpl.java:46)
	at org.sonar.server.platform.PlatformImpl$1.lambda$doRun$1(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.runIfNotAborted(PlatformImpl.java:370)
	at org.sonar.server.platform.PlatformImpl$1.doRun(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.run(PlatformImpl.java:354)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uniq_profile_rule_uuids"
  Detail: Key (profile_uuid, rule_uuid)=(AXpfnwbarWRV8oV6Rll-, 2633) 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:481)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
	at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	... 36 common frames omitted
2022.05.02 06:54:30 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process
2022.05.02 06:54:30 INFO  web[][o.s.s.n.NotificationDaemon] Notification service stopped
2022.05.02 06:54:30 INFO  web[][o.s.s.e.CoreExtensionStopper] Stopping Governance
2022.05.02 06:54:30 INFO  web[][o.s.s.e.CoreExtensionStopper] Stopping Governance (done) | time=0ms
2022.05.02 06:54:30 INFO  app[][o.s.a.SchedulerImpl] Process[web] is stopped
2022.05.02 06:54:31 INFO  app[][o.s.a.SchedulerImpl] Process[es] is stopped
2022.05.02 06:54:31 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 143
2022.05.02 06:54:31 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped

can someone help with this issue?

Hi Manasa,
Were you able to solve it? I’m facing the same issue.

Thx!
Chris

I solved it by rebuilding the indexes of my Postgres database.

Here’s a short explanation: PostgreSQL REINDEX Explained

2 Likes

Thanks for the followup @chrisleipold!

This is enormously helpful to know!

 
Ann

1 Like