Re: transactional swap of tables

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: transactional swap of tables
Date: 2013-07-12 14:50:50
Message-ID: CAHjZ2x5Sa+rHN-Q33B0_H1FkMB0GKfuKtUQ3tZT0ojdnuOpAmg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it> wrote:
>
>> I'd like to "replace" a full table F with an empty one E.
>> In order to do this I see only one way:
>>
>> ALTER TABLE F RENAME TO T;
>> ALTER TABLE E RENAME TO F;
>> ALTER TABLE T RENAME TO E; -- optional
>>
>> This implies there's a moment when the full table doesn't exist.
>> Would a transaction enclosure ensure that the table F will be
>> always available to all clients?
>
> Yes. What you show is safe. What has a race condition is dropping
> the old table before all transactions which started with it have
> completed. If you're going to drop the old table, be sure to wait
> long enough after the COMMIT for things to "settle".

Would you please elaborate more on the "wait[ing] long enough after
the COMMIT" ?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Koichi Suzuki 2013-07-12 15:04:01 Re: Distributed systems and primary keys
Previous Message Joshua D. Drake 2013-07-12 14:46:47 Re: Distributed systems and primary keys