How to fix Index corrupted in PostgreSQL

PostgreSQLINTERMEDIATEHIGHUpdated Dec 28, 2025ยท 150 views

PostgreSQL index corruption causes queries to return incorrect results or fail. Rebuild the corrupted index using REINDEX to restore normal database operations.

Quick fix

Fixes Index corrupted

SET enable_seqscan = off;  -- Force index usage
SELECT * FROM your_table WHERE indexed_column = value;
SET enable_seqscan = on;   -- Reset
  1. Stop the application and verify the corrupted index
  2. Verify corruption with the amcheck extension (PostgreSQL 10+)
  3. Back up your database before proceeding
  4. Rebuild the corrupted index with REINDEX
postgresql โ€” error
SET enable_seqscan = off; -- Force index usage
SELECT * FROM your_table WHERE indexed_column = value;
SET enable_seqscan = on; -- Reset
Index corrupted

What this error means

An index in PostgreSQL has become inconsistent with the actual data in the table. This happens when the index structure is damaged due to hardware failures, software bugs, or system crashes. When PostgreSQL tries to use a corrupted index to find data, it returns incorrect results or encounters errors. The good news is that indexes are derived from table data, so the underlying data remains intact and can be rebuilt.

Typical symptoms

  • Queries return incorrect number of rows when using indexes
  • Sequential scans return different results than index scans
  • Error messages mentioning index tuple overlaps or corruption
  • Query execution is slower or uses unexpected query plans
  • Database operations fail with index-related errors

Common causes

  1. Hardware failures such as faulty RAID controllers or power loss
  2. Operating system upgrades causing glibc incompatibility between source and target machines
  3. PostgreSQL bug in index creation or maintenance
  4. CREATE INDEX CONCURRENTLY failures that left indexes in invalid state
  5. Database running with fsync=off during OS crash or power loss
  6. Concurrent update race conditions during index operations

How to fix "Index corrupted"

1Stop the application and verify the corrupted index

First, safely stop your application to prevent further writes. Then connect to your database and run a query using the suspected index to confirm the corruption:

sql
SET enable_seqscan = off;  -- Force index usage
SELECT * FROM your_table WHERE indexed_column = value;
SET enable_seqscan = on;   -- Reset

If you get different results or errors, the index is likely corrupted.

2Verify corruption with the amcheck extension (PostgreSQL 10+)

Enable and run the amcheck extension to formally detect corruption:

sql
CREATE EXTENSION IF NOT EXISTS amcheck;
SELECT bt_index_check('your_index_name'::regclass);

If amcheck reports DUPLICATE or BACKWARDS entries, corruption is confirmed.

3Back up your database before proceeding

Create a full backup in case anything goes wrong:

bash
pg_dump -U postgres database_name > backup.sql

Store this backup safely on another system.

4Rebuild the corrupted index with REINDEX

For a single corrupted index (quickest, but locks writes):

sql
REINDEX INDEX CONCURRENTLY your_index_name;

The CONCURRENTLY option allows reads and writes during rebuilding (slower but no downtime). For all indexes on a table:

sql
REINDEX TABLE CONCURRENTLY your_table_name;

Wait for the command to complete. Progress may be slow depending on table size.

5Verify the index is restored

After REINDEX completes, verify normal operation:

sql
SET enable_seqscan = off;
SELECT COUNT(*) FROM your_table WHERE indexed_column = value;
SET enable_seqscan = on;

Run the same query again without forcing the index. Both should return the same count.

6Restart your application

Once verification is complete, restart your application:

bash
# For systemd services
sudo systemctl restart your-app

# Or for Docker containers
docker-compose restart web

Monitor logs to ensure the application connects successfully.

Advanced notes

For system catalog index corruption (preventing PostgreSQL startup), restart PostgreSQL with single-user mode and -P flag: postgres -P -D /var/lib/postgresql/data. Then run REINDEX DATABASE;. Increase maintenance_work_mem to 2% of total RAM during large reindexing operations for better performance. If duplicate data violates the index uniqueness constraint, remove duplicates before attempting REINDEX. Consider using pg_repack as an alternative if you need zero-downtime reindexing without CONCURRENTLY.

Frequently asked questions

What does "Index corrupted" mean?
An index in PostgreSQL has become inconsistent with the actual data in the table. This happens when the index structure is damaged due to hardware failures, software bugs, or system crashes. When PostgreSQL tries to use a corrupted index to find data, it returns incorrect results or encounters errors.
How do I fix "Index corrupted"?
PostgreSQL index corruption causes queries to return incorrect results or fail. Rebuild the corrupted index using REINDEX to restore normal database operations.
What causes "Index corrupted"?
Hardware failures such as faulty RAID controllers or power loss Operating system upgrades causing glibc incompatibility between source and target machines PostgreSQL bug in index creation or maintenance
Is the "Index corrupted" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading