The only scalable delete in Postgres is DROP TABLE
- Databases
- Infrastructure
- Open Source
- Developer Tools
The post says PostgreSQL does not really have a cheap way to remove huge amounts of data with DELETE, because every deleted row still creates transactional and storage work that later has to be cleaned up by VACUUM. Its practical advice is to avoid row-by-row deletion when the shape of the workload allows it, especially for retention use cases, and instead delete whole chunks of data by dropping a table or partition. That is fast because the database mostly throws away metadata instead of touching every row.
If you own a high-volume Postgres system, treat bulk deletion as a data-modeling problem, not just a query problem. Use partitioning and retention boundaries where you can, and be wary of copy-swap-drop or DROP TABLE tricks in live OLTP paths because locking, foreign keys, and concurrency can turn a fast idea into an outage.
- planetscale.com
- Discuss on HN