Canonical URL
Do not index
Do not index
Related to Authors (1) (Content)
As simple as it sounds like, it isn’t. Recently I had the opportunity to delete over 34 million rows. I started with trying a noob approach, simply doing:
DELETE FROM subscribers WHERE zoneId = 'some_value'It didn’t work!
The postgres server took a brief pause, saw what I was trying to do and it silently exited the process.
Then I did what everyone does, asked chatgpt what should I do - I’m trying to delete 34 million rows. It suggested to use batching. I thought yeah, makes sense.
The code it gave me was this:
DELETE FROM subscribers
WHERE ctid IN (
SELECT ctid
FROM subscribers
WHERE zone_id = 'some_value'
AND partition = 'some_value'
AND created_at >= 'date_string' // 2020-12-12
LIMIT a_numeric
);