Re: Unloading a table consistently

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: Unloading a table consistently
Дата
Msg-id 481DD610.5010206@postnewspapers.com.au
обсуждение исходный текст
Ответ на Re: Unloading a table consistently  (ptjm@news-reader-radius.uniserve.com (Patrick TJ McPhee))
Список pgsql-general
Patrick TJ McPhee wrote:

> How about something along the lines of
>
> BEGIN;
> ALTER TABLE log RENAME to log_old;
> CREATE TABLE log(...);
> COMMIT;
>
> BEGIN;
> LOCK table log_old;
> COPY log_old TO 'filename-path';
> DROP TABLE log_old;
> COMMIT;
>
> I believe this will keep the writers writing while keeping the efficiency
> of truncating.

It's almost a pity that there's no

TRUNCATE TABLE log MOVE DATA TO log_copy;

or similar; ie with two identical table definitions `log' and `log_copy'
swap the backing file from `log' to `log_copy' before truncating `log'.

`log_copy' could be a new temp table created with CREATE TEMPORARY TABLE
... LIKE.

This sort of thing doesn't seem to come up all that much, though.

--
Craig Ringer

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

Предыдущее
От: "Roberts, Jon"
Дата:
Сообщение: Re: SQL window functions
Следующее
От: Hannes Dorbath
Дата:
Сообщение: Re: SQL window functions