SQLSTATE XX002 PANIC Class XX: Internal Error

index_corrupted Index Corrupted — SQLSTATE XX002

An index is corrupted.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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:

  1. Rebuild the index: REINDEX INDEX CONCURRENTLY idx; (or REINDEX TABLE).
  2. After a glibc/ICU collation change, reindex affected text indexes — a common cause.
  3. Verify with amcheck (bt_index_check) after rebuilding.

Reference: PostgreSQL error codes — Class XX (Internal Error).

Was this helpful?