I need to delete about 400 million rows from a 1.3 billion row table based on an indexed date field.
The table is about 800 GB in size.
What is the most efficient way to delete the data without causing adverse effects? The table is under heavy use, meaning lots of inserts and updates (which don't affect the rows to be deleted).
There is a maintenance window, which would be fastest, but I may not be able to get a big enough maintenance window. On the flip side, I can take my time with the delete, so there is no rush.
Best Answer
Figured a better way to do this
Insert into new_tbl select * from old_tbl where start_date < now -INTERVAL '2 years'
During downtime window:
Rename
old_tbl
toold_tbl_drop
andnew_tbl
toold_tbl
.old_tbl_drop
.