Re: Transactional-DDL DROP/CREATE TABLE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
Cc: Kevin Grittner <kgrittn(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Transactional-DDL DROP/CREATE TABLE
Date: 2016-10-06 17:33:28
Message-ID: 26376.1475775208@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Geoff Winkless <pgsqladmin(at)geoff(dot)dj> writes:
> On 6 October 2016 at 16:47, Kevin Grittner <kgrittn(at)gmail(dot)com> wrote:
>> I recommend using a transactional advisory lock to serialize these.

> Thanks Kevin, that does seem like the best (although not particularly
> pleasant) solution.

I'm a bit confused about exactly what the context is here. AFAICS,
the fragment you quoted should work as you expect, as long as the
table always exists beforehand. Then, the DROPs serialize the
transactions' access to the table and all is well[1]. On the other hand,
if the table *doesn't* exist beforehand, there is nothing to serialize
on and the behavior Adrian exhibited is what I'd expect. (It's a bit
unfortunate that the complaint is about a duplicate type name not
a duplicate relation name: that's an artifact of the order in which
the rows are stored into the catalogs, and maybe we should try to
change it, because it's confusing. But one way or the other you're
going to get a unique-index failure in whichever transaction is slightly
behind.)

But if all your transactions are doing this and only this to the table,
then there should never be an instant where the table doesn't exist.
Is there more DDL going on that you have not shown us?

regards, tom lane

[1] at least, since PG 9.2 or thereabouts.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Borodin 2016-10-06 17:39:30 Online course for those who want tot contribute
Previous Message Adrian Klaver 2016-10-06 17:25:46 Re: Transactional-DDL DROP/CREATE TABLE