Introduction
As databases grow, tables containing millions of rows can become increasingly difficult to manage. Queries may take longer to execute, indexes become larger, maintenance operations require more time, and backup or archival tasks become more complex.
Table partitioning is a PostgreSQL feature that divides a large table into smaller, more manageable pieces called partitions. Although applications continue to interact with a single logical table, PostgreSQL automatically routes data to the appropriate partition based on the partitioning strategy.
In this article, you'll learn what PostgreSQL table partitioning is, the different partitioning methods, how to create partitioned tables, and best practices for improving database performance and maintainability.
What Is Table Partitioning?
Table partitioning is the process of splitting a large table into multiple physical tables while presenting them as a single logical table.
Each partition stores a subset of the data based on predefined rules.
Benefits include:
Faster query execution
Improved maintenance
Smaller indexes
Easier data archiving
Better scalability
Simplified data management
Applications continue to query the parent table without needing to know where the data is stored.
Why Use Table Partitioning?
As data volume increases, operations on a single large table become less efficient.
Partitioning helps by:
Reducing the amount of data scanned by queries
Improving index efficiency
Speeding up maintenance tasks
Simplifying historical data management
Supporting high-volume workloads
It is particularly useful for time-series and transactional data.
Partitioning Methods
PostgreSQL supports three primary partitioning strategies.
Range Partitioning
Rows are divided based on a range of values.
Examples include:
Order dates
Invoice dates
Years
Months
This is the most common partitioning method.
List Partitioning
Rows are divided according to predefined values.
Examples include:
Countries
Regions
Departments
Categories
Each partition contains specific values.
Hash Partitioning
Rows are distributed using a hash function.
Hash partitioning helps balance data evenly across partitions when no natural range or list exists.
Create a Partitioned Table
The following example creates a table partitioned by order date.
CREATE TABLE Orders
(
OrderId INT,
OrderDate DATE,
CustomerName TEXT,
Amount NUMERIC
)
PARTITION BY RANGE (OrderDate);
The parent table defines the schema but does not store data directly.
Create Range Partitions
Create partitions for different years.
CREATE TABLE Orders2025
PARTITION OF Orders
FOR VALUES FROM ('2025-01-01')
TO ('2026-01-01');
CREATE TABLE Orders2026
PARTITION OF Orders
FOR VALUES FROM ('2026-01-01')
TO ('2027-01-01');
Each partition stores data within its configured date range.
Insert Data
Insert records into the parent table.
INSERT INTO Orders
VALUES
(
1,
'2026-03-15',
'John Smith',
850.00
);
PostgreSQL automatically routes the row to the correct partition.
No application changes are required.
Query the Parent Table
Applications query the parent table as usual.
SELECT *
FROM Orders
WHERE OrderDate >= '2026-01-01';
PostgreSQL scans only the relevant partitions whenever possible.
This optimization is known as partition pruning.
Understanding Partition Pruning
Partition pruning allows PostgreSQL to ignore partitions that cannot contain matching rows.
For example, a query for 2026 orders skips the 2025 partition entirely.
Benefits include:
Faster queries
Reduced disk reads
Better index utilization
Lower CPU usage
Partition pruning is one of the primary performance advantages of partitioning.
Create List Partitions
List partitioning is useful for categorical data.

Join the conversation! Your thoughts help the community grow.