SonarQube database error in issues_component_uuid index

Hello,

can someone help me to fix the below error ?

Below is my set up details

SonarQube Version 9.6.1
Deployed with Helm
Application code scanning/Quality gate checks

And below is the error I’m facing

Error Details
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.sonar.db.issue.IssueMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
    message, line, locations, gap, effort, status, tags, rule_description_context_key,
    resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date,
    issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available)
    VALUES (
    'AYhsnxifat72VKr9jkA7',
    'AYOGGumRoWN2o9YrP-3a',
    'MAJOR',
    'FALSE', 'Remove this unused method parameter "code".', 12,
    ?,
    NULL, 5, 'OPEN',
    'cert,unused',
    NULL,
    NULL,
    '7ee9f674590008e80058b88eef87af04',
    NULL,
    'xyz@blabla.com',
    1665743643000,1685449532000, NULL,
    1685449546460, 1685449546460,
    'AYa8VBIk-_kw-292JHU-', 'AYa8VAp74SSZcdK02rzy', 1,
    'TRUE') was aborted: ERROR: table tid from new index tuple (1997,12) cannot find insert offset between offsets 62 and 74 of block 1 in index "issues_component_uuid"  Call getNextException to see other errors in the batch.
### The error may exist in org.sonar.db.issue.IssueMapper
### The error may involve org.sonar.db.issue.IssueMapper.selectByKeysIfNotUpdatedAt
### The error occurred while executing a query
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.sonar.db.issue.IssueMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
    message, line, locations, gap, effort, status, tags, rule_description_context_key,
    resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date,
    issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available)
    VALUES (
    'AYhsnxifat72VKr9jkA7',
    'AYOGGumRoWN2o9YrP-3a',
    'MAJOR',
    'FALSE', 'Remove this unused method parameter "code".', 12,
    ?,
    NULL, 5, 'OPEN',
    'cert,unused',
    NULL,
    NULL,
    '7ee9f674590008e80058b88eef87af04',
    NULL,
    'xyz@blabla.com',
    1665743643000,1685449532000, NULL,
    1685449546460, 1685449546460,
    'AYa8VBIk-_kw-292JHU-', 'AYa8VAp74SSZcdK02rzy', 1,
    'TRUE') was aborted: ERROR: table tid from new index tuple (1997,12) cannot find insert offset between offsets 62 and 74 of block 1 in index "issues_component_uuid"  Call getNextException to see other errors in the batch.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at org.sonar.db.DbSessionImpl.selectList(DbSessionImpl.java:87)
	at org.sonar.db.BatchSession.selectList(BatchSession.java:82)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
	at com.sun.proxy.$Proxy80.selectByKeysIfNotUpdatedAt(Unknown Source)
	at org.sonar.ce.task.projectanalysis.step.PersistIssuesStep.persistUpdatedIssues(PersistIssuesStep.java:159)
	at org.sonar.ce.task.projectanalysis.step.PersistIssuesStep.execute(PersistIssuesStep.java:117)
	at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:80)
	at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:71)
	at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:58)
	at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:75)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:212)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:194)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:160)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:135)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:87)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	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: org.apache.ibatis.executor.BatchExecutorException: org.sonar.db.issue.IssueMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
    message, line, locations, gap, effort, status, tags, rule_description_context_key,
    resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date,
    issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available)
    VALUES (
    'AYhsnxifat72VKr9jkA7',
    'AYOGGumRoWN2o9YrP-3a',
    'MAJOR',
    'FALSE', 'Remove this unused method parameter "code".', 12,
    ?,
    NULL, 5, 'OPEN',
    'cert,unused',
    NULL,
    NULL,
    '7ee9f674590008e80058b88eef87af04',
    NULL,
    'rohit.yadav@dltapp.co.uk',
    1665743643000,1685449532000, NULL,
    1685449546460, 1685449546460,
    'AYa8VBIk-_kw-292JHU-', 'AYa8VAp74SSZcdK02rzy', 1,
    'TRUE') was aborted: ERROR: table tid from new index tuple (1997,12) cannot find insert offset between offsets 62 and 74 of block 1 in index "issues_component_uuid"  Call getNextException to see other errors in the batch.
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:149)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122)
	at org.apache.ibatis.executor.BatchExecutor.doQuery(BatchExecutor.java:86)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
	... 30 more
Caused by: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
    message, line, locations, gap, effort, status, tags, rule_description_context_key,
    resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date,
    issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available)
    VALUES (
    'AYhsnxifat72VKr9jkA7',
    'AYOGGumRoWN2o9YrP-3a',
    'MAJOR',
    'FALSE', 'Remove this unused method parameter "code".', 12,
    ?,
    NULL, 5, 'OPEN',
    'cert,unused',
    NULL,
    NULL,
    '7ee9f674590008e80058b88eef87af04',
    NULL,
    'xyz@blabla.com',
    1665743643000,1685449532000, NULL,
    1685449546460, 1685449546460,
    'AYa8VBIk-_kw-292JHU-', 'AYa8VAp74SSZcdK02rzy', 1,
    'TRUE') was aborted: ERROR: table tid from new index tuple (1997,12) cannot find insert offset between offsets 62 and 74 of block 1 in index "issues_component_uuid"  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:165)
	at org.postgresql.core.ResultHandlerDelegate.handleError(ResultHandlerDelegate.java:52)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2367)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:560)
	at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887)
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910)
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1663)
	at org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:241)
	at org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:241)
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:123)
	... 38 more
Caused by: org.postgresql.util.PSQLException: ERROR: table tid from new index tuple (1997,12) cannot find insert offset between offsets 62 and 74 of block 1 in index "issues_component_uuid"
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2676)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
	... 45 more

Hey there.

A quick search online shows these are symptoms of a broken Postgres index. I suggest rebuilding all the database indices on your Postgres database.

:warning: Make sure you upgrade to SonarQube v9.9 LTS soon, not only to benefit from our Best LTS Ever™, but because soon we will systematically ask users to upgrade when they ask questions about earlier versions of SonarQube, which are now considered unsupported. :smiley: