creating the same table in 2 different sessions - Mailing list pgsql-hackers

From Jeroen van Iddekinge
Subject creating the same table in 2 different sessions
Date
Msg-id 420F32B4.1060400@lycos.com
Whole thread Raw
Responses Re: creating the same table in 2 different sessions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

Maybe I found the following bug or 'not ideal behaviour'  of 
postgres(version 7.4.7 and 8.0 /linux):

first start asession 1

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"
So i think postgres first inserts into pg_class, but blocks in session 2 
because of the unique the unique index on (relname,relnamespace). I just 
wonder if it's safer to check if the table is being created in an other 
session, 'block' until the session is commited block before starting any 
insert or other action? Or when the error 'duplicate key violates unique 
constraint "pg_class_relname_nsp_index"' hapens during creating of a 
table ,raise  the error 'duplicate key violates unique constraint 
"pg_class_relname_nsp_index", maybe table allready exists' ?


Regards,
   Jeroen


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: slow SP with temporary tables, PLPGSQL problems
Next
From: Tom Lane
Date:
Subject: Re: creating the same table in 2 different sessions