Interview Prep/Real-World Interview/Data loss and corruption

Queries against one table fail with "ERROR: invalid page in block 48213 of relation base/16384/24576".

AdvancedTroubleshootingData loss and corruption
Answer

Likely causes → Physical corruption on disk: a storage or controller fault, a crash with fsync disabled, a bad volume restore, or a filesystem bug. Postgres page checksums detected it.

Diagnose →

SELECT relname FROM pg_class WHERE relfilenode = 24576;
SHOW data_checksums;
pg_amcheck --all --heapallindexed -d app
dmesg -T | grep -iE 'i/o error|ext4|xfs'

Check whether replicas have the same problem (physical replicas can copy corruption; logical ones usually don't).

Fix → Fail over to a healthy replica if it's clean, or restore from backup plus WAL to just before the corruption. Only as a last resort, to save what's left, use zero_damaged_pages = on on a copy and dump the readable rows; that permanently drops the damaged pages.

Prevent → Enable data checksums, never run with fsync = off, run pg_amcheck regularly, and keep tested backups with WAL archiving.

All Real-World Interview questions Roadmap: Interview readiness

More on Data loss and corruption