PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Declarative Table Partitioning: Range, List, and Hash.
senior LevelCode ExamplepostgresqlAdvanced Internals
In Simple Words: Partitioning splits a massive table into smaller physical child tables while maintaining a single logical table interface:
- Range Partitioning: Partition by continuous intervals (e.g.
order_dateby month or year). - List Partitioning: Partition by discrete categorical values (e.g.
country_code IN ('US', 'CA')). - Hash Partitioning: Partition by
MODULUShash keys to balance write traffic across disks. - Partition Pruning: The query planner automatically skips child partitions that do not match the
WHEREclause conditions!
sql
-- Creating a range-partitioned table by month
CREATE TABLE telemetry_events (
id BIGSERIAL,
event_time TIMESTAMPTZ NOT NULL,
payload JSONB
) PARTITION BY RANGE (event_time);
CREATE TABLE telemetry_2026_11 PARTITION OF telemetry_events
FOR VALUES FROM ('2026-11-01') TO ('2026-12-01');