Postgres pg_dump catalog attribute missing error

Viewed 18

I’ve been attempting to backup my remote database to my local system, with the following command I found in some other resources :

ssh user@host “pg_dump -U username -h localhost -d dbname -C —-column-inserts” \ mybackup.sql

The result was :

pg_dump: error: query failed: ERROR: catalog is missing 2 attribute(s) for relid 18141

I’m actually not so much experienced with databases, I searched for the error but none of them made much sense for me to be honest. Anyone can help me with the issue?

1 Answers

You have catalog corruption: the pg_class entry for relation 18141 has a value of relnatts that is two more than the number of rows in pg_attribute that have attrelid equal to 18141. Just as the error message says: two attributes (= columns) are missing.

Research your conscience what you did to corrupt the catalog. Did you use bad hardware and had crashes? Did you manually manipulate the catalog tables?

You should restore your last good backup.

However, if you want to try to salvage data from that database: If you are extremely lucky, you are dealing with a corrupted index. That could be rebuilt with

REINDEX INDEX pg_catalog.pg_attribute_relid_attnum_index;

If that works, dump the whole table and restore it to a freshly created PostgreSQL cluster to leave all corruption behind. If that is not enough, hire an expert who can try to salvage some data from the wreck.

Related