Destructive Operations

DELETE without WHERE

Lock mode ROW EXCLUSIVE
Risk HIGH
Blocks other DDL
pgfence rule delete-without-where
DELETE FROM orders;

What this does

The lock itself is unremarkable (ROW EXCLUSIVE is what any ordinary write takes), but a DELETE with no WHERE clause, or one whose WHERE clause is provably always true, removes every row in the table. pgfence also catches tautological predicates like WHERE 1=1 or WHERE true, not just a bare missing WHERE.

Safe rewrite

Add a WHERE clause, or delete in batches if the intent really is to clear the table

-- Delete in batches out-of-band:
-- DELETE FROM orders WHERE ctid IN (SELECT ctid FROM orders LIMIT 1000);

Read more

More in Destructive Operations