-
Notifications
You must be signed in to change notification settings - Fork 32
Added pg_partman extension #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
egkristi
wants to merge
1
commit into
cloudnative-pg:main
Choose a base branch
from
egkristi:dev/pg-partman
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie | ||
| FROM $BASE AS builder | ||
|
|
||
| ARG PG_MAJOR | ||
| ARG EXT_VERSION | ||
|
|
||
| USER 0 | ||
|
|
||
| # Install extension via `apt-get` | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| "postgresql-${PG_MAJOR}-partman=${EXT_VERSION}" | ||
|
|
||
| FROM scratch | ||
| ARG PG_MAJOR | ||
|
|
||
| # Licenses | ||
| COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-partman/copyright /licenses/postgresql-${PG_MAJOR}-partman/ | ||
|
|
||
| # Libraries | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_partman_bgw.so /lib/ | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/ /lib/bitcode/ | ||
|
|
||
| # Share | ||
| COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_partman* /share/extension/ | ||
|
|
||
| # Binaries (maintenance scripts) | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/bin/check_unique_constraint.py /bin/ | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/bin/dump_partition.py /bin/ | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/bin/vacuum_maintenance.py /bin/ | ||
|
|
||
| USER 65532:65532 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # pg_partman | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
|
|
||
| [pg_partman](https://github.com/pgpartman/pg_partman) is a PostgreSQL extension | ||
| for automated table partition management. It supports both time-based and | ||
| ID-based partitioning with automatic creation and maintenance of child tables. | ||
|
|
||
| The extension includes a background worker (`pg_partman_bgw`) that can | ||
| automatically run partition maintenance at configured intervals, removing the | ||
| need for external cron jobs. | ||
|
|
||
| For more information, see the | ||
| [official documentation](https://github.com/pgpartman/pg_partman). | ||
|
|
||
| ## Usage | ||
|
|
||
| The `pg_partman` extension must be loaded via `shared_preload_libraries` to | ||
| enable the background worker. The worker periodically runs | ||
| `partman.run_maintenance_proc()` to create new partitions and drop expired ones. | ||
|
|
||
| ### 1. Add the pg_partman extension image to your Cluster | ||
|
|
||
| Define the `pg-partman` extension under the `postgresql.extensions` section of | ||
| your `Cluster` resource. For example: | ||
|
|
||
| ```yaml | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: cluster-pg-partman | ||
| spec: | ||
| imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie | ||
| instances: 1 | ||
|
|
||
| storage: | ||
| size: 1Gi | ||
|
|
||
| postgresql: | ||
| shared_preload_libraries: | ||
| - pg_partman_bgw | ||
| extensions: | ||
| - name: pg-partman | ||
| image: | ||
| # renovate: suite=trixie-pgdg depName=postgresql-18-partman | ||
| reference: ghcr.io/cloudnative-pg/pg-partman:5.4.3-18-trixie | ||
| ``` | ||
|
|
||
| ### 2. Enable the extension in a database | ||
|
|
||
| You can install `pg_partman` in a specific database by creating or updating a | ||
| `Database` resource. For example, to enable it in the `app` database: | ||
|
|
||
| ```yaml | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Database | ||
| metadata: | ||
| name: cluster-pg-partman-app | ||
| spec: | ||
| name: app | ||
| owner: app | ||
| cluster: | ||
| name: cluster-pg-partman | ||
| extensions: | ||
| - name: pg_partman | ||
| # renovate: suite=trixie-pgdg depName=postgresql-18-partman | ||
| version: '5.4.3' | ||
| ``` | ||
|
|
||
| ### 3. Verify installation | ||
|
|
||
| Once the database is ready, connect to it with `psql` and run: | ||
|
|
||
| ```sql | ||
| \dx | ||
| ``` | ||
|
|
||
| You should see `pg_partman` listed among the installed extensions. | ||
|
|
||
| ## Included utilities | ||
|
|
||
| This image also bundles the following Python maintenance scripts in `/bin/`: | ||
|
|
||
| - `check_unique_constraint.py` — validates unique constraints across partitions | ||
| - `dump_partition.py` — exports individual partitions for archival | ||
| - `vacuum_maintenance.py` — targeted vacuum operations on partitioned tables | ||
|
|
||
| > [!NOTE] | ||
| > These scripts require a Python 3 runtime and the `psycopg2` library, which | ||
| > are not included in the minimal base image. They are provided for | ||
| > environments where Python is available on the host or in a sidecar container. | ||
|
|
||
| ## Contributors | ||
|
|
||
| This extension is maintained by: | ||
|
|
||
| - Erling Kristiansen (@egkristi) | ||
|
|
||
| The maintainers are responsible for: | ||
|
|
||
| - Monitoring upstream releases and security vulnerabilities. | ||
| - Ensuring compatibility with supported PostgreSQL versions. | ||
| - Reviewing and merging contributions specific to this extension's container | ||
| image and lifecycle. | ||
|
|
||
| --- | ||
|
|
||
| ## Licenses and Copyright | ||
|
|
||
| This container image contains software that may be licensed under various | ||
| open-source licenses. | ||
|
|
||
| All relevant license and copyright information for the `pg_partman` extension | ||
| and its dependencies are bundled within the image at: | ||
|
|
||
| ```text | ||
| /licenses/ | ||
| ``` | ||
|
|
||
| By using this image, you agree to comply with the terms of the licenses | ||
| contained therein. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| metadata = { | ||
| name = "pg-partman" | ||
| sql_name = "pg_partman" | ||
| image_name = "pg-partman" | ||
| licenses = ["PostgreSQL"] | ||
| shared_preload_libraries = ["pg_partman_bgw"] | ||
| postgresql_parameters = {} | ||
| extension_control_path = [] | ||
| dynamic_library_path = [] | ||
| ld_library_path = [] | ||
| bin_path = ["bin"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for following this standard |
||
| env = {} | ||
| auto_update_os_libs = false | ||
| required_extensions = [] | ||
| create_extension = true | ||
|
|
||
| versions = { | ||
| bookworm = { | ||
| "18" = { | ||
| // renovate: suite=bookworm-pgdg depName=postgresql-18-partman | ||
| package = "5.4.3-1.pgdg12+1" | ||
| // renovate: suite=bookworm-pgdg depName=postgresql-18-partman extractVersion=^(?<version>\d+\.\d+\.\d+) | ||
| sql = "5.4.3" | ||
| } | ||
| } | ||
| trixie = { | ||
| "18" = { | ||
| // renovate: suite=trixie-pgdg depName=postgresql-18-partman | ||
| package = "5.4.3-1.pgdg13+1" | ||
| // renovate: suite=trixie-pgdg depName=postgresql-18-partman extractVersion=^(?<version>\d+\.\d+\.\d+) | ||
| sql = "5.4.3" | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!