Re: Postgres db corrupted ? - Mailing list pgsql-admin

From Tom Lane
Subject Re: Postgres db corrupted ?
Date
Msg-id 29907.1059497704@sss.pgh.pa.us
Whole thread Raw
In response to Re: Postgres db corrupted ?  ("John P. Looney" <valen@tuatha.org>)
Responses Re: Postgres db corrupted ?  ("John P. Looney" <valen@tuatha.org>)
List pgsql-admin
"John P. Looney" <valen@tuatha.org> writes:
>> If no go, could we see the output of "select * from pg_database"?

>  Yep, no worries...

> postgres=# select * from pg_database;
>      datname     | datdba | encoding | datistemplate | datallowconn | datlastsysoid | datvacuumxid | datfrozenxid |
datpath
>
-----------------+--------+----------+---------------+--------------+---------------+--------------+--------------+---------
>  bbadmin         |        |        0 | f             | t            |         16554 |           49 |           49 |

Hm, that datdba field actually is NULL, isn't it?  That's what you need
to fix.  The low-level code isn't expecting it to be NULL, and falls
over in surprising ways.  (Recent releases try to enforce NOT NULL on
system catalog columns that mustn't be NULL, but I'm not sure how
bulletproof that really is.)

I'd try

UPDATE pg_database SET datdba = <something reasonable> WHERE datdba IS NULL;

You could just set them all to 1 (the postgres userid); if you want
these databases owned by specific users then see pg_shadow.usesysid for
the numbers to insert.

Once you have all the entries fixed, do the "VACUUM FULL pg_database"
fandango for good luck, and you should be back in business.

            regards, tom lane

pgsql-admin by date:

Previous
From: "Benjamin Thelen (CCGIS)"
Date:
Subject: changing ownership of db
Next
From: "John P. Looney"
Date:
Subject: Re: Postgres db corrupted ?