Skip to content

Commit c87dc1c

Browse files
feat: add pg_repack container image
Adds the `pg_repack` extension, a tool for online reorganization of tables and indexes. It allows to release BLOAT on heavily updated relations. Closes #170
1 parent f24a0c9 commit c87dc1c

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

pgrepack/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
6+
FROM $BASE AS builder
7+
8+
ARG PG_MAJOR
9+
ARG EXT_VERSION
10+
11+
USER 0
12+
13+
# TODO: Remove this comment block after customizing the Dockerfile
14+
# Instructions:
15+
# 1. Remove all TODO comment blocks after completing the customization.
16+
# 2. Uncomment and customize the COPY/RUN commands below.
17+
# 3. If your extension requires additional system libraries, ensure they are
18+
# copied to /lib.
19+
20+
# Install extension via `apt-get`
21+
# RUN apt-get update && apt-get install -y --no-install-recommends \
22+
# "postgresql-${PG_MAJOR}-pg_repack=${EXT_VERSION}"
23+
24+
FROM scratch
25+
ARG PG_MAJOR
26+
27+
# Licenses
28+
# TODO: Uncomment and customize the COPY command below
29+
# Including license files is essential for legal compliance and transparency.
30+
# It ensures proper attribution to original authors, fulfills open source license
31+
# requirements, and enables automated compliance scanning tools to verify licensing.
32+
# COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-pg_repack/copyright /licenses/postgresql-${PG_MAJOR}-pg_repack/
33+
34+
# Libraries
35+
# TODO: Uncomment and customize the COPY command below
36+
# Include the extension's shared objects and related dependencies under the /lib directory.
37+
# CNPG will configure PostgreSQL to locate these libraries at runtime by configuring
38+
# the "dynamic_library_path" GUC to include this path.
39+
# For more details, see: https://cloudnative-pg.io/docs/current/imagevolume_extensions#how-it-works
40+
# COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_repack* /lib/
41+
42+
# Share
43+
# TODO: Uncomment and customize the COPY command below
44+
# Include the extension's SQL scripts and control files under the /share/extension directory.
45+
# CNPG will configure PostgreSQL to include this path via the "extension_control_path" GUC to
46+
# seamlessly find and manage the current extension.
47+
# For more details, see: https://cloudnative-pg.io/docs/current/imagevolume_extensions#how-it-works
48+
# COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_repack* /share/extension/
49+
50+
USER 65532:65532

pgrepack/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Pg_repack
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+
<!--
8+
TODO: Replace this section with a brief introduction of your extension.
9+
Describe what the extension does and what it is useful for.
10+
Add a reference to the official documentation if available.
11+
-->
12+
13+
The pg_repack PostgreSQL extension provides a binary tool that can perform online operation that can remove bloat from tables and indexes. For more information, see the [official documentation](https://reorg.github.io/pg_repack/).
14+
15+
## Usage
16+
17+
<!--
18+
Usage: add instructions on how to use the extension with CloudNativePG.
19+
Include code snippets for Cluster and Database resources as needed.
20+
-->
21+
22+
### 1. Add the pg_repack extension image to your Cluster
23+
24+
Define the `pg_repack` extension under the `postgresql.extensions` section of
25+
your `Cluster` resource. For example:
26+
27+
```yaml
28+
apiVersion: postgresql.cnpg.io/v1
29+
kind: Cluster
30+
metadata:
31+
name: cluster-pg_repack
32+
spec:
33+
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
34+
instances: 1
35+
36+
storage:
37+
size: 1Gi
38+
39+
postgresql:
40+
extensions:
41+
- name: pg_repack
42+
image:
43+
# renovate: suite=trixie-pgdg depName=postgresql-18-pg_repack
44+
reference: ghcr.io/cloudnative-pg/pg_repack:1.0-18-trixie
45+
```
46+
47+
### 2. Enable the extension in a database
48+
49+
You can install `pg_repack` in a specific database by creating or updating a
50+
`Database` resource. For example, to enable it in the `app` database:
51+
52+
```yaml
53+
apiVersion: postgresql.cnpg.io/v1
54+
kind: Database
55+
metadata:
56+
name: cluster-pg_repack-app
57+
spec:
58+
name: app
59+
owner: app
60+
cluster:
61+
name: cluster-pg_repack
62+
extensions:
63+
- name: pg_repack
64+
# renovate: suite=trixie-pgdg depName=postgresql-18-pg_repack extractVersion=^(?<version>\d+\.\d+\.\d+)
65+
version: '1.0'
66+
```
67+
68+
<!--
69+
TODO: Adjust the extractVersion regex pattern above based on your extension's versioning scheme
70+
Examples: \d+\.\d+ for major.minor (e.g., "18.0"), \d+\.\d+\.\d+ for major.minor.patch (e.g., "0.8.2")
71+
-->
72+
73+
### 3. Verify installation
74+
75+
Once the database is ready, connect to it with `psql` and run:
76+
77+
```sql
78+
\dx
79+
```
80+
81+
You should see `pg_repack` listed among the installed extensions.
82+
83+
## Contributors
84+
85+
This extension is maintained by:
86+
87+
- FirstName LastName (@GitHub_Handle)
88+
89+
The maintainers are responsible for:
90+
91+
- Monitoring upstream releases and security vulnerabilities.
92+
- Ensuring compatibility with supported PostgreSQL versions.
93+
- Reviewing and merging contributions specific to this extension's container
94+
image and lifecycle.
95+
96+
---
97+
98+
## Licenses and Copyright
99+
100+
This container image contains software that may be licensed under various
101+
open-source licenses.
102+
103+
All relevant license and copyright information for the `pg_repack` extension
104+
and its dependencies are bundled within the image at:
105+
106+
```text
107+
/licenses/
108+
```
109+
110+
By using this image, you agree to comply with the terms of the licenses
111+
contained therein.

pgrepack/metadata.hcl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
metadata = {
4+
name = "pgrepack"
5+
sql_name = "pg_repack"
6+
7+
# TODO: Remove this comment block after customizing the file.
8+
# `image_name`: MUST be unique across the container registry because
9+
# it identifies the image (e.g. ghcr.io/cloudnative-pg/<image_name>)
10+
image_name = "pgrepack"
11+
12+
# TODO: Remove this comment block after customizing the file.
13+
# `licenses`: A list of SPDX identifiers representing the main software's licenses.
14+
# Formatting Rules:
15+
# - Must be a list of strings: ["MIT", "Apache-2.0"]
16+
# - Use SPDX IDs exactly as they appear at https://spdx.org/licenses/
17+
# - These are automatically joined with " AND " to populate the OCI label
18+
# org.opencontainers.image.licenses
19+
# Warning: the ghcr.io registry requires labels < 256 characters
20+
# Examples: "Apache-2.0", "PostgreSQL", "MIT".
21+
licenses = ["BSD-3-Clause"]
22+
23+
# TODO: Remove this comment block after customizing the file.
24+
# `shared_preload_libraries`: list libraries to be added to
25+
# `shared_preload_libraries` in Postgres. Usually empty.
26+
# Used in tests.
27+
# Example: ["pgaudit"].
28+
shared_preload_libraries = ["pg_repack"]
29+
30+
# TODO: Remove this comment block after customizing the file.
31+
# `extension_control_path`: if EMPTY (`[]`), the operator follows the CNPG
32+
# convention and will add the image's `share` directory to
33+
# `extension_control_path`. Usually empty.
34+
# Used in tests and to generate image catalogs.
35+
# See: https://cloudnative-pg.io/docs/current/imagevolume_extensions#image-specifications
36+
extension_control_path = []
37+
38+
# TODO: Remove this comment block after customizing the file.
39+
# `dynamic_library_path`: if EMPTY (`[]`) the operator will add the image's
40+
# `lib` directory to `dynamic_library_path`. Usually empty.
41+
# Used in tests and to generate image catalogs.
42+
dynamic_library_path = []
43+
44+
# TODO: Remove this comment block after customizing the file.
45+
# `ld_library_path`: this SHOULD be defined when your extension needs
46+
# additional (usually system) libraries loaded into Postgres before startup.
47+
# If left EMPTY (`[]`) the operator will NOT alter `ld_library_path`. See the
48+
# `postgis` extension metadata for an example usage. Usually empty.
49+
# Used in tests and to generate image catalogs.
50+
ld_library_path = []
51+
52+
# TODO: Remove this comment block after customizing the file.
53+
# `bin_path`: this SHOULD be defined when your extension needs executables
54+
# to be present in the PATH of the PostgreSQL process to function properly.
55+
# For most extensions, the default empty list (`[]`) is correct and the
56+
# operator will NOT alter `PATH`.
57+
# Each path provided is appended to the `PATH` environment variable for the
58+
# Postgres process. Used in tests and to generate image catalogs.
59+
bin_path = []
60+
61+
# TODO: Remove this comment block after customizing the file.
62+
# `auto_update_os_libs`: set to true to allow the maintenance tooling
63+
# to update OS libraries automatically; look at the `postgis` example.
64+
auto_update_os_libs = false
65+
66+
# TODO: Remove this comment block after customizing the file.
67+
# `required_extensions`: must contain the name(s) of the sibling
68+
# folders in this repository that contain a required extension.
69+
required_extensions = []
70+
71+
# TODO: Remove this comment block after customizing the file.
72+
# `create_extension`: if set to `true` (default), the test suite will
73+
# automatically run `CREATE EXTENSION` for this project during E2E tests.
74+
# Set to `false` if the image only provides libraries or tools without
75+
# a formal Postgres extension object.
76+
create_extension = true
77+
78+
versions = {
79+
trixie = {
80+
"18" = {
81+
// renovate: suite=trixie-pgdg depName=postgresql-18-pg_repack
82+
package = "1.5.3-1.pgdg13+1"
83+
// Examples: \d+\.\d+ for major.minor (e.g., "18.0"), \d+\.\d+\.\d+ for major.minor.patch (e.g., "0.8.2")
84+
// renovate: suite=trixie-pgdg depName=postgresql-18-pg_repack extractVersion=^(?<version>\d+\.\d+\.\d+)
85+
sql = "1.5.3"
86+
}
87+
}
88+
bookworm = {
89+
"18" = {
90+
// renovate: suite=bookworm-pgdg depName=postgresql-18-pg_repack
91+
package = "1.5.3-1.pgdg12+1"
92+
// Examples: \d+\.\d+ for major.minor (e.g., "18.0"), \d+\.\d+\.\d+ for major.minor.patch (e.g., "0.8.2")
93+
// renovate: suite=bookworm-pgdg depName=postgresql-18-pg_repack extractVersion=^(?<version>\d+\.\d+\.\d+)
94+
sql = "1.5.3"
95+
}
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)