In PolarDB for PostgreSQL (Compatible with Oracle), TRUNCATE PARTITION removes all rows from a partition or subpartition without dropping the partition structure. Use it when you need to clear partition data quickly and reclaim disk space immediately — faster than DELETE for large data sets.
Syntax
ALTER TABLE <table_name> TRUNCATE PARTITION <partition_name>;
ALTER TABLE <table_name> TRUNCATE SUBPARTITION <subpartition_name>;How TRUNCATE differs from DELETE
Both TRUNCATE and DELETE remove all rows from the target partition, but TRUNCATE is typically faster and has different space-reclamation behavior:
| Aspect | TRUNCATE | DELETE |
|---|---|---|
| Performance | Deallocates data pages directly — no row-by-row scanning | Scans and removes rows one at a time |
| Disk space | Reclaimed immediately, no VACUUM needed | May require a VACUUM to reclaim space |
Example
The following example creates a hash-partitioned table and truncates partition p1.
Create the table:
CREATE TABLE hash_partitions_sales (deptno NUMBER, deptname VARCHAR(32))
PARTITION BY HASH(deptno)
(PARTITION p1, PARTITION p2,
PARTITION p3, PARTITION p4, PARTITION p5);Truncate the partition:
ALTER TABLE hash_partitions_sales TRUNCATE PARTITION p1;