Destructive Operations

TRUNCATE

Lock mode ACCESS EXCLUSIVE
Risk CRITICAL
Blocks reads, writes, other DDL
pgfence rule truncate
TRUNCATE orders;

What this does

Deletes every row in the table under ACCESS EXCLUSIVE. It is transactionally rollbackable before commit; after commit, recovery requires a retained copy such as a backup or replica.

Safe rewrite

Use batched DELETE instead of TRUNCATE for safer, resumable data removal

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

Read more

More in Destructive Operations