Destructive Operations
TRUNCATE ... CASCADE
Lock mode ACCESS EXCLUSIVE
Risk CRITICAL
Blocks reads, writes, other DDL
pgfence rule
truncate-cascade TRUNCATE orders CASCADE; What this does
Deletes all rows in the named table AND every table that references it via a foreign key, taking ACCESS EXCLUSIVE on all of them. The blast radius is easy to underestimate from reading the statement alone.
Safe rewrite
Remove CASCADE and explicitly truncate or batch-delete each table
-- Delete in batches out-of-band, table by table:
-- DELETE FROM orders WHERE ctid IN (SELECT ctid FROM orders LIMIT 1000);