Re: Best way to delete big amount of records from big table

Поиск
Список
Период
Сортировка
От Justin Pryzby
Тема Re: Best way to delete big amount of records from big table
Дата
Msg-id 20200327150954.GG20103@telsasoft.com
обсуждение исходный текст
Ответ на Re: Best way to delete big amount of records from big table  (Michael Lewis <mlewis@entrata.com>)
Список pgsql-performance
On Fri, Mar 27, 2020 at 08:41:04AM -0600, Michael Lewis wrote:
> 2) If you are deleting/moving most of the table (91 of 150 million),
> consider moving only the records you are keeping to a new table, renaming
> old table, and renaming new table back to original name. Then you can do
> what you want to shift the data in the old table and delete it.

You could also make the old table a child of (inherit from) the new table.
That allows you to remove rows separately from removing them.
Partitioning (with legacy inheritence or the new, integrated way available in
postgres 10) allows DROPing oldest tables rather than DELETEing from one
gigantic table.

You should consider somehow cleaning up the old table after you DELETE from it,
maybe using vacuum full (which requires a long exclusive lock) or pg_repack
(which briefly acquires an exclusive lock).

-- 
Justin



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

Предыдущее
От: Rick Otten
Дата:
Сообщение: Re: Best way to delete big amount of records from big table
Следующее
От: Ekaterina Amez
Дата:
Сообщение: Re: Best way to delete big amount of records from big table