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

Hello

i have recently upgraded my sonarqube from 8.9.9 to 8.9.10 LTA.

i’m getting same error with active_rules tables. when i delete the complaining row again i will get new rule_uuid number.

--
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile java/Sonar way
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile web/Sonar way
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile xml/Sonar way
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile flex/Sonar way
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile php/Sonar way
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile php/PSR-2
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile php/Drupal
2024.07.04 02:40:23 INFO  web[][o.s.s.q.RegisterQualityProfiles] Update profile vbnet/Sonar way
2024.07.04 02:40:23 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)=(AYHPrK5FTiVai3yrmiy-, 2581) 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)=(AYHPrK5FTiVai3yrmiy-, 2581) 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.$Proxy57.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.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:829)
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "uniq_profile_rule_uuids"
  Detail: Key (profile_uuid, rule_uuid)=(AYHPrK5FTiVai3yrmiy-, 2581) already exists.
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166)
	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:155)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)

Vacumm full, Reindex db, analyze.

i have performed all the above on sonarqube database.

Hi @ljaladi,

Welcome to the community!

You’ve resurrected a 2-year-old thread. Per the FAQ, please don’t do that. Normally, I’d ask you to create a new thread with all your details, but your version is past EOL, and we simply cannot help you with it. Given that you’re facing an error after a point-release upgrade, I believe you should restore your DB backup of 8.9.9 and then upgrade to either the latest version or the current LTA (long-term active version) at your earliest convenience. Your upgrade path is:

8.9.9 → 9.9.6 → 10.6 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after upgrade, please come back to us.

 
HTH,
Ann