Thread: BUG #5347: initdb does not work when a data directory has been deleted

BUG #5347: initdb does not work when a data directory has been deleted

From
"David Andersen"
Date:
The following bug has been logged online:

Bug reference:      5347
Logged by:          David Andersen
Email address:      david.andersen@andersen-innovation.com
PostgreSQL version: 8.4.2
Operating system:   Windows 7 64-bit
Description:        initdb does not work when a data directory has been
deleted
Details:

I had my database placed at /data. The data in that database was somehow
corrupted (my mistake) so I dropped the database with the following
warnings:

postgres=# drop database adatabase;
WARNING:  could not remove file or directory "base/16397": Directory not
empty
WARNING:  some useless files may be left behind in old database directory
"base/16397"
DROP DATABASE

I then deleted the whole directory /data and attempted to run initdb again
as seen below. A workaround, which worked was to run initdb -D ..\data3. So
the severity of this bug is very low, but I want postgresql to be perfect!

C:\Program Files (x86)\PostgreSQL\8.4\bin>initdb -D ..\data
The files belonging to this database system will be owned by user "David
Andersen".
This user must also own the server process.

The database cluster will be initialized with locale Danish_Denmark.1252.
The default database encoding has accordingly been set to WIN1252.
The default text search configuration will be set to "danish".

initdb: directory "../data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "../data" or run initdb
with an argument other than "../data".

C:\Program Files (x86)\PostgreSQL\8.4\bin>dir ..
 Volume in drive C is OS
 Volume Serial Number is 2A35-DFB6

 Directory of C:\Program Files (x86)\PostgreSQL\8.4

26-02-2010  12:34    <DIR>          .
26-02-2010  12:34    <DIR>          ..
22-02-2010  15:16    <DIR>          bin
02-02-2010  11:07    <DIR>          csv
04-02-2010  11:11       321.557.856 csv.zip
23-02-2010  19:57    <DIR>          data2
29-01-2010  21:36    <DIR>          doc
29-01-2010  21:36    <DIR>          include
29-01-2010  21:36    <DIR>          installer
29-01-2010  21:36    <DIR>          lib
29-01-2010  21:36    <DIR>          pgAdmin III
29-01-2010  21:37               358 pg_env.bat
08-02-2010  11:10    <DIR>          scripts
29-01-2010  21:36    <DIR>          share
29-01-2010  21:36    <DIR>          StackBuilder
29-01-2010  21:37    <DIR>          symbols
29-01-2010  21:37         2.914.462 uninstall-postgresql.exe
               3 File(s)    324.472.676 bytes
              14 Dir(s)  197.489.139.712 bytes free

C:\Program Files (x86)\PostgreSQL\8.4\bin>

Re: BUG #5347: initdb does not work when a data directory has been deleted

From
Tom Lane
Date:
"David Andersen" <david.andersen@andersen-innovation.com> writes:
> [ initdb fails with ]
> initdb: directory "../data" exists but is not empty
> If you want to create a new database system, either remove or empty
> the directory "../data" or run initdb
> with an argument other than "../data".

This is not a bug.  It's an intentional safety feature to prevent people
from accidentally wiping out their databases by re-initdb'ing over them.
If you really want to re-initdb, do what the message tells you to.

            regards, tom lane

Re: BUG #5347: initdb does not work when a data directory has been deleted

From
David Andersen
Date:
Hi Tom,

Thank you for your answer. The error message states:
"initdb: directory "../data" exists but is not empty"
This is wrong. ../data does not exist

It then states:
"If you want to create a new database system, either remove or empty the
directory "../data" or run initdb with an argument other than "../data".
The first part of this sentence is what I attempted to do, and it did not
work.


Regards,

David


On Fri, Feb 26, 2010 at 16:52, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "David Andersen" <david.andersen@andersen-innovation.com> writes:
> > [ initdb fails with ]
> > initdb: directory "../data" exists but is not empty
> > If you want to create a new database system, either remove or empty
> > the directory "../data" or run initdb
> > with an argument other than "../data".
>
> This is not a bug.  It's an intentional safety feature to prevent people
> from accidentally wiping out their databases by re-initdb'ing over them.
> If you really want to re-initdb, do what the message tells you to.
>
>                        regards, tom lane
>

Re: BUG #5347: initdb does not work when a data directory has been deleted

From
Tom Lane
Date:
David Andersen <david.andersen@andersen-innovation.com> writes:
> Thank you for your answer. The error message states:
> "initdb: directory "../data" exists but is not empty"
> This is wrong. ../data does not exist

I really, really doubt that the code gets that test wrong.

Your message suggested that you might have typed ..\data when you meant
\data, or vice versa --- you might want to double check exactly which
directory you meant.  Personally I dislike using relative paths for data
directories; it's much too easy to mess up.

            regards, tom lane