All Products
Search
Document Center

PolarDB:Truncate a partition

Last Updated:Mar 28, 2026

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:

AspectTRUNCATEDELETE
PerformanceDeallocates data pages directly — no row-by-row scanningScans and removes rows one at a time
Disk spaceReclaimed immediately, no VACUUM neededMay 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;