pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgres db corrupted ?
13+ messages / 3 participants
[nested] [flat]
* Postgres db corrupted ?
@ 2003-07-29 09:28 John P. Looney <valen@tuatha.org>
0 siblings, 2 replies; 13+ messages in thread
From: John P. Looney @ 2003-07-29 09:28 UTC (permalink / raw)
To: pgsql-admin
What's up here ? Google is deathly silent.
bash-2.05a$ pg_dumpall > db.out
connected to template1...
dumping database "MyPgSQLTest"...
dumping database "bb1"...
dumping database "bbadmin"...
pg_dump: [archiver (db)] connection to database "bbadmin" failed: FATAL
1: SetDatabaseEncoding(): invalid database encoding
pg_dump failed on bbadmin, exiting
Hmm. Curiously, the database I'm playing with;
bbadmin | | SQL_ASCII
Says it is SQL_ASCII...but it doesn't have an owner.
Would this mean the database is corrupt ? This is on 7.2.3 - I had been
running 7.1.3 and upgraded with the assistance pg_dumpall. Is this an
artifact of the upgrade ?
John
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 14:38 Tom Lane <tgl@sss.pgh.pa.us>
parent: John P. Looney <valen@tuatha.org>
1 sibling, 1 reply; 13+ messages in thread
From: Tom Lane @ 2003-07-29 14:38 UTC (permalink / raw)
To: John P. Looney <valen@tuatha.org>; +Cc: pgsql-admin
"John P. Looney" <valen@tuatha.org> writes:
> What's up here ? Google is deathly silent.=20
> bash-2.05a$ pg_dumpall > db.out
> connected to template1...
> dumping database "MyPgSQLTest"...
> dumping database "bb1"...
> dumping database "bbadmin"...
> pg_dump: [archiver (db)] connection to database "bbadmin" failed: FATAL
> 1: SetDatabaseEncoding(): invalid database encoding
> pg_dump failed on bbadmin, exiting
A quick-and-dirty nostrum that sometimes helps for this sort of thing
is "vacuum full pg_database". (The idea is to get rid of dead tuples
that a new backend might be accidentally picking instead of the live
ones --- it has to read pg_database before it's joined the PROC array,
which among other things means it can't tell 100% accurately which rows
are really committed.)
If no go, could we see the output of "select * from pg_database"?
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 16:22 John P. Looney <valen@tuatha.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: John P. Looney @ 2003-07-29 16:22 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
On Tue, Jul 29, 2003 at 10:38:50AM -0400, Tom Lane mentioned:
> A quick-and-dirty nostrum that sometimes helps for this sort of thing
> is "vacuum full pg_database". (The idea is to get rid of dead tuples
> that a new backend might be accidentally picking instead of the live
> ones --- it has to read pg_database before it's joined the PROC array,
> which among other things means it can't tell 100% accurately which rows
> are really committed.)
Ah, OK. That's the sort of help I was hoping to get. Alas, for very
different reasons (I'd run out of ideas), I'd run that myself, with no
gain.
> 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
-----------------+--------+----------+---------------+--------------+---------------+--------------+--------------+---------
pguser | | 0 | f | t | 16554 | 611746 | 3221837219 |
phpuser-654937 | | 0 | f | t | 16554 | 611746 | 3221837219 |
gestr-654937 | | 0 | f | t | 16554 | 611746 | 3221837219 |
template0 | 1 | 0 | t | f | 16554 | 49 | 49 |
postgres | 1 | 0 | f | t | 16554 | 658793 | 658793 |
rob-654937 | | 0 | f | t | 16554 | 611746 | 3221837219 |
template1 | 1 | 0 | t | t | 16554 | 611746 | 3221837219 |
testtest | 28 | 0 | f | t | 16554 | 49 | 49 |
dsitestogo | 33 | 0 | f | t | 16554 | 49 | 49 |
bb1 | 36 | 0 | f | t | 16554 | 49 | 49 |
carlstest | 37 | 0 | f | t | 16554 | 49 | 49 |
pgdbase | 38 | 0 | f | t | 16554 | 49 | 49 |
novadance | 41 | 0 | f | t | 16554 | 49 | 49 |
MyPgSQLTest | 43 | 0 | f | t | 16554 | 49 | 49 |
forum | 45 | 0 | f | t | 16554 | 49 | 49 |
ct2 | 48 | 0 | f | t | 16554 | 49 | 49 |
directory | 49 | 0 | f | t | 16554 | 49 | 49 |
faqsection | 50 | 0 | f | t | 16554 | 49 | 49 |
demo | 51 | 0 | f | t | 16554 | 49 | 49 |
planetepochdb | 53 | 0 | f | t | 16554 | 49 | 49 |
bbadmin | | 0 | f | t | 16554 | 49 | 49 |
shanecody | | 0 | f | t | 16554 | 49 | 49 |
dmduffy-654937 | | 0 | f | t | 16554 | 49 | 49 |
zozallen-665478 | | 0 | f | t | 16554 | 49 | 49 |
zozhugh-665478 | | 0 | f | t | 16554 | 49 | 49 |
zozea | 41 | 0 | f | t | 16554 | 49 | 49 |
(26 rows)
John
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 16:55 Tom Lane <tgl@sss.pgh.pa.us>
parent: John P. Looney <valen@tuatha.org>
0 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2003-07-29 16:55 UTC (permalink / raw)
To: valen@tuatha.org; +Cc: 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
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 17:06 John P. Looney <valen@tuatha.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: John P. Looney @ 2003-07-29 17:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
On Tue, 2003-07-29 at 17:55, Tom Lane wrote:
> 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.)
Ah, OK. That makes sense.
> 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.
OK; is there an already existing table that should have those entries
in it ? As a postgres novice, does that mean that these broken tables
aren't accessible ?
John
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 17:28 Tom Lane <tgl@sss.pgh.pa.us>
parent: John P. Looney <valen@tuatha.org>
0 siblings, 0 replies; 13+ messages in thread
From: Tom Lane @ 2003-07-29 17:28 UTC (permalink / raw)
To: John P. Looney <valen@tuatha.org>; +Cc: pgsql-admin
"John P. Looney" <valen@tuatha.org> writes:
> OK; is there an already existing table that should have those entries
> in it ? As a postgres novice, does that mean that these broken tables
> aren't accessible ?
pg_database *is* the table that should have those entries in it. I'm
not real sure how you got into this state, but given that you are in it,
the "SetDatabaseEncoding" failure will probably occur when you try to
connect to any of the databases with the bad pg_database rows.
Fortunately, since that table is shared across databases, you can fix it
from a connection to any of the non-broken databases (like template1).
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-29 23:49 Mendola Gaetano <mendola@bigfoot.com>
parent: John P. Looney <valen@tuatha.org>
1 sibling, 1 reply; 13+ messages in thread
From: Mendola Gaetano @ 2003-07-29 23:49 UTC (permalink / raw)
To: pgsql-admin; +Cc: \"John P. Looney\" <valen@tuatha.org>
""John P. Looney"" <valen@tuatha.org> writes:
> bbadmin | | SQL_ASCII
For sure a way to obtain this inconsistence is delete the owner of
a db and voila' a DB result to have no owner.
May be is a good idea that the user postgres adopt these orfan DB.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-30 14:26 Tom Lane <tgl@sss.pgh.pa.us>
parent: Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 2 replies; 13+ messages in thread
From: Tom Lane @ 2003-07-30 14:26 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: pgsql-admin@postgresql.org, "\"John P. Looney\"" <valen@tuatha.org>
"Mendola Gaetano" <mendola@bigfoot.com> writes:
> ""John P. Looney"" <valen@tuatha.org> writes:
>> bbadmin | | SQL_ASCII
> For sure a way to obtain this inconsistence is delete the owner of
> a db and voila' a DB result to have no owner.
Nope. I don't know how John got into this state, but it most definitely
was not that way. Try it.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-30 14:43 Mendola Gaetano <mendola@bigfoot.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 13+ messages in thread
From: Mendola Gaetano @ 2003-07-30 14:43 UTC (permalink / raw)
To: pgsql-admin; +Cc: Tom Lane <tgl@sss.pgh.pa.us>
"Tom Lane" <tgl@sss.pgh.pa.us>
> "Mendola Gaetano" <mendola@bigfoot.com> writes:
> > ""John P. Looney"" <valen@tuatha.org> writes:
> >> bbadmin | | SQL_ASCII
>
> > For sure a way to obtain this inconsistence is delete the owner of
> > a db and voila' a DB result to have no owner.
>
> Nope. I don't know how John got into this state, but it most definitely
> was not that way. Try it.
Here it his:
kalman@XXX [] > createuser jfk
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) y
CREATE USER
kalman@XXX [] > psql -U jfk template1
Welcome to psql 7.3.3, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
template1=# create database db_jfk;
CREATE DATABASE
template1=# \q
kalman@XXX [] > psql -l | grep jfk
db_jfk | jfk | SQL_ASCII
kalman@XXX [] > psql template1
Welcome to psql 7.3.3, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
template1=# delete from pg_shadow where usename = 'jfk';
DELETE 1
template1=# \q
kalman@XXX [] > psql -l | grep jfk
db_jfk | | SQL_ASCII
Regards
Gaetano
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-30 14:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2003-07-30 14:54 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: pgsql-admin
"Mendola Gaetano" <mendola@bigfoot.com> writes:
> "Tom Lane" <tgl@sss.pgh.pa.us>
>> Nope. I don't know how John got into this state, but it most definitely
>> was not that way. Try it.
> Here it his:
No, you're looking at the result of psql -l. What John was showing us
was the actual contents of pg_database, which would still contain a
numeric datdba value after your example.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-30 16:01 Mendola Gaetano <mendola@bigfoot.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: Mendola Gaetano @ 2003-07-30 16:01 UTC (permalink / raw)
To: pgsql-admin; +Cc: Tom Lane <tgl@sss.pgh.pa.us>
"Tom Lane" <tgl@sss.pgh.pa.us> wrote:
> "Mendola Gaetano" <mendola@bigfoot.com> writes:
> > "Tom Lane" <tgl@sss.pgh.pa.us>
> >> Nope. I don't know how John got into this state, but it most
definitely
> >> was not that way. Try it.
>
> > Here it his:
>
> No, you're looking at the result of psql -l. What John was showing us
> was the actual contents of pg_database, which would still contain a
> numeric datdba value after your example.
>
> regards, tom lane
You're right ( like usual :-) )
but you agree anyway that should not possible delete
a user that own DB object or at least change the owner
to postgres?
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-30 16:26 Tom Lane <tgl@sss.pgh.pa.us>
parent: Mendola Gaetano <mendola@bigfoot.com>
0 siblings, 0 replies; 13+ messages in thread
From: Tom Lane @ 2003-07-30 16:26 UTC (permalink / raw)
To: Mendola Gaetano <mendola@bigfoot.com>; +Cc: pgsql-admin
"Mendola Gaetano" <mendola@bigfoot.com> writes:
> but you agree anyway that should not possible delete
> a user that own DB object or at least change the owner
> to postgres?
If you do it the approved way, with DROP USER, you'll find there's
already an interlock:
regression=# create user foo;
CREATE USER
regression=# create database foo owner foo;
CREATE DATABASE
regression=# drop user foo;
ERROR: user "foo" cannot be dropped
DETAIL: The user owns database "foo".
regression=#
When you issue direct UPDATE/DELETEs on the system catalogs, consistency
is your responsibility.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Postgres db corrupted ?
@ 2003-07-31 08:21 John P. Looney <valen@tuatha.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 13+ messages in thread
From: John P. Looney @ 2003-07-31 08:21 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Mendola Gaetano <mendola@bigfoot.com>; pgsql-admin
On Wed, 2003-07-30 at 15:26, Tom Lane wrote:
> "Mendola Gaetano" <mendola@bigfoot.com> writes:
> > ""John P. Looney"" <valen@tuatha.org> writes:
> >> bbadmin | | SQL_ASCII
>
> > For sure a way to obtain this inconsistence is delete the owner of
> > a db and voila' a DB result to have no owner.
>
> Nope. I don't know how John got into this state, but it most definitely
> was not that way. Try it.
OK, it turns out that the cause was the shared hosting admin software
that was trying to add users and databases had some wierd problems
(hidden obscure shell scripts crashing out when it couldn't find an up
to date text dump of the pg_shadow file), which resulted in tables being
created, given specific sysids for users that weren't created.
Anyway, it looks like it wasn't a postgres bug that caused the
problems. If any field should be considered "not null" though, it's that
owner field!
John
Attachments:
signature.asc (application/pgp-signature, 188B) download
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2003-07-31 08:21 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-07-29 09:28 Postgres db corrupted ? John P. Looney <valen@tuatha.org>
2003-07-29 14:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-29 16:22 ` John P. Looney <valen@tuatha.org>
2003-07-29 16:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-29 17:06 ` John P. Looney <valen@tuatha.org>
2003-07-29 17:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-29 23:49 ` Mendola Gaetano <mendola@bigfoot.com>
2003-07-30 14:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-30 14:43 ` Mendola Gaetano <mendola@bigfoot.com>
2003-07-30 14:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-30 16:01 ` Mendola Gaetano <mendola@bigfoot.com>
2003-07-30 16:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-07-31 08:21 ` John P. Looney <valen@tuatha.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox