Re: Best way to delete big amount of records from big table - Mailing list pgsql-performance

From Justin Pryzby
Subject Re: Best way to delete big amount of records from big table
Date
Msg-id 20200327150954.GG20103@telsasoft.com
Whole thread Raw
In response to Re: Best way to delete big amount of records from big table  (Michael Lewis <mlewis@entrata.com>)
List 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 by date:

Previous
From: Rick Otten
Date:
Subject: Re: Best way to delete big amount of records from big table
Next
From: Ekaterina Amez
Date:
Subject: Re: Best way to delete big amount of records from big table