---
title: "I don't trust ON DELETE CASCADE"
description: "Postgres ON DELETE CASCADE turns a single-row delete into an unbounded transaction that can cause outages at scale."
url: "https://swe.quest/articles/i-don-t-trust-on-delete-cascade-44280f7ae72c78f6"
canonical: "https://planetscale.com/blog/i-dont-like-delete-cascade"
source: "PlanetScale"
published: "2026-10-21"
difficulty: "medium"
kind: "Opinion"
reading_minutes: 5
tags: ["postgres","schema-migrations","replication","databases"]
---

# I don't trust ON DELETE CASCADE

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-10-21, 5 min read, Opinion. Original: [https://planetscale.com/blog/i-dont-like-delete-cascade](https://planetscale.com/blog/i-dont-like-delete-cascade)

## Summary

Postgres 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.

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)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- Postgres foreign keys ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Postgres table locks ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- logical replication basics ([easy posts on Replication](https://swe.quest/tags/replication.md?difficulty=easy))

## Keywords

PostgreSQL, ON DELETE CASCADE, AccessExclusiveLock, logical replication, WAL, soft deletes, PlanetScale

## Related posts

- [Postgres DELETE Can Actualy Scale](https://swe.quest/articles/postgres-delete-can-actualy-scale-9f7f79b6782a5f75.md): DBOS · 2026-09-17 · Medium · 7 min read · PostgreSQL, Storage engines, Performance engineering, Databases
  Postgres DELETE can scale for data retention if you design around MVCC churn, cache locality and dead tuples.
- [Navigating PostgreSQL Locks with Neon and Atlas](https://swe.quest/articles/navigating-postgresql-locks-with-neon-and-atlas-61f1baeebb69a86a.md): Neon · 2025-03-14 · Medium · 11 min read · Schema migrations, PostgreSQL, CI/CD, Static analysis
  Adding a UNIQUE constraint or setting a column NOT NULL in Postgres triggers a full table scan under an ACCESS EXCLUSIVE lock, which blocks all reads and writes and can take down an API on large tables.
- [Post mortem on Linear incident from Jan 24th, 2024](https://swe.quest/articles/post-mortem-on-linear-incident-from-jan-24th-2024-c1bcc35cc14b559c.md): Linear · 2024-01-30 · Medium · 9 min read · Incidents & postmortems, PostgreSQL, Schema migrations, Local-first & sync
  A database migration using \`TRUNCATE TABLE ... CASCADE\` on two new, unused tables silently wiped every production table with foreign keys to them, including issue and document descriptions, comments, notifications and reactions.
- [How we migrate TBs from Heroku without logical replication](https://swe.quest/articles/how-we-migrate-tbs-from-heroku-without-logical-replication-e0568c616a878849.md): PlanetScale · 2026-11-11 · Medium · 12 min read · PostgreSQL, Schema migrations, Replication, Networking
  PlanetScale's open-source Heroku Migrator moves multi-terabyte Postgres databases off Heroku standard plans, which lack WAL access and logical replication, by using Bucardo trigger-based replication: triggers record changes in delta tables, a one-time COPY loads existing data, and a worker replays the backlog before a controlled switchover with verification.
- [What's new in Postgres 15?](https://swe.quest/articles/what-s-new-in-postgres-15-a6b4172551a1b66b.md): Supabase · 2022-12-16 · Easy · 3 min read · PostgreSQL, Replication, SQL
  PostgreSQL 15 tightens the default permission model by revoking CREATE on the public schema from non-owners and adds security\_invoker views that check the caller's permissions.

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)
