createdb: ... duplicate key value violates unique constraint "pg_database_datname_index" - Mailing list pgsql-general

From Dave Vitek
Subject createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"
Date
Msg-id 4B99489D.7000900@grammatech.com
Whole thread Raw
Responses Re: createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"
List pgsql-general
Hi all,

On a new x86_64 windows 7 SMP, a new database server was being set up by
some test automation.  We are using official 8.4.2 binaries.

It runs:
initdb -D c:\... --no-locale

... eventually this outputs the "Success. You can now start the database
server using ..." message.  Once that exits (with 0) it proceeds to
start postgres:

postgres -D c:\...

Then we wait for the .pid file to show up.

Once that happens we do createdb:
createdb -h 127.0.0.1 -p 1234 abc
createdb: database creation failed: ERROR: duplicate key value violates
unique constraint "pg_database_datname_index"

This is not reproducible and only happens occasionally.  We do sometimes
get the "database is starting up" error (and we just retry if that
happens).  For technical reasons I no longer remember, we found it
problematic to use pg_ctl -w on windows, and I do not remember whether
it always waited long enough anyway.

Is there a proper way to wait for postgres to start up other than
waiting until the pid file exists and retrying things whenever you get
the "database is starting up" error?  Is the error I am describing
indicative of something else?

Once, we got this slightly different error when creating the second
table in the freshly created database:

duplicate key value violates unique constraint "pg_type_typname_nsp_index"

It had some primitive columns and a foreign key reference to the first
table (which only had primitive columns).

We run this test automation quite a few platforms and have never
encountered this problem on any of them:
- All flavors of windows NT from win2k onwards, including an older win7 box
- linux: x86 + x86_64
- macos: x86_64
- solaris: sparc + x86 + x86_64

- Dave



pgsql-general by date:

Previous
From: "Garrett Murphy"
Date:
Subject: Re: Joining one-to-one and one-to-many tables
Next
From: Dave Vitek
Date:
Subject: Re: createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"