Cookbook recipe

Partition a growing table with declarative partitioning

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

A single table is too big to vacuum, index, or prune efficiently. Range partitioning by time makes maintenance and queries fast. Diagnose it Create a partitioned parent and a monthly child: CREATE TABLE events (id bigint,…

Investigation Path

A single table is too big to vacuum, index, or prune efficiently. Range partitioning by time makes maintenance and queries fast.

Diagnose it

Create a partitioned parent and a monthly child:

CREATE TABLE events (id bigint, ts timestamptz, ...)
  PARTITION BY RANGE (ts);
CREATE TABLE events_2026_05 PARTITION OF events
  FOR VALUES FROM ('2026-05-01') TO ('2026-06-01');

Why it happens

Declarative partitioning splits one logical table into physical children by key range/list/hash. The planner prunes irrelevant partitions, and you can drop old data instantly by detaching a partition.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes