Re: createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"

From: Dave Vitek <dvitek(at)grammatech(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"
Date: 2010-03-11 20:17:04
Message-ID: 4B994FC0.1030801@grammatech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi again,

I'm going to answer my own question. I think there is a race where two
database servers are being setup on the same port at the same time and
two different tests end up trying to create the same DB on the same
server at the same time.

Let me know if you think I'm wrong :).

Dave Vitek wrote:
> 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
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2010-03-11 22:34:40 PgEast Hotel discount deadline today!
Previous Message Dave Vitek 2010-03-11 19:46:37 createdb: ... duplicate key value violates unique constraint "pg_database_datname_index"