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
- Rebuild the index:
REINDEX INDEX CONCURRENTLY orders_pkey;. - Use
amcheckto scan for other corrupt indexes. - Investigate the underlying storage; indexes corrupting repeatedly signal hardware issues.
Related & next steps
Reference: PostgreSQL 18 — REINDEX.
Thanks — noted. This helps keep the database accurate.