-
Notifications
You must be signed in to change notification settings - Fork 37
Feat/Add pg_ivm Extension Support #49
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
shusaan
wants to merge
10
commits into
cloudnative-pg:main
Choose a base branch
from
shusaan:feat/add-pg_vim-extension
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
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b047e98
feat(pg_ivm): add pg_ivm extension container image
shusaan a614a58
Ensures license file is properly included in final container image
shusaan 940d06a
docs(pg_ivm): update README with shared_preload_libraries configuration
shusaan 55f734b
chore(pg_ivm): update package source and versions
shusaan 3c13bba
update metadata.hcl
shusaan 3ba115f
chore: review Dockerfile and metadata.hcl
NiccoloFei 5c81387
fix: use pg_ivm (with underscore) only for the sql_name
NiccoloFei ca923ed
test: replace CRLF with LF for consistency
NiccoloFei 477fa45
test: make smoke test idempotent and fix wrong syntax
NiccoloFei 5567350
Merge branch 'main' into feat/add-pg_vim-extension
shusaan 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
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
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,28 @@ | ||
| # 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 | ||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends "postgresql-${PG_MAJOR}-pg-ivm=${EXT_VERSION}" | ||
|
|
||
| FROM scratch | ||
| ARG PG_MAJOR | ||
|
|
||
| # Licenses | ||
| COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-pg-ivm/copyright /licenses/postgresql-${PG_MAJOR}-pg-ivm/ | ||
|
|
||
| # Libraries | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_ivm* /lib/ | ||
| COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/ /lib/bitcode/ | ||
|
|
||
| # Share | ||
| COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_ivm* /share/extension/ | ||
|
|
||
| USER 65532:65532 | ||
|
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. Can you add a new line here? |
||
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,84 @@ | ||
| # `pg_ivm` | ||
|
|
||
| [pg_ivm](https://github.com/sraoss/pg_ivm) is an open-source extension | ||
| that provides **Incremental View Maintenance (IVM)** for PostgreSQL, allowing | ||
| materialized views to be updated incrementally when base tables change. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### 1. Add the pg_ivm extension image to your Cluster | ||
|
|
||
| Define the `pg_ivm` extension under the `postgresql.extensions` section of | ||
| your `Cluster` resource. For example: | ||
|
|
||
| ```yaml | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: cluster-pg-ivm | ||
| spec: | ||
| imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie | ||
| instances: 1 | ||
|
|
||
| storage: | ||
| size: 1Gi | ||
|
|
||
| postgresql: | ||
| extensions: | ||
| - name: pg_ivm | ||
| image: | ||
| # renovate: suite=trixie-pgdg depName=postgresql-18-pg-ivm | ||
| reference: ghcr.io/cloudnative-pg/pg-ivm:1.13-18-trixie | ||
| ``` | ||
|
|
||
| ### 2. Enable the extension in a database | ||
|
|
||
| You can install `pg_ivm` 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-ivm-app | ||
| spec: | ||
| name: app | ||
| owner: app | ||
| cluster: | ||
| name: cluster-pg-ivm | ||
| extensions: | ||
| - name: pg_ivm | ||
| # renovate: suite=trixie-pgdg depName=postgresql-18-pg-ivm extractVersion=^(?<version>\d+\.\d+) | ||
| version: '1.13' | ||
| ``` | ||
|
|
||
| ### 3. Verify installation | ||
|
|
||
| Once the database is ready, connect to it with `psql` and run: | ||
|
|
||
| ```sql | ||
| \dx | ||
| ``` | ||
|
|
||
| You should see `pg_ivm` listed among the installed extensions. | ||
|
|
||
| ## Maintainers | ||
|
|
||
| This container image is maintained by @shuusan. | ||
|
|
||
| --- | ||
|
|
||
| ## 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_ivm` 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,35 @@ | ||
| metadata = { | ||
| name = "pg-ivm" | ||
| sql_name = "pg_ivm" | ||
| image_name = "pg-ivm" | ||
| licenses = ["PostgreSQL"] | ||
| shared_preload_libraries = [] | ||
| postgresql_parameters = {} | ||
| extension_control_path = [] | ||
| dynamic_library_path = [] | ||
| ld_library_path = [] | ||
| bin_path = [] | ||
| env = {} | ||
| auto_update_os_libs = false | ||
| required_extensions = [] | ||
| create_extension = true | ||
|
|
||
| versions = { | ||
| trixie = { | ||
| "18" = { | ||
| // renovate: suite=trixie-pgdg depName=postgresql-18-pg-ivm | ||
| package = "1.13-1.pgdg13+1" | ||
| // renovate: suite=trixie-pgdg depName=postgresql-18-pg-ivm extractVersion=^(?<version>\d+\.\d+) | ||
| sql = "1.13" | ||
| } | ||
| } | ||
| bookworm = { | ||
| "18" = { | ||
| // renovate: suite=bookworm-pgdg depName=postgresql-18-pg-ivm | ||
| package = "1.13-1.pgdg12+1" | ||
| // renovate: suite=bookworm-pgdg depName=postgresql-18-pg-ivm extractVersion=^(?<version>\d+\.\d+) | ||
| sql = "1.13" | ||
| } | ||
| } | ||
| } | ||
| } |
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,28 @@ | ||
| apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
| kind: Test | ||
| metadata: | ||
| name: verify-pg-ivm-extension | ||
| spec: | ||
| timeouts: | ||
| apply: 5s | ||
| assert: 3m | ||
| delete: 30s | ||
| description: Verify pg_ivm extension is properly installed | ||
| steps: | ||
| - name: Create a Cluster with the extension | ||
| try: | ||
| - apply: | ||
| file: cluster.yaml | ||
| - apply: | ||
| file: database.yaml | ||
| - assert: | ||
| file: cluster-assert.yaml | ||
| - assert: | ||
| file: database-assert.yaml | ||
|
|
||
| - name: Verify extension is installed | ||
| try: | ||
| - apply: | ||
| file: check-extension.yaml | ||
| - assert: | ||
| file: check-extension-assert.yaml |
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,6 @@ | ||
| apiVersion: batch/v1 | ||
| kind: Job | ||
| metadata: | ||
| name: extension-installed | ||
| status: | ||
| succeeded: 1 |
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,33 @@ | ||||||||
| apiVersion: batch/v1 | ||||||||
| kind: Job | ||||||||
| metadata: | ||||||||
| name: extension-installed | ||||||||
| spec: | ||||||||
| template: | ||||||||
| spec: | ||||||||
| restartPolicy: OnFailure | ||||||||
| containers: | ||||||||
| - name: data-test | ||||||||
| env: | ||||||||
| - name: EXT_VERSION | ||||||||
| value: ($values.version) | ||||||||
| - name: DB_URI | ||||||||
| valueFrom: | ||||||||
| secretKeyRef: | ||||||||
| name: (join('-', [$values.name, 'app'])) | ||||||||
| key: uri | ||||||||
| image: alpine/psql:latest | ||||||||
|
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.
Suggested change
|
||||||||
| command: ['sh', '-c'] | ||||||||
| args: | ||||||||
| - | | ||||||||
| set -e | ||||||||
| DB_URI=$(echo $DB_URI | sed "s|/\*|/|") | ||||||||
| test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'pg_ivm' AND extversion = '${EXT_VERSION}')" -q)" = "t" | ||||||||
| psql "$DB_URI" -c "DROP TABLE IF EXISTS test_ivm CASCADE;" | ||||||||
| psql "$DB_URI" -c "DROP TABLE IF EXISTS base_table CASCADE;" | ||||||||
| psql "$DB_URI" -c "CREATE TABLE base_table (id INT PRIMARY KEY, value TEXT);" | ||||||||
| psql "$DB_URI" -c "INSERT INTO base_table VALUES (1, 'test');" | ||||||||
| psql "$DB_URI" -c "SELECT pgivm.create_immv('test_ivm', 'SELECT * FROM base_table');" | ||||||||
| test "$(psql "$DB_URI" -tAc "SELECT COUNT(*) FROM test_ivm" -q)" = "1" | ||||||||
| psql "$DB_URI" -c "INSERT INTO base_table VALUES (2, 'test2');" | ||||||||
| test "$(psql "$DB_URI" -tAc "SELECT COUNT(*) FROM test_ivm" -q)" = "2" | ||||||||
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,8 @@ | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: ($values.name) | ||
| status: | ||
| readyInstances: 1 | ||
| phase: Cluster in healthy state | ||
| image: ($values.pg_image) |
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,15 @@ | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: ($values.name) | ||
| spec: | ||
| imageName: ($values.pg_image) | ||
| instances: 1 | ||
|
|
||
| storage: | ||
| size: 1Gi | ||
|
|
||
| postgresql: | ||
| parameters: ($values.postgresql_parameters) | ||
| shared_preload_libraries: ($values.shared_preload_libraries) | ||
| extensions: ($values.extensions) |
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,10 @@ | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Database | ||
| metadata: | ||
| name: (join('-', [$values.name, 'app'])) | ||
| status: | ||
| applied: true | ||
| extensions: | ||
| - applied: true | ||
| name: ($values.sql_name) | ||
| observedGeneration: 1 |
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,12 @@ | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Database | ||
| metadata: | ||
| name: (join('-', [$values.name, 'app'])) | ||
| spec: | ||
| name: app | ||
| owner: app | ||
| cluster: | ||
| name: ($values.name) | ||
| extensions: | ||
| - name: ($values.sql_name) | ||
| version: ($values.version) |
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.