Home / Companies / PlanetScale / Blog / Post Details
Content Deep Dive

The only scalable delete in Postgres is DROP TABLE

Blog post from PlanetScale

Post Details
Company
Date Published
Author
structuring your schema to avoid large bulk DELETE, pg_squeeze becomes less necessary.In cases where the data to keep is much larger than the data to discard, but the data to discard is still substantial, the typical approach is to perform many isolated b
Word Count
1,187
Language
English
Hacker News Points
-
Summary

Deleting data in PostgreSQL can be resource-intensive, especially at large scales, due to the way the database manages row versions and space. Large DELETE operations do not immediately free disk space and add additional load due to the need for replication and maintaining multiple row versions through Multi-Version Concurrency Control (MVCC). This can lead to increased work for read queries and autovacuum processes. In contrast, DROP TABLE and TRUNCATE operations are more efficient for large data deletions as they remove data files directly from the operating system, freeing up space immediately, and do not generate dead tuples or vacuum debt. For scenarios where a large amount of data must be deleted, restructuring the database schema to allow for DROP TABLE or TRUNCATE instead of DELETE can greatly enhance performance and scalability. This can be particularly useful in cases of schema designs utilizing partitioning, which allows for efficient data management by converting frequent DELETE operations into occasional DROP TABLE operations. Additionally, employing a trigger-based approach or pg_squeeze for large-scale data deletions can further optimize database performance by preventing bloat and reducing replication lag.