SQLSTATE XX002 ERROR Class XX: Internal Error

index_corrupted index “…” contains unexpected zero page — XX002

PostgreSQL error “index … contains unexpected zero page — XX002” (SQLSTATE XX002): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

An index access found an unexpected zero (all-zero) page, indicating index corruption. PostgreSQL raises SQLSTATE XX002 (index_corrupted).

  • An index page is unexpectedly all zeros.
  • Index scans on the relation may fail.
  • Often a crash- or storage-related fault.

What the server log shows

ERROR:  index "orders_pkey" contains unexpected zero page at block 99

Why PostgreSQL raises this — what the manual says

As the REINDEX reference (Description) explains:

The index’s on-disk structure is inconsistent with the underlying table — commonly caused by storage faults, collation-library changes, or an unclean shutdown; REINDEX rebuilds the index from scratch to restore a valid structure.

Index pages must be properly initialized. Encountering an all-zero page where data is expected means the index structure is damaged, so PostgreSQL reports XX002. Because indexes are derived data, they can usually be rebuilt.

Common causes

  • A crash during index writes (especially with fsync off).
  • Storage/hardware faults zeroing pages.
  • A bad restore or filesystem corruption.

How to fix it

  1. Rebuild the index: REINDEX INDEX CONCURRENTLY orders_pkey;.
  2. Use amcheck to scan for other corrupt indexes.
  3. Investigate the underlying storage; indexes corrupting repeatedly signal hardware issues.

Related & next steps

Reference: PostgreSQL 18 — REINDEX.

Was this helpful?