What is pg_partman and how does it simplify partition management?

Answer

pg_partman is a PostgreSQL extension that automates the creation and maintenance of time-based and serial-based partitioned tables. Without pg_partman, you must manually create new partitions before data arrives — miss this and data goes to the default partition or errors. With pg_partman: (1) Create the parent table with declarative partitioning. (2) Set up the partition set: SELECT partman.create_parent('public.orders', 'created_at', 'native', 'monthly');. (3) pg_partman automatically creates pre-built future partitions and maintains a retention policy. (4) Schedule maintenance: SELECT partman.run_maintenance(); — typically via pg_cron. It handles: creating new partitions in advance (premake setting), dropping old partitions based on retention, and moving data from the default partition. Essential for production time-series tables.