Diagnostic Queries
Symptoms
While reassembling an out-of-line TOAST value, PostgreSQL found chunks in the wrong order. This indicates data corruption, so it raises SQLSTATE XX001 (data_corrupted).
- TOAST chunk numbers don’t match the expected sequence.
- Points to corruption in the TOAST table or its index.
- Reads of the affected wide value fail.
What the server log shows
ERROR: unexpected chunk number 2 (expected 1) for toast value 24601 in pg_toast_16390
Why PostgreSQL raises this — what the manual says
Section 66.2.1 Out-of-Line, On-Disk TOAST Storage:
“Out-of-line values are divided (after compression if used) into chunks of at most TOAST_MAX_CHUNK_SIZE bytes (by default this value is chosen so that four chunk rows will fit on a page, making it about 2000 bytes).”
Large field values are split into numbered chunks in a TOAST table. If the chunk sequence is inconsistent (a chunk is misnumbered), the value cannot be reassembled and PostgreSQL reports XX001.
Common causes
- Storage-level corruption of the TOAST table or its index.
- Hardware faults, or crashes with disabled fsync.
- A corrupted TOAST index returning wrong rows.
How to fix it
- REINDEX the TOAST index; if data itself is damaged, restore from backup.
- Run hardware/filesystem checks; this signals real corruption.
- Identify the affected row and consider deleting/repairing it after backing up.
Related & next steps
Reference: PostgreSQL 18 Section 73.2 “TOAST”.
Thanks — noted. This helps keep the database accurate.