{
    "content": [
        {
            "type": "text",
            "text": "# TRUNCATE(7) (man)\n\n**Summary:** TRUNCATE - empty a table or set of tables\n\n**Synopsis:** TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]\n[ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]\n\n## Examples\n\n- `Truncate the tables bigtable and fattable:`\n- `TRUNCATE bigtable, fattable;`\n- `The same, and also reset any associated sequence generators:`\n- `TRUNCATE bigtable, fattable RESTART IDENTITY;`\n- `Truncate the table othertable, and cascade to any tables that reference othertable via`\n- `foreign-key constraints:`\n- `TRUNCATE othertable CASCADE;`\n\n## See Also\n\n- DELETE(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (3 lines)\n- **DESCRIPTION** (5 lines)\n- **PARAMETERS** (20 lines)\n- **NOTES** (41 lines)\n- **EXAMPLES** (13 lines)\n- **COMPATIBILITY** (6 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nTRUNCATE - empty a table or set of tables\n\n### SYNOPSIS\n\nTRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]\n[ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]\n\n### DESCRIPTION\n\nTRUNCATE quickly removes all rows from a set of tables. It has the same effect as an\nunqualified DELETE on each table, but since it does not actually scan the tables it is\nfaster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent\nVACUUM operation. This is most useful on large tables.\n\n### PARAMETERS\n\nname\nThe name (optionally schema-qualified) of a table to truncate. If ONLY is specified\nbefore the table name, only that table is truncated. If ONLY is not specified, the table\nand all its descendant tables (if any) are truncated. Optionally, * can be specified\nafter the table name to explicitly indicate that descendant tables are included.\n\nRESTART IDENTITY\nAutomatically restart sequences owned by columns of the truncated table(s).\n\nCONTINUE IDENTITY\nDo not change the values of sequences. This is the default.\n\nCASCADE\nAutomatically truncate all tables that have foreign-key references to any of the named\ntables, or to any tables added to the group due to CASCADE.\n\nRESTRICT\nRefuse to truncate if any of the tables have foreign-key references from tables that are\nnot listed in the command. This is the default.\n\n### NOTES\n\nYou must have the TRUNCATE privilege on a table to truncate it.\n\nTRUNCATE acquires an ACCESS EXCLUSIVE lock on each table it operates on, which blocks all\nother concurrent operations on the table. When RESTART IDENTITY is specified, any sequences\nthat are to be restarted are likewise locked exclusively. If concurrent access to a table is\nrequired, then the DELETE command should be used instead.\n\nTRUNCATE cannot be used on a table that has foreign-key references from other tables, unless\nall such tables are also truncated in the same command. Checking validity in such cases would\nrequire table scans, and the whole point is not to do one. The CASCADE option can be used to\nautomatically include all dependent tables — but be very careful when using this option, or\nelse you might lose data you did not intend to! Note in particular that when the table to be\ntruncated is a partition, siblings partitions are left untouched, but cascading occurs to all\nreferencing tables and all their partitions with no distinction.\n\nTRUNCATE will not fire any ON DELETE triggers that might exist for the tables. But it will\nfire ON TRUNCATE triggers. If ON TRUNCATE triggers are defined for any of the tables, then\nall BEFORE TRUNCATE triggers are fired before any truncation happens, and all AFTER TRUNCATE\ntriggers are fired after the last truncation is performed and any sequences are reset. The\ntriggers will fire in the order that the tables are to be processed (first those listed in\nthe command, and then any that were added due to cascading).\n\nTRUNCATE is not MVCC-safe. After truncation, the table will appear empty to concurrent\ntransactions, if they are using a snapshot taken before the truncation occurred. See\nSection 13.5 for more details.\n\nTRUNCATE is transaction-safe with respect to the data in the tables: the truncation will be\nsafely rolled back if the surrounding transaction does not commit.\n\nWhen RESTART IDENTITY is specified, the implied ALTER SEQUENCE RESTART operations are also\ndone transactionally; that is, they will be rolled back if the surrounding transaction does\nnot commit. Be aware that if any additional sequence operations are done on the restarted\nsequences before the transaction rolls back, the effects of these operations on the sequences\nwill be rolled back, but not their effects on currval(); that is, after the transaction\ncurrval() will continue to reflect the last sequence value obtained inside the failed\ntransaction, even though the sequence itself may no longer be consistent with that. This is\nsimilar to the usual behavior of currval() after a failed transaction.\n\nTRUNCATE can be used for foreign tables if supported by the foreign data wrapper, for\ninstance, see postgresfdw.\n\n### EXAMPLES\n\nTruncate the tables bigtable and fattable:\n\nTRUNCATE bigtable, fattable;\n\nThe same, and also reset any associated sequence generators:\n\nTRUNCATE bigtable, fattable RESTART IDENTITY;\n\nTruncate the table othertable, and cascade to any tables that reference othertable via\nforeign-key constraints:\n\nTRUNCATE othertable CASCADE;\n\n### COMPATIBILITY\n\nThe SQL:2008 standard includes a TRUNCATE command with the syntax TRUNCATE TABLE tablename.\nThe clauses CONTINUE IDENTITY/RESTART IDENTITY also appear in that standard, but have\nslightly different though related meanings. Some of the concurrency behavior of this command\nis left implementation-defined by the standard, so the above notes should be considered and\ncompared with other implementations if necessary.\n\n### SEE ALSO\n\nDELETE(7)\n\n\n\nPostgreSQL 14.23                                2026                                     TRUNCATE(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "TRUNCATE",
        "section": "7",
        "mode": "man",
        "summary": "TRUNCATE - empty a table or set of tables",
        "synopsis": "TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]\n[ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]",
        "flags": [],
        "examples": [
            "Truncate the tables bigtable and fattable:",
            "TRUNCATE bigtable, fattable;",
            "The same, and also reset any associated sequence generators:",
            "TRUNCATE bigtable, fattable RESTART IDENTITY;",
            "Truncate the table othertable, and cascade to any tables that reference othertable via",
            "foreign-key constraints:",
            "TRUNCATE othertable CASCADE;"
        ],
        "see_also": [
            {
                "name": "DELETE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DELETE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 41,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}