"initdb -t" destroys all databases

From: Richard Poole <richard(dot)poole(at)vi(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: "initdb -t" destroys all databases
Date: 2000-09-25 17:32:46
Message-ID: 20000925183246.M3414@office.vi.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

No response to this one on -general, so here goes...

The documentation for initdb says that the "-t" (== "--template") option
recreates the template1 database but doesn't touch anything else. But it
seems that if it detects a failure it will abort and remove anything it
*might* have created:

-- begin cut-and-paste

[barbra rp]/usr/lib/postgresql/bin/initdb -t -D /home/rp/tmp/pgtest
Updating template1 database only.
This database system will be initialized with username "rp".
This user will own all the data files and must also own the server process.

Creating template database in /home/rp/tmp/pgtest/base/template1
000925.16:49:28.545 [5432] FATAL 2: BootStrapXLOG failed to create control file (/home/rp/tmp/pgtest/pg_control): 17
000925.16:49:28.545 [5432] FATAL 2: BootStrapXLOG failed to create control file (/home/rp/tmp/pgtest/pg_control): 17

initdb failed.
Removing /home/rp/tmp/pgtest.
Removing temp file /tmp/initdb.5412.

-- end cut-and-paste

It seems that initdb starts a single-user backend but gives it the "-x"
option, which makes it call BootStrapXLOG, which fails because it
expects to be called only on absolutely first-time system startup (?).
initdb sees the failure and removes everything under the data directory,
which is the wrong behaviour here. Everything seems to be OK if I fix
initdb not to pass "-x" to postgres if it's been given "-t", but I don't
know enough to know that this is really the right thing. If it is, I'll
submit a patch; any opinions?

Richard

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-09-25 20:31:54 Re: "initdb -t" destroys all databases
Previous Message Alfred Perlstein 2000-09-25 16:58:59 Re: byacc problem with FreeBSD ...