I don't trust ON DELETE CASCADE
Oct 21, 2026Tom Pang

Summary
This post details the failure modes of `ON DELETE CASCADE` in PostgreSQL, particularly when combined with schema migrations or logical replication. It explains how `RowExclusiveLock` during cascading deletes can block `AccessExclusiveLock` requests for schema changes, leading to outages. It also covers issues with unindexed foreign keys, orphaned rows in logical replication subscribers, and the failure of publications when replica identity is missing. The post strongly advocates for soft deletes as a more scalable alternative, allowing for controlled, batched real deletes and shorter, bounded transactions.