Partitioning Best Practices
Plan partition count; avoid daily partitions forever. Partition for prune-friendly access patterns and operable retention, not because the table "feels big."
Search across all documentation pages
Plan partition count; avoid daily partitions forever. Partition for prune-friendly access patterns and operable retention, not because the table "feels big."
EXPLAIN proof of pruning in the table's runbook.occurred_at), tenant (tenant_id), or region - not arbitrary IDs.(tenant_id, occurred_at DESC) for tenant-time queries.timestamptz UTC. Pruning bounds must match stored representation.date_trunc wrapper in production SQL templates.EXPLAIN in CI for canonical queries. Assert expected child partition names appear.Append-only event or audit logs with time-bounded queries and 90-day retention - clear key, clear prune, clear detach.
Weekly when single-month partitions exceed comfortable size (roughly 50-100GB+) or retention is weekly. Otherwise monthly reduces catalog overhead.
PostgreSQL uses per-child physical indexes created via parent DDL. There is no separate "global" index across partitions without partition key.
events_2026_03 for March 2026 - sortable, grep-friendly in ops scripts.
No. Partitioning is single-node (or single primary). Multi-node write scale needs Citus, application sharding, or split databases.
pg_class child count, EXPLAIN planning time, autovacuum duration on parent, insert errors at month boundary.
Rarely. Hash spreads writes but time-range reports scan all partitions. Prefer range with time filter.
Transparent - pooling does not affect pruning. Ensure prepared statements still pass partition-friendly parameters.
Optional pattern: detach, dump to parquet, query via postgres_fdw or external engine for rare audits.
Small dimension tables, heavily updated rows scattered across time, or queries without partition key filters.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.
Reviewed by Chris St. John·Last updated Jul 19, 2026