Re: using DROP in a transaction - Mailing list pgsql-general

From Tom Lane
Subject Re: using DROP in a transaction
Date
Msg-id 18877.1202429210@sss.pgh.pa.us
Whole thread Raw
In response to using DROP in a transaction  ("Willy-Bas Loos" <willybas@gmail.com>)
Responses Re: using DROP in a transaction
List pgsql-general
"Willy-Bas Loos" <willybas@gmail.com> writes:
> then in TTY2, run
>   begin;
>   drop table test;
>   create table test (id int4 primary key);
>   insert into test (id) values (2);

> then, in TTY1:
>   select * from test;

> Actually, i thought of a longer test, but it stops here - there is no
> response, no prompt anaymore, until i cancel the query.

DROP TABLE takes an exclusive lock.  The SELECT is waiting for that
lock to be released.

You could shorten the length of the exclusive lock by creating and
filling the replacement table under a new name, then DROP, then
rename the new table into place and immediately commit.  But you
aren't going to be able to eliminate it entirely.

            regards, tom lane

pgsql-general by date:

Previous
From: "Willy-Bas Loos"
Date:
Subject: Re: using DROP in a transaction
Next
From: SunWuKung
Date:
Subject: Re: "advanced" database design (long)