Attaching and Detaching Partitions
Learn to efficiently move data in and out of partitioned tables using ATTACH PARTITION and DETACH PARTITION.
Move Data Efficiently
Partitioned tables in PostgreSQL are powerful for managing large datasets. But how do you handle data that needs to be added or removed from these partitions?
This lesson introduces ATTACH PARTITION and DETACH PARTITION, two critical commands that allow you to efficiently move data in and out of your partitioned tables with minimal disruption.
The DETACH PARTITION Command
DETACH PARTITION is used to separate an existing partition from its parent partitioned table. When a partition is detached, it becomes a standalone, regular table.
- Syntax:
ALTER TABLE parent_table DETACH PARTITION child_table; - Why use it? For archiving old data, performing maintenance on a specific partition, or moving data to a different storage tier.
The main partitioned table remains available for queries during this operation.
All lessons in this course
- Query Optimization with Partitioning
- Attaching and Detaching Partitions
- Partition Pruning and Exclusion
- Partition-wise Joins and Aggregates