SQLSTATE XX002 ERROR Class XX: Internal Error

index_corrupted index “…” contains corrupted page at block n — XX002

PostgreSQL error “index “…” contains corrupted page at block n” (SQLSTATE XX002, index_corrupted): what it means, common causes, and how to fix it.

PG 15, 16, 17, 18, 19 Official docs
Last reviewed Jun 2026 Grounded in source
Production impact High Competency WAL & Recovery Career Own backup and recovery strategy Frequency Common

Investigation

Symptoms

A statement failed with SQLSTATE XX002 (index_corrupted), reported at severity ERROR. This is a Internal Error condition: PostgreSQL emits the message index "…" contains corrupted page at block n.

  • The client receives SQLSTATE XX002 (index corrupted).
  • The operation is rejected at ERROR level; the statement does not complete.

What the server log shows

ERROR:  index "…" contains corrupted page at block n
HINT:  Please REINDEX it.

Why PostgreSQL raises this

Class XX (Internal Error) indicates a condition that should not normally occur — often a sign of data corruption or a server bug. These warrant careful investigation.

As described in PostgreSQL’s Chapter 30 Reliability and the Write-Ahead Log and Appendix A (PostgreSQL Error Codes), SQLSTATE XX002 carries the condition name index_corrupted in class Internal Error. (Paraphrased — see the linked reference for the exact wording.)

Common causes

  • Data or index corruption (often storage/hardware related).
  • An unexpected internal state or a server bug.
  • A failed consistency check during execution.

How to fix it

  1. Capture the full message, context, and server version.
  2. Check storage/hardware and recent crash history.
  3. Take a backup and consider reporting a reproducible case upstream.

Version applicability

This message is present in PostgreSQL 15, 16, 17, 18 and 19.

Related & next steps

Reference: PostgreSQL Chapter 30 Reliability and the Write-Ahead Log.

Keep going

Related & next steps

Concepts on this page

Was this helpful?