|
| 1 | +# pg_partman |
| 2 | +<!-- |
| 3 | +SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC. |
| 4 | +SPDX-License-Identifier: Apache-2.0 |
| 5 | +--> |
| 6 | + |
| 7 | +[pg_partman](https://github.com/pgpartman/pg_partman) is a PostgreSQL extension |
| 8 | +for automated table partition management. It supports both time-based and |
| 9 | +ID-based partitioning with automatic creation and maintenance of child tables. |
| 10 | + |
| 11 | +The extension includes a background worker (`pg_partman_bgw`) that can |
| 12 | +automatically run partition maintenance at configured intervals, removing the |
| 13 | +need for external cron jobs. |
| 14 | + |
| 15 | +For more information, see the |
| 16 | +[official documentation](https://github.com/pgpartman/pg_partman). |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +The `pg_partman` extension must be loaded via `shared_preload_libraries` to |
| 21 | +enable the background worker. The worker periodically runs |
| 22 | +`partman.run_maintenance_proc()` to create new partitions and drop expired ones. |
| 23 | + |
| 24 | +### 1. Add the pg_partman extension image to your Cluster |
| 25 | + |
| 26 | +Define the `pg-partman` extension under the `postgresql.extensions` section of |
| 27 | +your `Cluster` resource. For example: |
| 28 | + |
| 29 | +```yaml |
| 30 | +apiVersion: postgresql.cnpg.io/v1 |
| 31 | +kind: Cluster |
| 32 | +metadata: |
| 33 | + name: cluster-pg-partman |
| 34 | +spec: |
| 35 | + imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie |
| 36 | + instances: 1 |
| 37 | + |
| 38 | + storage: |
| 39 | + size: 1Gi |
| 40 | + |
| 41 | + postgresql: |
| 42 | + shared_preload_libraries: |
| 43 | + - pg_partman_bgw |
| 44 | + extensions: |
| 45 | + - name: pg-partman |
| 46 | + image: |
| 47 | + # renovate: suite=trixie-pgdg depName=postgresql-18-partman |
| 48 | + reference: ghcr.io/cloudnative-pg/pg-partman:5.4.3-18-trixie |
| 49 | +``` |
| 50 | +
|
| 51 | +### 2. Enable the extension in a database |
| 52 | +
|
| 53 | +You can install `pg_partman` in a specific database by creating or updating a |
| 54 | +`Database` resource. For example, to enable it in the `app` database: |
| 55 | + |
| 56 | +```yaml |
| 57 | +apiVersion: postgresql.cnpg.io/v1 |
| 58 | +kind: Database |
| 59 | +metadata: |
| 60 | + name: cluster-pg-partman-app |
| 61 | +spec: |
| 62 | + name: app |
| 63 | + owner: app |
| 64 | + cluster: |
| 65 | + name: cluster-pg-partman |
| 66 | + extensions: |
| 67 | + - name: pg_partman |
| 68 | + # renovate: suite=trixie-pgdg depName=postgresql-18-partman |
| 69 | + version: '5.4.3' |
| 70 | +``` |
| 71 | + |
| 72 | +### 3. Verify installation |
| 73 | + |
| 74 | +Once the database is ready, connect to it with `psql` and run: |
| 75 | + |
| 76 | +```sql |
| 77 | +\dx |
| 78 | +``` |
| 79 | + |
| 80 | +You should see `pg_partman` listed among the installed extensions. |
| 81 | + |
| 82 | +## Included utilities |
| 83 | + |
| 84 | +This image also bundles the following Python maintenance scripts in `/bin/`: |
| 85 | + |
| 86 | +- `check_unique_constraint.py` — validates unique constraints across partitions |
| 87 | +- `dump_partition.py` — exports individual partitions for archival |
| 88 | +- `vacuum_maintenance.py` — targeted vacuum operations on partitioned tables |
| 89 | + |
| 90 | +> [!NOTE] |
| 91 | +> These scripts require a Python 3 runtime and the `psycopg2` library, which |
| 92 | +> are not included in the minimal base image. They are provided for |
| 93 | +> environments where Python is available on the host or in a sidecar container. |
| 94 | + |
| 95 | +## Contributors |
| 96 | + |
| 97 | +This extension is maintained by: |
| 98 | + |
| 99 | +- Erling Kristiansen (@egkristi) |
| 100 | + |
| 101 | +The maintainers are responsible for: |
| 102 | + |
| 103 | +- Monitoring upstream releases and security vulnerabilities. |
| 104 | +- Ensuring compatibility with supported PostgreSQL versions. |
| 105 | +- Reviewing and merging contributions specific to this extension's container |
| 106 | + image and lifecycle. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Licenses and Copyright |
| 111 | + |
| 112 | +This container image contains software that may be licensed under various |
| 113 | +open-source licenses. |
| 114 | + |
| 115 | +All relevant license and copyright information for the `pg_partman` extension |
| 116 | +and its dependencies are bundled within the image at: |
| 117 | + |
| 118 | +```text |
| 119 | +/licenses/ |
| 120 | +``` |
| 121 | + |
| 122 | +By using this image, you agree to comply with the terms of the licenses |
| 123 | +contained therein. |
0 commit comments