# Postgres DELETE can scale after all, if you tune it right

Original title: How Postgres DELETE can actually scale

> Hacker News story 50108297 · language: en · submitted 2026-10-15
> Web version: https://zeli.app/story/50108297
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 30 · by [KraftyOne](<https://news.ycombinator.com/user?id=KraftyOne>) · 💬 34
[original](<https://www.dbos.dev/blog/scaling-deletions-in-postgres>) · [HN discussion](<https://news.ycombinator.com/item?id=50108297>)

## Summary

Postgres DELETE has a bad reputation, and for good reason: deleting every row is orders of magnitude slower than dropping a table, because MVCC stamps each row version instead of removing it outright. But the flexibility of DELETE matters when data is heterogeneous and retention varies. DBOS engineers explain how they tuned cache and index performance to run retention policies on a system handling tens of thousands of workflows and steps per second.

## Key quote

> The accusations aren't wrong: Postgres DELETE uses a lot of expensive machinery to ensure deletes are transactionally safe, so deleting every row in a table is indeed orders of magnitudes slower than just dropping the table.

## HN discussion (34 comments)

### [mike_hearn](<https://news.ycombinator.com/item?id=50150299>)

> MVCC doesn't have to work the way Postgres does it. In some other databases a write like a DELETE or UPDTE directly overwrites disk blocks in place. There are no row copies or vacuums. To provide MVCC the database generates "undo logs" which are what they sound like - if you need to read the database at an earlier snapshot it reads the data off disk then use the undo data to revert the writes that happened after your MVCC snapshot. Undo data is periodically dropped when no live transaction needs it anymore.
>
> There are patches to change Postgres to this kind of model, as it has many advantages - all the outages and problems caused by autovacuuming falling behind go away - but the patches were never merged.
>
> Oracle has a couple of related features:
>
> \- undo data can be retained and used for time travel queries (SELECT .. AS OF).
>
> \- DML can be parallelized and write masters scale horizontally, so a large DELETE can run on multiple machines simultaneously. You do need to opt in manually though:
>
> ALTER SESSION ENABLE PARALLEL DML;
>
> DELETE /*+ PARALLEL(t, 8) */
>
> FROM   t
>
> WHERE  created_at < :cutoff;
>
> COMMIT;
>
> https://docs.oracle.com/en/database/oracle/oracle-database/2...
>
> That said the issues discussed in the blog post aren't directly to do with how fast the DELETE itself is processed but what it does to the database's performance afterwards.
>
> Disclosure: I have a part time role in the Oracle DB group.

### [bob1029](<https://news.ycombinator.com/item?id=50149379>)

> \> A partition can’t be deleted until every single piece of data it stores is no longer needed. This is appropriate for some systems, like message queues, where data is needed for a predictable amount of time. However, it’s not appropriate for a workflow system that supports long-running workflows.
>
> If most workflows complete within a few days, we could explicitly copy the long running items forward and then reclaim the entire partition. Sacrificing an extremely good technical solution because we can't be bothered to normalize <1% of use cases seems quite hasty, especially when we consider where this rejection of technological simplicity often takes us.

### [sgarland](<https://news.ycombinator.com/item?id=50152469>)

> \> Because a workflow typically performs many steps over a long period of time, those step records are widely separated on disk
>
> Clustered indices would be so, so nice for Postgres to have. OrioleDB can’t come quickly enough.
>
> \> However, this stamp is applied only to the row itself, not to any indexes referencing the row.
>
> Indices also hold the hint bit LP_DEAD, which is set by any  query that follows the index to the heap and finds that it’s invisible to everyone.
>
> I suspect that a combined query that uses pagination rather than LIMIT … OFFSET would be more performant here, and could skip the dead tuple problem.
>
> DELETE FROM step_outputs
>
> WHERE ctid = ANY(ARRAY(
>
> SELECT s.ctid
>
> FROM step_outputs s
>
> WHERE (s.created_at, s.id) > (?, ?)
>
> AND s.created_at < ?
>
> AND NOT EXISTS (
>
> SELECT 1 FROM workflow_status w
>
> WHERE w.workflow_uuid = s.workflow_uuid
>
> )
>
> ORDER BY s.created_at, s.id
>
> LIMIT ?
>
> ))
>
> RETURNING created_at, id;
>
> Haven’t tested that, but something of that shape. You’d need a composite index on (created_at, id) as well.

### [menthe](<https://news.ycombinator.com/item?id=50150417>)

> First of all, what are you optimizing for? Expiry latency shouldn't matter, only keeping pace with insert throughput. And while I appreciate that you sidestepped the immediate issue through the solutions presented in the article, dropping the foreign key and adding an anti-join doesn't feel like a long-term solution, since you trade referential integrity for orphan risk.
>
> There's a point in PostgreSQL scalability where the need to vacuum (following updates/deletes) becomes a problem in itself, and that point is a lot closer than most anticipate. For instance, vacuum can’t be unable to reclaim versions unexpectedly (e.g stuck transaction holding the TID horizon), leaving you with millions of dead tuples & massive stale index linked-lists, which can lead to major service degradations.
>
> An alternative could be to tombstone rows with a HOT UPDATE on a `deleted_at` column. If that update is HOT (heap-only), the new row version lives on the same page and no new index entries are created. The old version does become a dead tuple, but it's pruned in-page and ad-hoc by ordinary reads and writes, so VACUUM is never needed to reclaim them, and dead tuples never accumulate, least of all in the indexes. On PG16+ this even works with a BRIN index on `deleted_at`, given some fillfactor headroom.
>
> That also addresses the 20-minute scan, which seems to  have been caused by walking millions of dead index entries at the oldest end of created_at, each needing a heap visit to confirm it was dead. Wi […]

---

## Cite

- Page: https://zeli.app/story/50108297
- Date: 2026-10-15
- Source: dbos.dev (https://www.dbos.dev/blog/scaling-deletions-in-postgres)
- Hacker News: https://news.ycombinator.com/item?id=50108297

## Other languages

- zh: https://zeli.app/zh/story/50108297 · markdown: https://zeli.app/zh/story/50108297.md
- ja: https://zeli.app/ja/story/50108297 · markdown: https://zeli.app/ja/story/50108297.md
- ko: https://zeli.app/ko/story/50108297 · markdown: https://zeli.app/ko/story/50108297.md
- de: https://zeli.app/de/story/50108297 · markdown: https://zeli.app/de/story/50108297.md
- es: https://zeli.app/es/story/50108297 · markdown: https://zeli.app/es/story/50108297.md
- ru: https://zeli.app/ru/story/50108297 · markdown: https://zeli.app/ru/story/50108297.md
