TRUNCATE (Truncate Table)
Last updated: 2026-11-04
TRUNCATE (Truncate Table)
TRUNCATE empties a table in one shot, much faster than row-by-row DELETE. It rewrites the table's data file and reclaims all the space at once, so it leaves no dead tuples behind for VACUUM to clean up. It can also truncate tables referenced by foreign keys, or reset the identity sequence with RESTART IDENTITY.
| Kind | command |
|---|---|
| Example Language | SQL |
📝 Syntax
TRUNCATE [TABLE] [ONLY] <table> [, ...]
[RESTART IDENTITY | CONTINUE IDENTITY]
[CASCADE | RESTRICT]
⚙️ Parameters
| RESTART IDENTITY | Resets the associated identity/serial sequence |
|---|---|
| CONTINUE IDENTITY | Keeps the sequence going (the default) |
| CASCADE | Also truncates tables referencing this one |
| RESTRICT | Refuses when a foreign key references the table (the default) |
Returns:No return value. After the statement succeeds the table is empty.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
DROP TABLE
CREATE TABLE
INSERT 0 3
TRUNCATE TABLE
rows_left
---------
0
📌 Key Points
- TRUNCATE fires no row-level DELETE triggers (only a statement-level TRUNCATE trigger), whereas DELETE fires one per row.
- TRUNCATE rewrites the table file (its relfilenode changes); measured on a million rows it is two orders of magnitude faster than DELETE.
- A table referenced by a foreign key cannot be truncated by default — you get cannot truncate a table referenced in a foreign key constraint unless you add CASCADE.
- RESTART IDENTITY resets the IDENTITY/serial sequence to its start value; without it the sequence keeps counting up.
- TRUNCATE is transactional — a rollback brings the rows back.
- TRUNCATE only removes data: sequences, indexes, constraints, and triggers all survive.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhat exactly separates TRUNCATE from DELETE?
ATRUNCATE is faster (it rewrites the file instead of marking rows), fires no row-level DELETE triggers, returns space immediately, and can reset sequences. DELETE runs row by row, fires triggers, and leaves dead tuples for VACUUM.
QDoes the identity counter restart after TRUNCATE?
ANot by default — the sequence keeps counting up. Add RESTART IDENTITY to reset it to the start value.