TRUNCATE TABLE instantly removes all rows from one or more PostgreSQL tables, optionally resetting sequences and cascading to related tables.
TRUNCATE TABLE deletes every row in a table in a single, metadata-level operation. Unlike DELETE, it bypasses row-by-row logging, giving near-instant execution even on millions of records.
Use TRUNCATE TABLE when you need a fresh table state and do not require per-row triggers, foreign-key checks, or VACUUM reclamation. It is ideal for nightly ETL staging tables.
Place the TRUNCATE keyword before one or more table names. Add RESTART IDENTITY to reset SERIAL/BIGSERIAL sequences, or CONTINUE IDENTITY to keep them.
Yes. List several tables separated by commas, or use CASCADE to automatically truncate tables that reference them through foreign keys.
Append RESTART IDENTITY so sequences behind SERIAL or IDENTITY columns restart from their start value. Useful for dev and test datasets.
Use CASCADE only when you are certain that child rows can be lost. For example, truncating Orders might need CASCADE to clear OrderItems.
Wrap TRUNCATE in a transaction so it can be rolled back. Grant the command sparingly; it requires table owner or superuser privileges.
Avoid truncating tables with critical audit data. Remember that triggers do not fire, so downstream logic will not execute.
No. TRUNCATE bypasses all row-level triggers. If you need trigger logic, use DELETE instead.
Yes, as long as it occurs inside an open transaction that has not yet been committed.
Minimal logging occurs to support replication and crash recovery, but far less than a DELETE of every row.