---
title: "Postgres DELETE Can Actualy Scale"
description: "Postgres DELETE can scale for data retention if you design around MVCC churn, cache locality and dead tuples."
url: "https://swe.quest/articles/postgres-delete-can-actualy-scale-9f7f79b6782a5f75"
canonical: "https://www.dbos.dev/blog/scaling-deletions-in-postgres"
source: "DBOS"
published: "2026-09-17"
difficulty: "medium"
kind: "Case study"
reading_minutes: 7
tags: ["postgres","storage-engines","performance","databases"]
---

# Postgres DELETE Can Actualy Scale

A post on [DBOS](https://swe.quest/sources/dbos.md), published 2026-09-17, 7 min read, Case study. Original: [https://www.dbos.dev/blog/scaling-deletions-in-postgres](https://www.dbos.dev/blog/scaling-deletions-in-postgres)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Storage engines](https://swe.quest/tags/storage-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- PostgreSQL MVCC ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- B-tree indexes ([easy posts on Storage engines](https://swe.quest/tags/storage-engines.md?difficulty=easy))
- foreign keys and cascades
- VACUUM and autovacuum

## Keywords

PostgreSQL, DBOS, MVCC, VACUUM, autovacuum, ON DELETE CASCADE, pgmq

## Related posts

- [Postgres Bloat Minimization](https://swe.quest/articles/postgres-bloat-minimization-4680de201e2c3adb.md): Supabase · 2024-04-26 · Medium · 6 min read · PostgreSQL, Storage engines, Performance engineering
  Postgres 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.
- [I don't trust ON DELETE CASCADE](https://swe.quest/articles/i-don-t-trust-on-delete-cascade-44280f7ae72c78f6.md): PlanetScale · 2026-10-21 · Medium · 5 min read · PostgreSQL, Schema migrations, Replication, Databases
  Postgres ON DELETE CASCADE turns a single-row delete into an unbounded transaction that can cause outages at scale.
- [6 tips to optimize storage costs for your Postgres databases](https://swe.quest/articles/6-tips-to-optimize-storage-costs-for-your-postgres-databases-11da5e875c34786c.md): Neon · 2024-03-15 · Medium · 4 min read · PostgreSQL, Cost optimization, Storage engines
  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.
- [Postgres on NVMe: performance and the convergence of transactions and analytics](https://swe.quest/articles/postgres-on-nvme-performance-and-the-convergence-of-transactions-and-analytics-6553677f279f656e.md): ClickHouse · 2026-09-21 · Medium · 8 min read · PostgreSQL, Performance engineering, Storage systems, Replication, Analytics & OLAP
  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.
- [Leveraging Change Data Capture For Database Migrations At Scale](https://swe.quest/articles/leveraging-change-data-capture-for-database-migrations-at-scale-c10095cde295b15f.md): Squarespace Engineering · 2025-05-13 · Medium · 6 min read · Schema migrations, Event-driven architecture, PostgreSQL, Distributed databases, Stream processing
  Squarespace 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
