Postgres DELETE Can Actualy Scale
Postgres DELETE can scale for data retention if you design around MVCC churn, cache locality and dead tuples. In DBOS's durable workflow system, ON DELETE CASCADE foreign keys from step_outputs to workflow_status forced scattered page fetches, so the team dropped the foreign keys and batch-deleted each table separately in physical creation order, using a NOT EXISTS anti-join to keep data for still-active workflows. A created_at index lookup occasionally took 20 minutes because millions of unvacuumed dead tuples piled up at the front of the index and each had to be checked against the heap. Running a manual VACUUM before and after each retention pass fixed it, and the combined changes made deletion an order of magnitude faster, while keeping per-row flexibility that partition dropping can't offer for long-running or heterogeneous retention.
Related posts
- Postgres Bloat Minimization
Supabase mediumAdeptPostgres stores table rows in 8KB heap pages and writes a new row version on every update, so dead versions accumulate until vacuum reclaims them and updates the free-space and visibility maps. Bloat usually means autovacuum never started, because the default 20% scale factor is too high for large tables, or it started but couldn't finish because of long-running idle transactions or SHARE UPDATE EXCLUSIVE locks. The fixes include lowering per-table scale factors, setting idle_in_transaction_session_timeout, cancelling stuck backends, and raising autovacuum_max_workers or autovacuum_work_mem. VACUUM FULL or pg_repack returns space to the filesystem after mass deletes; VACUUM FULL takes an exclusive lock and pg_repack does not.
- I don't trust ON DELETE CASCADE
PlanetScale mediumAdeptPostgres ON DELETE CASCADE turns a single-row delete into an unbounded transaction that can cause outages at scale. The cascade holds RowExclusiveLock on every table in the tree, so a migration requesting AccessExclusiveLock queues behind it and blocks all later writes. It can also generate hundreds of gigabytes of WAL that stall synchronous replication, and it falls back to sequential scans on unindexed foreign keys. With logical replication it can leave orphaned rows on subscribers, which skip cascade triggers, and it fails outright on published tables lacking a replica identity. The recommended alternative is soft deletes via a deleted_at column, followed by batched background reaping and vacuum, keeping transactions to hundreds or low thousands of rows.
- 6 tips to optimize storage costs for your Postgres databases
Neon mediumAdept
Six ways to shrink Postgres storage spend: drop unused indexes (found via pg_stat_user_indexes and pg_index), avoid full database copies for dev and staging by using Neon's copy-on-write branching, choose smaller data types like SMALLINT, order columns largest to smallest to cut alignment padding, shorten Neon's history retention window, and tune autovacuum to limit bloat. Shorter retention saves storage but narrows the point-in-time recovery window. For bloat, look in pg_stat_activity for long-running transactions that block autovacuum.
- Postgres on NVMe: performance and the convergence of transactions and analytics
ClickHouse mediumAdept
Running Postgres on local NVMe instead of gp3 EBS gave 9.2× more throughput (16,030 vs 1,734 TPS) and UPDATE latency of 4.0 ms vs 36.9 ms in a pgbench benchmark with a 482 GiB dataset about 30× larger than RAM. Profiling showed EBS backends spending 89% of wall time blocked on I/O. VACUUM ran 2.6× faster on NVMe, while logical decoding gained only 1.7× because it is single-threaded. To offset NVMe's ephemerality, durability moves into Postgres via quorum synchronous replication across AZs plus continuous WAL archival to S3 with WAL-G. Analytics still needs a columnar engine, so the recommended pattern is CDC (PeerDB, or the new WalShadow) into ClickHouse, queried through the pg_clickhouse extension.
- Leveraging Change Data Capture For Database Migrations At Scale
Squarespace Engineering mediumAdeptSquarespace migrated many PostgreSQL databases to CockroachDB without write downtime by streaming changes through a CDC pipeline: pgoutput logical decoding feeds per-table Debezium connectors into Kafka (Avro), and per-table Apache Beam pipelines on Dataflow upsert batched events into CRDB with checkpointing and backpressure. A reverse changefeed into a separate Kafka queue gave a rollback path to Postgres, and a homegrown diffing tool validated data before cutting over via a proxy. Snapshots reached about 60k rows/s and most systems were over 99.99% fresh at cutover, though some needed brief write pauses. Foreign-key failures across independent per-table writers, including cyclic constraints CRDB can't defer, were handled by disabling constraints during the isolated migration and restoring them before cutover.