pg_partman — Partition Management
Native PostgreSQL partition automation. MonPG monitors partition lag.
pg_partman automates partition creation and retention for native PostgreSQL partitioned tables. MonPG reads partman.part_config and per-table partition counts to surface:
- Partition count per parent table.
- Pre-creation lag — partman defaults to creating 4 partitions ahead, and we alert if it falls below 1 ahead. Less than 1 ahead means inserts are about to fail.
- Retention drop lag — partitions past their retention that haven't been dropped yet. Usually means the bgw is stopped.
- Background worker (
pg_partman_bgw) status if it's running.
Enabling
Plain CREATE EXTENSION for the extension itself — pure DDL, no SPL needed. The pg_partman_bgw background worker requires SPL + restart, but it's optional. You can also call partman.run_maintenance() from external cron, pg_cron, or whatever scheduler you already have.
- RDS: PG 15+.
CREATE EXTENSION pg_partman;. - Azure Flex / Cloud SQL / Crunchy / Aiven: shipped, plain
CREATE EXTENSION. - Heroku: Standard+ only (Essential lacks it).
- Self-hosted: install
pg_partmanpackage +CREATE EXTENSION.
Bgw or cron
If your provider supports SPL changes, the bgw is simpler — auto-runs every pg_partman_bgw.interval seconds, no extra moving parts. If it doesn't, schedule with pg_cron or the equivalent:
SELECT cron.schedule('partman-maintenance', '*/30 * * * *',
$$SELECT partman.run_maintenance()$$);
Either way produces the same result. The bgw is more convenient when it works; the cron approach is more portable.