Re: transactional swap of tables

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: transactional swap of tables
Дата
Msg-id 1373639089.44097.YahooMailNeo@web162905.mail.bf1.yahoo.com
обсуждение исходный текст
Ответ на  (Vincenzo Romano <vincenzo.romano@notorand.it>)
Ответы Re: transactional swap of tables  (Vincenzo Romano <vincenzo.romano@notorand.it>)
Re: transactional swap of tables  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Vincenzo Romano <vincenzo.romano@notorand.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".

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


В списке pgsql-general по дате отправления:

Предыдущее
От: Melvin Call
Дата:
Сообщение: Distributed systems and primary keys
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Distributed systems and primary keys