Symptoms
An index is corrupted.
- The error is written to the server log and returned to the client carrying
SQLSTATE XX002. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
Environment
Severity: PANIC | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Indicates a system- or storage-level problem; inspect OS logs, disk health, and any recent hardware or filesystem changes.
Root Cause
Index pages are inconsistent — often after a crash, a glibc/ICU collation change, or hardware faults.
Common causes:
- A crash during index modification.
- An OS collation/locale change altering text sort order.
- Hardware faults.
Diagnostic Queries
Recovery
Steps to resolve XX002:
- Rebuild the index:
REINDEX INDEX CONCURRENTLY idx;(orREINDEX TABLE). - After a glibc/ICU collation change, reindex affected text indexes — a common cause.
- Verify with
amcheck(bt_index_check) after rebuilding.
Reference: PostgreSQL error codes — Class XX (Internal Error).
Was this helpful?
Thanks — noted. This helps keep the database accurate.