SQLSTATE XX001 ERROR Class XX: Internal Error

data_corrupted unexpected chunk number N (expected N) for toast value N — XX001

PostgreSQL error "unexpected chunk number N (expected N) for toast value N" (SQLSTATE XX001): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. REINDEX the TOAST index; if data itself is damaged, restore from backup.
  2. Run hardware/filesystem checks; this signals real corruption.
  3. Identify the affected row and consider deleting/repairing it after backing up.

Related & next steps

Reference: PostgreSQL 18 Section 73.2 “TOAST”.

Was this helpful?