PostgreSQL XX001: data corrupted
PostgreSQL read a data page that fails its sanity or checksum checks. Treat it as storage corruption: protect the data, then restore or salvage.
- SQLSTATE
XX001- Name
data_corrupted- Category
- Internal Error
What it means
XX001 (data_corrupted) means a page read from disk is not valid: its header is garbage, its checksum doesn't match (when data checksums are enabled), or a file is shorter than the table needs (could not read block ... read only 0 of 8192 bytes). The file path in the message (base/<database oid>/<relfilenode>) identifies the table or index.
PostgreSQL itself very rarely causes this. The usual sources are failing disks or controllers, storage that lies about flushing writes, a crash on hardware without proper write ordering, or files copied or restored inconsistently.
Common causes
- Hardware or storage faults: disks, RAID controllers, SAN or cloud volumes.
- Write caching that doesn't honor
fsync, followed by a power loss or crash. fsync = offorfull_page_writes = offin production.- A backup taken by copying the data directory without
pg_basebackupor the backup API, or files changed by other software.
How to fix it
-
Stop and take a file-level copy of the whole data directory before trying any repair, so nothing you do can make it worse.
-
Find which object the file belongs to.
SELECT relname, relkind FROM pg_class WHERE relfilenode = 16397;
-
If it is an index, rebuild it.
REINDEX INDEX CONCURRENTLY orders_pkey;
-
If it is a table, restore it from a backup or a replica. As a last resort to salvage the readable rows,
zero_damaged_pages = onmakes PostgreSQL skip bad pages (losing their rows) while you copy the table out.SET zero_damaged_pages = on; -- superuser, salvage only CREATE TABLE orders_salvage AS SELECT * FROM orders; RESET zero_damaged_pages;
-
Check the hardware and storage logs, and enable data checksums on new clusters (
initdb --data-checksums, orpg_checksums --enableon a stopped cluster) so corruption is detected early.
Related errors
XX000internal error58P01undefined file53100disk full824SQL Server: Logical consistency-based I/O errorSQLITE_CORRUPTSQLite: database disk image is malformed
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.