📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Partitioning

Partitioning

7 min read
Partitioning splits a large table into smaller physical pieces. Range partitioning by date creates one partition per month. PostgreSQL only scans relevant partitions, making queries much faster on large time-series tables.

Table Partitioning

CREATE TABLE orders (
  id   BIGSERIAL,
  date DATE NOT NULL,
  total NUMERIC
) PARTITION BY RANGE (date);

CREATE TABLE orders_2023
  PARTITION OF orders
  FOR VALUES FROM ('2023-01-01') TO ('2024-01-01');

CREATE TABLE orders_2024
  PARTITION OF orders
  FOR VALUES FROM ('2024-01-01') TO ('2025-01-01');

Partitioning splits large tables into smaller physical pieces for faster queries.