initdb -t trashes the entire database system

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: initdb -t trashes the entire database system
Date: 2000-08-29 19:06:51
Message-ID: 200008291906.e7TJ6pu29191@hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

toby cabot (toby(at)caboteria(dot)org) reports a bug with a severity of 1
The lower the number the more severe it is.

Short Description
initdb -t trashes the entire database system

Long Description
Hi,

PostgreSQL is very cool, kudos to all who have worked hard to make it
so!

initdb is pretty dangerous, though; it deleted my $PGDATA directory.

I had a problem with my pgsql server (wouldn't start - something about
log file corruption) so I was looking around in the docs for some way to
truncate the log file (since the server was pretty quiet when it was
shut down). Anyway, I found "initdb -t" which looked like just the
ticket, especially as the docs say "You can't destroy anything by
running initdb with the --template option."

On running initdb I got:

[postgres(at)tiny pgsql]$ initdb -t
Updating template1 database only.
This database system will be initialized with username "postgres".
This user will own all the data files and must also own the server
process.

Creating template database in /usr/local/pgsql/data/base/template1
FATAL 2: BootStrapXLOG failed to create control file
(/usr/local/pgsql/data/pg_control): 17
FATAL 2: BootStrapXLOG failed to create control file
(/usr/local/pgsql/data/pg_control): 17
/usr/local/pgsql/bin/initdb: line 443: 7462 Broken pipe cat
"$TEMPLATE"
7463 | sed -e
"s/PGUID/$POSTGRES_SUPERUSERID/g"
7464 Done(2) | "$PGPATH"/postgres $FIRSTRUN
template1

initdb failed.
Removing /usr/local/pgsql/data.
Removing temp file /tmp/initdb.7446.
[postgres(at)tiny pgsql]$

and I realize with some shock that initdb has just deleted my $PGDATA
directory. It does this because it tries to clean up after itself in
case of errors. My feeling is that things are pretty much in an
undefined state after an error has occurred so the prudent thing to do
is give the user as much info as possible and then bail out. OTOH, I
don't want to rock the boat so here's a patch to initdb that makes -n
implicit in -t:

--- bin/initdb.orig Fri Aug 11 22:12:10 2000
+++ bin/initdb Fri Aug 11 22:33:59 2000
@@ -157,6 +157,7 @@
;;
--template|-t)
template_only=1
+ noclean=1 # don't trash existing data dir
echo "Updating template1 database only."
;;
# The sysid of the database superuser. Can be freely changed.

With this patch it still fails but in a more graceful way.

If anyone has any insight into why it -t fails that would be much
appreciated, too.

Regards,
Toby Cabot

Sample Code

No file was uploaded with this report

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2000-08-29 22:32:31 Re: Re: [GENERAL] cannot vacuum a database !
Previous Message pgsql-bugs 2000-08-29 18:02:06 prepareStatement.executeUpdate(deleteQuery) returns 1 even when no data deleted.