pg_partman

Extension to manage partitioned tables by time or ID

Overview

PackageVersionCategoryLicenseLanguage
pg_partman5.4.3OLAPPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
2510pg_partmanNoYesNoYesNoNo-
Relatedcitus pg_fkpart timescaledb periods emaj pg_cron plproxy temporal_tables
Depended Bytimeseries

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG5.4.31817161514pg_partman-
RPMPGDG5.4.31817161514pg_partman_$v-
DEBPGDG5.4.31817161514postgresql-$v-partman-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 5.4.3
el8.x86_64.pg14 : pg_partman_14
pg_partman_14-5.4.3-1PGDG.rhel8.10.x86_64.rpm PGDG · 5.4.3 · 279.6KiB pg_partman_14-5.4.2-1PGDG.rhel8.10.x86_64.rpm PGDG · 5.4.2 · 279.0KiB pg_partman_14-5.4.1-1PGDG.rhel8.10.x86_64.rpm PGDG · 5.4.1 · 278.6KiB pg_partman_14-5.4.0-1PGDG.rhel8.10.x86_64.rpm PGDG · 5.4.0 · 275.3KiB pg_partman_14-5.3.1-1PGDG.rhel8.x86_64.rpm PGDG · 5.3.1 · 271.3KiB pg_partman_14-5.3.0-1PGDG.rhel8.x86_64.rpm PGDG · 5.3.0 · 270.4KiB pg_partman_14-5.2.4-1PGDG.rhel8.x86_64.rpm PGDG · 5.2.4 · 261.4KiB pg_partman_14-5.2.3-1PGDG.rhel8.x86_64.rpm PGDG · 5.2.3 · 260.9KiB pg_partman_14-5.2.2-1PGDG.rhel8.x86_64.rpm PGDG · 5.2.2 · 260.1KiB pg_partman_14-5.2.1-1PGDG.rhel8.x86_64.rpm PGDG · 5.2.1 · 259.6KiB pg_partman_14-5.2.0-1PGDG.rhel8.x86_64.rpm PGDG · 5.2.0 · 259.3KiB pg_partman_14-5.1.0-1PGDG.rhel8.x86_64.rpm PGDG · 5.1.0 · 254.7KiB pg_partman_14-5.0.1-1PGDG.rhel8.x86_64.rpm PGDG · 5.0.1 · 249.4KiB pg_partman_14-5.0.0-1PGDG.rhel8.x86_64.rpm PGDG · 5.0.0 · 248.4KiB pg_partman_14-4.7.4-1PGDG.rhel8.x86_64.rpm PGDG · 4.7.4 · 246.9KiB pg_partman_14-4.7.3-3.rhel8.x86_64.rpm PGDG · 4.7.3 · 246.5KiB pg_partman_14-4.7.3-1.rhel8.x86_64.rpm PGDG · 4.7.3 · 246.2KiB pg_partman_14-4.7.2-1.rhel8.x86_64.rpm PGDG · 4.7.2 · 245.7KiB pg_partman_14-4.7.1-1.rhel8.x86_64.rpm PGDG · 4.7.1 · 260.6KiB pg_partman_14-4.7.0-1.rhel8.x86_64.rpm PGDG · 4.7.0 · 259.9KiB pg_partman_14-4.6.2-1.rhel8.x86_64.rpm PGDG · 4.6.2 · 256.2KiB pg_partman_14-4.6.1-1.rhel8.x86_64.rpm PGDG · 4.6.1 · 255.7KiB pg_partman_14-4.6.0-1.rhel8.x86_64.rpm PGDG · 4.6.0 · 252.2KiB pg_partman_14-4.5.1-2.rhel8.x86_64.rpm PGDG · 4.5.1 · 246.5KiB
el8.aarch64
el9.x86_64
PGDG 5.4.3
el9.x86_64.pg14 : pg_partman_14
pg_partman_14-5.4.3-1PGDG.rhel9.7.x86_64.rpm PGDG · 5.4.3 · 218.5KiB pg_partman_14-5.4.2-1PGDG.rhel9.7.x86_64.rpm PGDG · 5.4.2 · 218.0KiB pg_partman_14-5.4.1-1PGDG.rhel9.7.x86_64.rpm PGDG · 5.4.1 · 217.8KiB pg_partman_14-5.4.0-1PGDG.rhel9.7.x86_64.rpm PGDG · 5.4.0 · 216.1KiB pg_partman_14-5.3.1-1PGDG.rhel9.x86_64.rpm PGDG · 5.3.1 · 213.7KiB pg_partman_14-5.3.0-1PGDG.rhel9.x86_64.rpm PGDG · 5.3.0 · 212.9KiB pg_partman_14-5.2.4-1PGDG.rhel9.x86_64.rpm PGDG · 5.2.4 · 207.3KiB pg_partman_14-5.2.3-1PGDG.rhel9.x86_64.rpm PGDG · 5.2.3 · 206.9KiB pg_partman_14-5.2.2-1PGDG.rhel9.x86_64.rpm PGDG · 5.2.2 · 206.2KiB pg_partman_14-5.2.1-1PGDG.rhel9.x86_64.rpm PGDG · 5.2.1 · 205.9KiB pg_partman_14-5.2.0-1PGDG.rhel9.x86_64.rpm PGDG · 5.2.0 · 205.6KiB pg_partman_14-5.1.0-1PGDG.rhel9.x86_64.rpm PGDG · 5.1.0 · 201.7KiB pg_partman_14-5.0.1-1PGDG.rhel9.x86_64.rpm PGDG · 5.0.1 · 197.9KiB pg_partman_14-5.0.0-1PGDG.rhel9.x86_64.rpm PGDG · 5.0.0 · 197.2KiB pg_partman_14-4.7.4-1PGDG.rhel9.x86_64.rpm PGDG · 4.7.4 · 198.7KiB pg_partman_14-4.7.3-3.rhel9.x86_64.rpm PGDG · 4.7.3 · 198.5KiB pg_partman_14-4.7.3-1.rhel9.x86_64.rpm PGDG · 4.7.3 · 198.4KiB pg_partman_14-4.7.2-1.rhel9.x86_64.rpm PGDG · 4.7.2 · 198.1KiB pg_partman_14-4.7.1-1.rhel9.x86_64.rpm PGDG · 4.7.1 · 213.6KiB pg_partman_14-4.7.0-1.rhel9.x86_64.rpm PGDG · 4.7.0 · 213.1KiB pg_partman_14-4.6.2-1.rhel9.x86_64.rpm PGDG · 4.6.2 · 211.1KiB pg_partman_14-4.6.1-1.rhel9.x86_64.rpm PGDG · 4.6.1 · 210.6KiB
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Build

You can build the RPM / DEB packages for pg_partman using pig build:

pig build pkg pg_partman         # build RPM / DEB packages

Install

You can install pg_partman directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_partman;          # Install for current active PG version
pig ext install -y pg_partman -v 18  # PG 18
pig ext install -y pg_partman -v 17  # PG 17
pig ext install -y pg_partman -v 16  # PG 16
pig ext install -y pg_partman -v 15  # PG 15
pig ext install -y pg_partman -v 14  # PG 14
dnf install -y pg_partman_18       # PG 18
dnf install -y pg_partman_17       # PG 17
dnf install -y pg_partman_16       # PG 16
dnf install -y pg_partman_15       # PG 15
dnf install -y pg_partman_14       # PG 14
apt install -y postgresql-18-partman   # PG 18
apt install -y postgresql-17-partman   # PG 17
apt install -y postgresql-16-partman   # PG 16
apt install -y postgresql-15-partman   # PG 15
apt install -y postgresql-14-partman   # PG 14

Create Extension:

CREATE EXTENSION pg_partman;

Usage

pg_partman: Extension to manage partitioned tables by time or ID

pg_partman automates creation and management of both time-based and number-based partition sets using PostgreSQL’s native declarative partitioning (v5.0+). It handles adding new partitions and removing old ones per retention policies, with an optional background worker for automatic maintenance.

Create the Extension

CREATE SCHEMA partman;
CREATE EXTENSION pg_partman SCHEMA partman;

Create a Time-Based Partition Set

CREATE TABLE public.measurements (
    id          bigserial,
    created_at  timestamptz NOT NULL DEFAULT now(),
    value       numeric
) PARTITION BY RANGE (created_at);

SELECT partman.create_parent(
    p_parent_table  := 'public.measurements',
    p_control       := 'created_at',
    p_interval      := '1 day'
);

Create a Serial/ID-Based Partition Set

CREATE TABLE public.events (
    id      bigserial,
    data    text
) PARTITION BY RANGE (id);

SELECT partman.create_parent(
    p_parent_table  := 'public.events',
    p_control       := 'id',
    p_interval      := '100000'
);

Run Maintenance

Manually trigger partition maintenance (create new partitions, drop expired ones):

SELECT partman.run_maintenance();

Or for a specific table:

SELECT partman.run_maintenance(p_parent_table := 'public.measurements');

Configure Retention

Update the configuration to set retention policy:

UPDATE partman.part_config
SET    retention = '30 days',
       retention_keep_table = false
WHERE  parent_table = 'public.measurements';

Background Worker

Enable automatic maintenance in postgresql.conf:

shared_preload_libraries = 'pg_partman_bgw'
pg_partman_bgw.interval = 3600          -- run every hour (seconds)
pg_partman_bgw.dbname = 'mydb'

Migrate Existing Data into Partitions

CALL partman.partition_data_proc('public.measurements');

Show Partitions

SELECT * FROM partman.show_partitions('public.measurements');

Undo Partitioning

CALL partman.undo_partition_proc('public.measurements');

Last Modified 2026-03-12: add pg extension catalog (95749bf)