catalog is missing N attribute(s) for relid N

SQLSTATE XX001 condition data_corrupted class XX — Internal Error severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

PostgreSQL found a relation in pg_class whose pg_attribute rows are missing or fewer than expected. The system catalogs are inconsistent, so it raises SQLSTATE XX001 (data_corrupted).

What the server log shows

ERROR:  catalog is missing 2 attribute(s) for relid 24576

Why PostgreSQL raises this — what the manual says

Section 52.7 pg_attribute:

“There will be exactly one pg_attribute row for every column in every table in the database.”

Every column of a relation must have a matching pg_attribute row. If rows are missing, the catalog cannot describe the relation’s shape — corruption — so PostgreSQL reports XX001.

Common causes

How to fix it

  1. Back up the current state and treat this as serious corruption.
  2. Restore from a known-good backup.
  3. Run hardware/filesystem diagnostics; never hand-edit system catalogs to “fix” it.

Related & next steps

Reference: PostgreSQL 18 Section 53.7 “pg_attribute”.