Re: creating the same table in 2 different sessions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeroen van Iddekinge <iddekingej(at)lycos(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: creating the same table in 2 different sessions
Date: 2005-02-13 10:24:27
Message-ID: 27894.1108290267@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jeroen van Iddekinge <iddekingej(at)lycos(dot)com> writes:
> begin;
> create table a0(a bigint);

> than login for a second session
> begin
> create table a0(a bigint)

> postgres block nows in session 2

> when session 1 is commited the following error appears in session 2

> duplicate key violates unique constraint "pg_class_relname_nsp_index"

It's always worked like that; certainly as far back as 7.0, which is the
oldest version I have alive to test. The friendly "a0 already exists"
test falls through because a0 doesn't exist (at least it's not committed
at the time). The unique index mechanism is the last-ditch fallback
that prevents the race condition from actually creating a problem.

So: no bug, it's operating as designed. I agree that the error message
isn't as pretty as one might wish, but I don't think it's worth the
effort it would take to produce something else. (The solution you
suggest doesn't fix it, it only makes the window narrower.)

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeroen van Iddekinge 2005-02-13 10:57:56 creating the same table in 2 different sessions
Previous Message Pavel Stehule 2005-02-13 08:52:31 Re: slow SP with temporary tables, PLPGSQL problems