$ pm/1056374.sh 99 60 # create table with 99 rows, keep 60 DROP TABLE SELECT 100 CREATE INDEX ANALYZE count | records_to_keep | records_to_dump -------+-----------------+----------------- 100 | 60 | 40 (1 row) QUERY PLAN -------------------------------------------------------- Delete on t (cost=0.00..2.75 rows=39 width=6) -> Seq Scan on t (cost=0.00..2.75 rows=39 width=6) Filter: (d <= (now() - '60 days'::interval)) (3 rows) DELETE 40 count | records_to_keep | records_to_dump -------+-----------------+----------------- 60 | 60 | 0 (1 row) $ pm/1056374.sh 999 990 # create table with 999 rows, keep 990 DROP TABLE SELECT 1000 CREATE INDEX ANALYZE count | records_to_keep | records_to_dump -------+-----------------+----------------- 1000 | 990 | 10 (1 row) QUERY PLAN --------------------------------------------------------------------------- Delete on t (cost=0.28..8.45 rows=10 width=6) -> Index Scan using d_date_idx on t (cost=0.28..8.45 rows=10 width=6) Index Cond: (d <= (now() - '990 days'::interval)) (3 rows) DELETE 10 count | records_to_keep | records_to_dump -------+-----------------+----------------- 990 | 990 | 0 (1 row)