Skip to content

Commit 4298330

Browse files
shusaanNiccoloFei
authored andcommitted
chore(pg_ivm): update package source and versions
Signed-off-by: Husn E Rabbi <shussan@gmail.com>
1 parent b125bb4 commit 4298330

File tree

11 files changed

+252
-117
lines changed

11 files changed

+252
-117
lines changed

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
# https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners
44

55
* @cloudnative-pg/maintainers @NiccoloFei
6+
# pg_ivm
7+
/pg_ivm/ @shusaan @cloudnative-pg/maintainers @NiccoloFei

pg_ivm/Dockerfile

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
2-
FROM $BASE AS builder
3-
4-
ARG PG_MAJOR
5-
ARG EXT_VERSION
6-
7-
USER 0
8-
9-
RUN set -eux; \
10-
apt-get update; \
11-
apt-get install -y --no-install-recommends \
12-
build-essential \
13-
ca-certificates \
14-
git \
15-
postgresql-server-dev-${PG_MAJOR}; \
16-
# Clone and build pg_ivm from source
17-
git clone --branch "v${EXT_VERSION}" --depth 1 https://github.com/sraoss/pg_ivm.git /build/pg_ivm; \
18-
cd /build/pg_ivm; \
19-
make USE_PGXS=1; \
20-
make USE_PGXS=1 install
21-
22-
FROM scratch
23-
ARG PG_MAJOR
24-
25-
# Licenses
26-
COPY --from=builder /build/pg_ivm/LICENSE /licenses/pg_ivm/LICENSE
27-
28-
# Libraries
29-
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_ivm* /lib/
30-
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/
31-
32-
# Share
33-
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_ivm* /share/extension/
34-
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+
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
5+
FROM $BASE AS builder
6+
7+
ARG PG_MAJOR
8+
ARG EXT_VERSION
9+
10+
USER 0
11+
12+
RUN set -eux; \
13+
apt-get update; \
14+
apt-get install -y --no-install-recommends \
15+
postgresql-${PG_MAJOR}-pg-ivm=${EXT_VERSION}*
16+
17+
FROM scratch
18+
ARG PG_MAJOR
19+
20+
# Licenses
21+
COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-pg-ivm/copyright /licenses/pg_ivm/
22+
23+
# Libraries
24+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_ivm* /lib/
25+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/pg_ivm* /lib/bitcode/
26+
27+
# Share
28+
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_ivm* /share/extension/
29+
3530
USER 65532:65532

pg_ivm/README.md

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,87 @@
1-
# pg_ivm Extension
2-
3-
[pg_ivm](https://github.com/sraoss/pg_ivm) is an open-source extension
4-
that provides **Incremental View Maintenance (IVM)** for PostgreSQL, allowing
5-
materialized views to be updated incrementally when base tables change.
6-
7-
## Usage
8-
9-
### 1. Add the pg_ivm extension image to your Cluster
10-
11-
Define the `pg_ivm` extension under the `postgresql.extensions` section of
12-
your `Cluster` resource. For example:
13-
14-
```yaml
15-
apiVersion: postgresql.cnpg.io/v1
16-
kind: Cluster
17-
metadata:
18-
name: cluster-pg-ivm
19-
spec:
20-
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
21-
instances: 1
22-
23-
storage:
24-
size: 1Gi
25-
26-
postgresql:
27-
shared_preload_libraries:
28-
- "pg_ivm"
29-
postgresql:
30-
extensions:
31-
- name: pg_ivm
32-
image:
33-
reference: ghcr.io/cloudnative-pg/pg_ivm:1.13-18-trixie
34-
```
35-
36-
### 2. Enable the extension in a database
37-
38-
You can install `pg_ivm` in a specific database by creating or updating a
39-
`Database` resource. For example, to enable it in the `app` database:
40-
41-
```yaml
42-
apiVersion: postgresql.cnpg.io/v1
43-
kind: Database
44-
metadata:
45-
name: cluster-pg-ivm-app
46-
spec:
47-
name: app
48-
owner: app
49-
cluster:
50-
name: cluster-pg-ivm
51-
extensions:
52-
- name: pg_ivm
53-
```
54-
55-
### 3. Verify installation
56-
57-
Once the database is ready, connect to it with `psql` and run:
58-
59-
```sql
60-
\dx
61-
```
62-
63-
You should see `pg_ivm` listed among the installed extensions.
1+
# pg_ivm
2+
3+
[pg_ivm](https://github.com/sraoss/pg_ivm) is an open-source extension
4+
that provides **Incremental View Maintenance (IVM)** for PostgreSQL, allowing
5+
materialized views to be updated incrementally when base tables change.
6+
7+
## Usage
8+
9+
<!--
10+
Usage: add instructions on how to use the extension with CloudNativePG.
11+
Include code snippets for Cluster and Database resources as needed.
12+
-->
13+
14+
### 1. Add the pg_ivm extension image to your Cluster
15+
16+
Define the `pg_ivm` extension under the `postgresql.extensions` section of
17+
your `Cluster` resource. For example:
18+
19+
```yaml
20+
apiVersion: postgresql.cnpg.io/v1
21+
kind: Cluster
22+
metadata:
23+
name: cluster-pg_ivm
24+
spec:
25+
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
26+
instances: 1
27+
28+
storage:
29+
size: 1Gi
30+
31+
postgresql:
32+
extensions:
33+
- name: pg_ivm
34+
image:
35+
reference: ghcr.io/cloudnative-pg/pg_ivm:1.0-18-trixie
36+
```
37+
38+
### 2. Enable the extension in a database
39+
40+
You can install `pg_ivm` in a specific database by creating or updating a
41+
`Database` resource. For example, to enable it in the `app` database:
42+
43+
```yaml
44+
apiVersion: postgresql.cnpg.io/v1
45+
kind: Database
46+
metadata:
47+
name: cluster-pg_ivm-app
48+
spec:
49+
name: app
50+
owner: app
51+
cluster:
52+
name: cluster-pg_ivm
53+
extensions:
54+
- name: pg_ivm
55+
version: '1.13'
56+
```
57+
58+
### 3. Verify installation
59+
60+
Once the database is ready, connect to it with `psql` and run:
61+
62+
```sql
63+
\dx
64+
```
65+
66+
You should see `pg_ivm` listed among the installed extensions.
67+
68+
## Maintainers
69+
70+
This container image is maintained by @shuusan.
71+
72+
---
73+
74+
## Licenses and Copyright
75+
76+
This container image contains software that may be licensed under various
77+
open-source licenses.
78+
79+
All relevant license and copyright information for the `pg_ivm` extension
80+
and its dependencies are bundled within the image at:
81+
82+
```text
83+
/licenses/
84+
```
85+
86+
By using this image, you agree to comply with the terms of the licenses
87+
contained therein.

pg_ivm/metadata.hcl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
metadata = {
2-
name = "pg_ivm"
3-
sql_name = "pg_ivm"
4-
image_name = "pg_ivm"
5-
shared_preload_libraries = []
6-
extension_control_path = []
7-
dynamic_library_path = []
8-
ld_library_path = []
9-
10-
versions = {
11-
bookworm = {
12-
// pg_ivm version from GitHub releases
13-
"18" = "1.13"
14-
}
15-
trixie = {
16-
// pg_ivm version from GitHub releases
17-
"18" = "1.13"
18-
}
19-
}
20-
}
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 = "pg_ivm"
5+
sql_name = "pg_ivm"
6+
image_name = "pg_ivm"
7+
shared_preload_libraries = []
8+
extension_control_path = []
9+
dynamic_library_path = []
10+
ld_library_path = []
11+
auto_update_os_libs = false
12+
required_extensions = []
13+
create_extension = true
14+
15+
versions = {
16+
trixie = {
17+
// renovate: suite=trixie-pgdg depName=postgresql-18-pg-ivm
18+
"18" = "1.13-1.pgdg13+1"
19+
}
20+
bookworm = {
21+
// renovate: suite=bookworm-pgdg depName=postgresql-18-pg-ivm
22+
"18" = "1.13-1.pgdg12+1"
23+
}
24+
}
25+
}

pg_ivm/test/chainsaw-test.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: verify-pg-ivm-extension
5+
spec:
6+
timeouts:
7+
apply: 5s
8+
assert: 3m
9+
delete: 30s
10+
description: Verify pg_ivm extension is properly installed
11+
steps:
12+
- name: Create a Cluster with the extension
13+
try:
14+
- apply:
15+
file: cluster.yaml
16+
- apply:
17+
file: database.yaml
18+
- assert:
19+
file: cluster-assert.yaml
20+
- assert:
21+
file: database-assert.yaml
22+
23+
- name: Verify extension is installed
24+
try:
25+
- apply:
26+
file: check-extension.yaml
27+
- assert:
28+
file: check-extension-assert.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: extension-installed
5+
status:
6+
succeeded: 1

pg_ivm/test/check-extension.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: extension-installed
5+
spec:
6+
template:
7+
spec:
8+
restartPolicy: OnFailure
9+
containers:
10+
- name: data-test
11+
env:
12+
- name: EXT_VERSION
13+
value: ($values.version)
14+
- name: DB_URI
15+
valueFrom:
16+
secretKeyRef:
17+
name: (join('-', [$values.name, 'app']))
18+
key: uri
19+
image: alpine/psql:latest
20+
command: ['sh', '-c']
21+
args:
22+
- |
23+
set -e
24+
DB_URI=$(echo $DB_URI | sed "s|/\*|/|")
25+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'pg_ivm' AND extversion = '${EXT_VERSION}')" -q)" = "t"
26+
psql "$DB_URI" -c "CREATE TABLE base_table (id INT PRIMARY KEY, value TEXT);"
27+
psql "$DB_URI" -c "INSERT INTO base_table VALUES (1, 'test');"
28+
psql "$DB_URI" -c "CREATE INCREMENTAL MATERIALIZED VIEW test_ivm AS SELECT * FROM base_table;"
29+
test "$(psql "$DB_URI" -tAc "SELECT COUNT(*) FROM test_ivm" -q)" = "1"
30+
psql "$DB_URI" -c "INSERT INTO base_table VALUES (2, 'test2');"
31+
test "$(psql "$DB_URI" -tAc "SELECT COUNT(*) FROM test_ivm" -q)" = "2"

pg_ivm/test/cluster-assert.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: ($values.name)
5+
status:
6+
readyInstances: 1
7+
phase: Cluster in healthy state
8+
image: ($values.pg_image)

pg_ivm/test/cluster.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: ($values.name)
5+
spec:
6+
imageName: ($values.pg_image)
7+
instances: 1
8+
9+
storage:
10+
size: 1Gi
11+
12+
postgresql:
13+
shared_preload_libraries: ($values.shared_preload_libraries)
14+
extensions: ($values.extensions)

pg_ivm/test/database-assert.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Database
3+
metadata:
4+
name: (join('-', [$values.name, 'app']))
5+
status:
6+
applied: true
7+
extensions:
8+
- applied: true
9+
name: ($values.sql_name)
10+
observedGeneration: 1

0 commit comments

Comments
 (0)