index “…” contains unexpected zero page at block N

SQLSTATE XX002 condition index_corrupted class XX — Internal Error severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

PostgreSQL found an all-zero page where a valid index page was expected. The index is corrupt and PostgreSQL raises SQLSTATE XX002 (index_corrupted).

What the server log shows

ERROR:  index "orders_pkey" contains unexpected zero page at block 42
HINT:  Please REINDEX it.

Why PostgreSQL raises this — what the manual says

As the REINDEX reference (Description) explains:

An index access found an all-zero page where a valid index page was expected — a sign of index corruption (often from hardware faults or an unclean shutdown); rebuilding the index with REINDEX recreates its pages from the table data.

Index pages must be valid; an all-zero page indicates the index is damaged (e.g. an interrupted write or storage fault). Because the index can no longer be trusted, scans fail with XX002 until it is rebuilt.

Common causes

How to fix it

  1. Rebuild the index: REINDEX INDEX orders_pkey; (or REINDEX TABLE).
  2. Use REINDEX INDEX CONCURRENTLY to avoid locking writes (PG12+).
  3. Investigate the underlying storage if corruption recurs.

Related & next steps

Reference: PostgreSQL 18 — REINDEX.