pg_partman for automated partition management

pg_partman automates creating and retiring time-based and number-based partitions on top of PostgreSQL's declarative partitioning. This page covers the configuration decisions, rollout, effort drivers and pg_partman 5 upgrade steps for teams running it in infrastructure they control.

On this page

How pg_partman automates partitions on self-hosted PostgreSQL

pg_partman builds on PostgreSQL's native declarative partitioning to create new partitions ahead of time and drop or detach old ones according to retention rules, so the database stops depending on someone running hand-written DDL on a schedule. Teams usually reach for it when a large table grows by time (daily events, monthly transactions) or by a sequence of IDs, and the partitions must appear before data arrives and disappear when policy says the data has aged out. Doing this by hand works for a while, but missed rotations and forgotten retention jobs tend to show up first as inserts failing for lack of a partition or as disks filling with stale data.

pg_partman does not replace the decisions that come before it. The partition key, the partition interval and the indexes on each child table still have to match how the data is queried, and a poor key choice will not be fixed by automation. Backups remain your responsibility too: dropping a partition under a retention rule is permanent unless you have a recoverable copy, so retention settings should be reviewed alongside your backup and recovery design. Confirm with the pg_partman documentation for your installed version which settings control pre-creation and retention, and whether retention drops or only detaches child tables.

The effort depends mostly on two inputs: the partition key and the retention rules the data needs. Ask who owns the retention policy, whether regulated records must be kept for a fixed period, and whether archived partitions should be moved elsewhere before removal. Then test the background worker against a copy of production volumes and confirm it runs under the database role you intend to use. Upgrade notes for pg_partman 5 are worth reading before you start, since the project's pg_partman repository documents special steps for moving from earlier versions to 5.x.

What pg_partman does on top of declarative partitioning

pg_partman does not replace PostgreSQL's declarative partitioning. It adds an management layer that creates, retains and maintains the child tables that the native feature expects you to manage yourself. The cards below describe the capabilities to plan around, and each one should be checked against the project documentation for the pg_partman version you deploy.

Time-based partition sets

pg_partman manages partition sets keyed on a timestamp or date column, creating one child table per interval such as a day or a month. For an operator, this means the partition key, interval and template design are decided at setup and then applied consistently to every child. Confirm which interval values and column types the version in use supports for your data, and test the setup against a copy of production data before it goes live.

pg_partman repository

Number-based partition sets

For integer keys such as sequence IDs, pg_partman creates child tables covering fixed ranges of values. Operators should plan the range size against expected row growth and the sequence's behavior, because ranges that are too small create many tables and ranges that are too large defeat pruning. Confirm the supported key types and range handling in the documentation for your version before choosing this mode for a table.

Pre-created future partitions

pg_partman can create child partitions ahead of the data that will land in them, so inserts do not fail or fall into a default partition when a new period starts. The operator sets how far ahead partitions are created. Check the lead time against your ingest pattern and monitor for inserts that land in a default or catch-all partition, since that usually signals that maintenance has fallen behind.

Retention for old partitions

pg_partman can drop or detach partitions that fall outside a configured retention window. Retention is a destructive operation, so operators should decide whether old partitions are dropped or kept detached for archiving, and confirm that backups cover the data before the window closes. Review the retention settings for the version in use and rehearse them on a non-production database first.

Background worker maintenance

A background worker can run partition maintenance inside the database, so most deployments do not need an external scheduler to create and retire partitions. Confirm the worker is enabled and running after each restart or upgrade, because a silent stop leaves partitions unmanaged. Confirm also which cases still need an external scheduler in the version you run.

Which partition key, interval and retention settings fit your data

This table compares the core pg_partman configuration choices, from partition type and key column to retention and scheduling. Read each row against your data's growth pattern and query shape, then confirm the named settings in the project's configuration reference before you deploy.

DecisionWhen it fitsOperational costConfirm before deployment
Time-based partitioningAppend-heavy event, log or audit tables where rows are queried by date range and old data ages out on a schedulePartition count grows with time, so interval choice drives how many child tables the planner and catalog must handleSupported interval values and how the partition name suffix is formed for your chosen interval
Number-based partitioningTables keyed by a sequence or ID where data arrives in ranges of values rather than by timeRetention must be defined by ID range, so operators need to track which IDs fall into which partitionsHow serial or identity keys are mapped to partition boundaries and whether the key type is supported
Partition key column and data typeA timestamp or integer column that is present on every row, never null, and used in most WHERE clausesChanging the key later usually means rebuilding the parent table, so a poor choice is costly to reverseWhether the column type is accepted for time-based or number-based setup and how timezone handling applies
Interval size (daily, monthly or other)Daily intervals suit high-volume tables; monthly intervals suit lower volume with long retentionSmaller intervals create more child tables and more maintenance work; larger intervals hold more rows per partitionFull list of supported interval values and how each one affects partition naming and boundaries
Pre-created future partitionsAny table where inserts must succeed before the next maintenance run, including bursty loadsEach pre-created partition holds catalog entries and reserves naming space that must later be managedThe setting that controls how many future partitions are created and how maintenance replenishes them
Retention: detachWhen data must leave the active table but remain available for archive, export or legal holdDetached tables still need storage and a plan for who reads them and when they are droppedHow detached partitions are named and whether pg_partman leaves them in place after detaching
Retention: keepWhen data must stay queryable in the parent table for long periods and storage is not a constraintTable size and vacuum time grow over time, and query planning depends on partition pruning being effectiveWhether old partitions remain attached indefinitely and how that setting interacts with maintenance runs
Retention: dropWhen policy sets a fixed deletion window and no copy is needed after it passesDropping is irreversible, so backups must cover any data required by policy before partitions are removedHow the drop setting is applied, and whether a backup or export step is required first
Background worker or external schedulerThe background worker suits most installs that want maintenance without a separate job system; an external scheduler suits teams that already run central job toolingThe worker adds a process to manage and its settings must be tuned per database; an external scheduler adds a dependency that must be monitoredHow the background worker is enabled, which databases it runs in, and the exact call to run maintenance from a scheduler

How the background worker and partition maintenance fit together

The diagram starts with application inserts into the partitioned parent table, which PostgreSQL routes to child partitions. pg_partman's background worker, or an external scheduler you choose, runs maintenance that creates future child partitions and then applies retention, either detaching or dropping old ones. Check that backups and monitoring see the partition set after each maintenance run, and confirm which scheduling path your team will operate before you rely on it.

Inserts flow into child partitions, while maintenance creates and retires them.

How a pg_partman rollout runs from test to production

This sequence takes a partitioned PostgreSQL table from its current layout to pg_partman-managed creation and retention, with a test record, a tested retention runbook and a rollback path before production changes are made.

  1. Confirm the PostgreSQL version and partition layout

    Confirm the PostgreSQL major version in use and check that it is still within its support window, since pg_partman has to be tested against the version you will run in production. Inventory the partitioned and candidate tables, their partition keys (time or integer), existing partition names, default partitions, indexes, and foreign keys that reference them. Record which tables are native declarative partitions and which still use legacy inheritance, because the migration path differs. The output is a written inventory that lists each table, its key, its current partition count and the owners who will approve retention periods. Confirm the exact pg_partman version and its 5.x upgrade notes before installation, because upgrading from earlier versions may need special steps.

  2. Install pg_partman in a test cluster

    Build a test cluster that matches production in PostgreSQL major version, extensions, configuration and authentication settings. Install the pg_partman build that matches that PostgreSQL major version, then create the extension in a dedicated schema that the operations team controls. Grant the minimum privileges needed for partition management, and record which role owns the managed tables. The output is a reproducible install record: package source, pg_partman version, PostgreSQL version, the schema and the role model. If the test cluster cannot reproduce production settings such as the authentication method or TLS configuration, document the gaps so they are closed before cutover.

  3. Set partition and retention parameters

    Create the partition set with pg_partman, selecting the interval for time-based partitions or the batch size for number-based partitions, and set the number of future partitions to pre-create. Define the retention policy for each set, including whether expired partitions are dropped or detached and kept, and whether they are archived before removal. Set the default partition handling and confirm the partition naming pattern against your backup and reporting jobs. The output is a configuration record that lists every partition set, its key, interval, premake count, retention value and retention action, reviewed and signed by the data owner. Store this record under version control so later changes can be compared.

  4. Verify creation and retention on representative data

    Load the test cluster with data volumes and insert patterns that resemble production, including late-arriving rows and rows that fall into the default partition. Run partition creation and then confirm that future partitions exist for the premake window and that inserts route to the correct child tables. Apply the retention settings and check which partitions are dropped or detached, and that no rows needed by applications, reports or legal holds are removed. Repeat the run at least once after a simulated missed maintenance cycle to see how catch-up behaves. The output is test evidence: row counts before and after each run, partition listings, query plans showing partition pruning, and a log of any failed or skipped maintenance.

  5. Enable the background worker or scheduler

    Decide how maintenance will run. pg_partman includes a background worker that runs partition maintenance without an external scheduler in most cases, so confirm whether your deployment will use it or a scheduled job instead. If you use the worker, set the database and the interval in the server configuration, restart as required by your configuration, and confirm the worker appears in the server process list. If you use an external scheduler, record who owns the job, its frequency and its alerting. Test a manual maintenance call and a failure case, such as a disabled worker, so the team knows how the failure appears in logs and monitoring. The output is a maintenance runbook section that names the mechanism, the owner and the alert that fires when maintenance stops.

  6. Write the retention change runbook

    Write a runbook for changing retention, premake counts and intervals after production goes live. The runbook should describe how to review the impact on storage and backups, how to check the current partition listing, who approves the change, and how to test the change in the test cluster first. Include the steps for upgrading pg_partman itself, referring to the 5.x upgrade notes and the test record from earlier steps. The output is a signed runbook that operations and the data owners can use without the implementation team present.

  7. Cut over to production with a rollback path

    Schedule the production change in a window agreed with the business and the application owners. Before changing anything, take a verified backup and record the current partition layout and row counts for each affected table. Apply the extension, create the partition sets and set the first retention values in a conservative configuration, such as a retention action that detaches rather than drops, so that the first maintenance cycle is reversible. Confirm that inserts route correctly, that the worker or scheduler runs, and that monitoring reports the expected results. Document the rollback path: how to disable the worker, restore the previous configuration and reattach any detached partitions. The output is a cutover record with the before and after state, the verification results and the rollback steps tested in the test cluster. Timing and staffing for each stage depend on your environment and must be agreed in the written scope before work begins.

Migrating an existing table into pg_partman versus starting fresh

Most teams with a large, unpartitioned table are converting it in place while the application keeps writing. The conversion creates a new native partitioned table, moves rows into it, swaps names and then hands the parent to pg_partman so future partitions are created and retired automatically. The hard part is not the DDL but the data movement: copying existing rows into partitions takes time, generates WAL and competes with production traffic. Plan the cutover around a strategy you have tested on a copy of production data.

  • Data movement method: Decide between a batched copy that moves rows in key ranges, a logical replication based cutover, or a short outage for a bulk load. Each has different write-lock and rollback behavior.
  • Locking: Attaching a partition, adding constraints and creating indexes can take locks that block reads or writes. Confirm which statements need an exclusive lock on your PostgreSQL version and schedule them accordingly.
  • Index planning: Partitioned indexes must include the partition key. Decide which indexes to rebuild per partition, which to drop before the load and which to recreate afterward.
  • Application query changes: Queries without a predicate on the partition key scan every partition. Collect the top queries from logs and confirm they filter on the time or number key.
  • Team inputs: Provide a maintenance window, row counts and growth rate per table, a list of foreign keys and triggers referencing the table, and representative query samples.

Before you start, check the pg_partman 5.0.1 upgrade notes if any earlier version of pg_partman is already installed in the target database.

What drives pg_partman effort and how to keep it down

This table compares the factors that raise or lower the work of running pg_partman, with the one-time and recurring cost each one touches. Read each row as a question to answer before asking for a quote, since the same driver can be cheap on one table and expensive on another. The main takeaway is that the table count, existing partitioning state, and constraints on each table set most of the design effort, while retention rules and upgrades set the recurring load.

DriverHow it changes the workHow to keep it down
Number of partitioned tablesEach table needs its own partition key, interval, premake setting and retention rule, so design and testing grow with every table added.Group tables that share an interval and retention pattern, and use one standard configuration template reviewed once.
Size and write rate of each tableLarge or fast-growing tables need partitions created ahead of demand, and a missed premake can route inserts into the default partition.Size the interval to the expected daily volume and monitor the default partition for rows that should have gone elsewhere.
Already partitioned nativelyTables on native declarative partitioning need only pg_partman configuration, while tables still on inheritance or unpartitioned need a migration plan first.Confirm the partitioning state of every table in the inventory before scoping, and budget migration work separately.
Number of retention rulesEach retention rule decides whether data is dropped or kept, and rules that differ by table or by compliance need sign-off and testing.Write retention periods into one reviewed register and test drop behavior on a copy before production.
Foreign keys and unique indexesPartitioned tables must include the partition key in unique constraints, and foreign keys that reference or come from partitioned tables can block changes or require redesign.Check constraints during design, and avoid adding new foreign keys to high-volume partitioned tables without a tested plan.
Scheduling modelThe background worker handles most maintenance in many setups, but teams with an external scheduler or strict run windows need extra configuration and monitoring of job runs.Pick one scheduling model early and document who watches job failures and how alerts reach them.
One-time workDesign, migration of existing tables, staging tests and restore drills are paid once per project or per major change.Ask a partner to quote these as separate line items so later changes do not reopen the full scope.
Recurring workRetention reviews, pg_partman upgrades (the 5.x line has version-specific steps in its 5.0.1 upgrade notes), monitoring and PostgreSQL major upgrades repeat over the life of the platform.Ask the quote to state who runs each recurring task, how often, and whether a retainer covers it.

How pg_partman connects to backups, monitoring and PostgreSQL upgrades

pg_partman changes what the rest of your PostgreSQL estate has to handle: partitions appear and disappear on a schedule, so backups, alerts, application queries and upgrades all need to agree on the same partition layout. Each card below names one connection point, what has to be aligned, and whether your team or DeployOpen usually owns it.

Backup and restore procedures

Partitions that pg_partman detaches or drops change what a restore must include. Backup jobs need to capture the parent table and the current child partitions, and your restore runbook should say whether detached partitions are kept as archives or removed for good. Confirm how long detached data must remain restorable, because a dropped partition is only recoverable from a backup taken before the drop. Your team owns the retention decision; DeployOpen can design the backup and restore test that proves it.

Continuous archiving docs

Monitoring partition jobs

Track partition creation, retention runs and the premake window as metrics, not just as log lines. A useful check confirms that the next partitions exist before inserts need them and that the oldest partitions match the retention you agreed. Add these checks to the same Prometheus, Grafana or Zabbix setup that covers the rest of your PostgreSQL cluster, so partition health appears beside replication lag and disk use. Your team usually owns the dashboards; DeployOpen can define the queries and thresholds.

Alerting when maintenance stops

A stopped maintenance process fails quietly. If the background worker stops, a scheduler job fails, or a permission change blocks partition creation, inserts into future time ranges can fail or land in a default partition. Alert on the age of the newest partition and on the absence of a successful maintenance run, not only on errors. Decide who receives the alert, how quickly someone must act, and what the fallback is. Your on-call team owns the response; DeployOpen can write the alert rules and the runbook.

Scheduling against pg_cron or an external scheduler

pg_partman includes a background worker that runs maintenance in most cases without an external scheduler. Choose one scheduling owner for partition maintenance and document it, because running pg_partman maintenance from both the worker and pg_cron or a system cron job can duplicate work and complicate troubleshooting. Pick an external scheduler when your organization already runs one centrally with better job history. Your team makes this choice; DeployOpen can implement and test whichever option you select.

Query and index design in applications

Applications should filter on the partition key so the planner can prune partitions and skip the rest. Queries that omit the key scan every partition, and indexes must be created on each partition layout you expect to keep. Review the most frequent queries against the partition key before go-live, and confirm that unique constraints include the key, since PostgreSQL requires that for partitioned tables. Application teams own the query changes; DeployOpen can review the query patterns and index plan as part of the design work.

PostgreSQL major upgrade plan

Plan the pg_partman version alongside the PostgreSQL major version. pg_partman 5.x upgrades from earlier versions may need special steps described in the project's 5.0.1 upgrade notes, so read those before changing the extension version. Include the extension in the upgrade rehearsal, and confirm the pg_partman build supports your target PostgreSQL major before you start. Choose between pg_upgrade and logical replication with the same rehearsal in mind. DeployOpen can run the rehearsal and document the sequence; your team approves the cutover window.

pg_partman repository

Upgrading to pg_partman 5 without losing partition control

Upgrading pg_partman to version 5.x from an earlier release can require special steps, so treat it as a planned change rather than a package update. The project's 5.0.1 upgrade notes describe those steps, and they depend on the version you are starting from. Begin by inventorying every database where the extension is installed, the exact installed version (check with \dx pg_partman in each database), and every parent table managed by pg_partman, along with its partition interval, premake setting and retention configuration. That inventory tells you which upgrade path applies to each database and which tables must be verified afterward.

Review the 5.0.1 upgrade notes against your starting version and write the steps you will run, including any catalog or configuration changes and the order of operations with the background worker. Before touching production, restore a recent copy of the database to a separate environment with the same PostgreSQL major version, apply the planned steps, and record what changes. Confirm each step against the official notes for your exact starting version, since the notes are the authority, not this summary. Pause partition maintenance and the background worker during the window so no rotation or retention job runs against a half-upgraded schema.

After the change, verify partition control rather than assuming it. Check that new partitions are created ahead of time for each parent table, that retention drops only the partitions you expect, and that the background worker runs on schedule and logs no errors. Plan this upgrade alongside any PostgreSQL major upgrade, because the extension must match the server version it runs on and both changes touch the same databases. Ask your team to confirm the compatibility of your pg_partman build with your target PostgreSQL version before scheduling both changes in the same window.

What buyers ask before hiring help with pg_partman

What drives the cost of a pg_partman implementation?

The main cost driver is how many tables need partitioning and how much each one differs in key type, interval, retention and data volume. A single time-partitioned table with one retention rule is a small scope. Dozens of tables with mixed time and number-based keys, existing unpartitioned history that must be converted, and separate rules for each environment add work at every step. Cost is mostly one-time: design, configuration, testing of creation and retention jobs, and documentation. Recurring cost is limited to upgrades and ongoing support if you buy a retainer. When requesting a quote, ask for a table-by-table list of the work, who performs the conversion of existing tables, how restore testing is included, and which environments are covered. DeployOpen does not publish a price list, and a quote follows from the written scope.

How long does a pg_partman implementation take?

Duration depends mainly on table size, the number of tables in scope and how much existing data must be moved into partitions. Converting a large table that is already in production usually takes longer than setting up partitions on a new table, because data movement and maintenance windows must be planned around live traffic. Scope also matters: each retention rule needs to be agreed with data owners and tested before it deletes anything. We do not state a duration here because none has been researched for this topic. Ask for a timeline in the written scope that separates discovery, configuration, conversion, retention testing and handover, and confirm which steps depend on your change approval process.

Can our team implement pg_partman without outside help?

Yes, if your team already runs PostgreSQL in production and has the time to test changes. pg_partman builds on PostgreSQL's declarative partitioning, so your engineers need to understand partition keys, default partitions, how the background worker runs and how retention deletes or detaches data. The risk is usually not the setup itself but a retention rule that removes data earlier than the policy allows. Teams that do it alone should test every retention setting on a copy of the data first and document who approves retention changes. DeployOpen can take on all or part of the work, such as the design review or the restore test, and the split is agreed in writing before work starts.

What does pg_partman need from our side before work starts?

You need to provide a table inventory, a written retention policy for each dataset, agreed maintenance windows and the access required to make changes. The inventory should list each candidate table with its partition key, row volume, growth rate, indexes, foreign keys and the queries that read it. The retention policy should name the rule for each table and the person who approves changes to it. Maintenance windows matter if existing tables must be converted. Access usually means a database role with the privileges needed to create partitions and extensions, plus read access to monitoring and logs. Confirm with your security team how these privileges are granted and recorded.

Does pg_partman replace a job scheduler like pg_cron or cron?

Not always. pg_partman includes a background worker that runs partition maintenance without an external scheduler in most cases, so for many setups no separate cron job is needed. Whether you keep an external scheduler depends on how your environment runs PostgreSQL, whether the background worker is enabled in your configuration and whether maintenance must run alongside other jobs in your estate. Confirm how the background worker is configured on your server, which databases it covers and how you will monitor that maintenance ran. If you already schedule other database jobs, decide in the design phase whether partition maintenance stays with them or moves to pg_partman.

How are upgrades to pg_partman 5 handled?

Upgrading to pg_partman 5.x from an earlier version may need special steps described in the project's 5.0.1 upgrade notes. Those notes are the starting point, and the upgrade should be tested on a copy of your database before production. The plan should confirm your current pg_partman version, the target PostgreSQL major version, the order of extension and database upgrades and the rollback approach. Keep in mind that pg_partman interacts with the PostgreSQL major version you run, so a PostgreSQL upgrade and a pg_partman upgrade should be planned together. Ask for the upgrade steps to be written into the runbook as part of the handover.

Does DeployOpen certify or audit the pg_partman result?

No. DeployOpen implements, configures, tests and documents the partition setup, and prepares evidence such as configuration records, retention settings and restore test results that your compliance team or an independent auditor can review. DeployOpen does not issue audit reports, attestations or certifications, and those come from independent auditors and certification bodies. If your data falls under a regulation, ask the auditor in advance which evidence they expect for retention and deletion, and confirm that the written scope includes producing it.

How DeployOpen scopes, delivers and supports pg_partman

DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure, and pg_partman is handled the same way. Each engagement starts from a written scope covering your partitioned tables, retention rules and recovery expectations before any change reaches your database.

How we scope

  • Inventory which tables need partitions, their time or number keys, and the expected row volume per partition.
  • Agree retention periods, archival rules and which partitions may be dropped, in writing before work starts.
  • Confirm your PostgreSQL major version, pg_partman version and whether you are upgrading to pg_partman 5.

How we build

  • Set up native declarative partitioning first, then configure pg_partman against those parent tables.
  • Enable and tune the background worker, then test partition creation and retention on a non-production copy.
  • Test restores of partitioned data and confirm backups still capture every partition as expected.

How we hand over

  • Deliver configuration files, retention settings and a runbook covering routine checks and failure recovery.
  • Document the pg_partman 5 upgrade steps your environment needs, including the 5.0.1 upgrade notes applicable to your path.
  • Walk your database and operations teams through monitoring of partition creation and dropped partitions.

How we support

  • Support is available as a retainer for ongoing monitoring, pg_partman upgrades and changes to retention rules.
  • Retainers can cover coordinated updates alongside planned PostgreSQL major upgrades in your environment.
  • Confirm response expectations and the scope of support in the written agreement before the engagement begins.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.