Skip to content

Commit e773cc8

Browse files
committed
feat: add migration from Crunchy operator
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
1 parent 0234d26 commit e773cc8

8 files changed

Lines changed: 517 additions & 0 deletions

File tree

173 KB
Loading

content/posts/20260513-crunchy-to-cloudnativepg-pg18/index.md

Lines changed: 354 additions & 0 deletions
Large diffs are not rendered by default.
74.8 KB
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: pg-app
5+
spec:
6+
instances: 1
7+
imageCatalogRef:
8+
apiGroup: postgresql.cnpg.io
9+
kind: ClusterImageCatalog
10+
name: postgresql-minimal-trixie
11+
major: 18
12+
storage:
13+
size: 5Gi
14+
postgresql:
15+
extensions:
16+
- name: pgaudit
17+
parameters:
18+
pgaudit.log: "all, -misc"
19+
pgaudit.log_catalog: "off"
20+
pgaudit.log_parameter: "on"
21+
pgaudit.log_relation: "on"
22+
bootstrap:
23+
initdb:
24+
import:
25+
type: microservice
26+
databases:
27+
- app
28+
source:
29+
externalCluster: crunchy
30+
externalClusters:
31+
- name: crunchy
32+
connectionParameters:
33+
host: crunchy-primary.default.svc
34+
port: "5432"
35+
user: cnpg
36+
dbname: app
37+
password:
38+
name: crunchy-pguser-cnpg
39+
key: password
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: pg-app
5+
spec:
6+
instances: 1
7+
imageCatalogRef:
8+
apiGroup: postgresql.cnpg.io
9+
kind: ClusterImageCatalog
10+
name: postgresql-minimal-trixie
11+
major: 18
12+
storage:
13+
size: 5Gi
14+
postgresql:
15+
extensions:
16+
- name: pgaudit
17+
parameters:
18+
pgaudit.log: "all, -misc"
19+
pgaudit.log_catalog: "off"
20+
pgaudit.log_parameter: "on"
21+
pgaudit.log_relation: "on"
22+
bootstrap:
23+
initdb:
24+
import:
25+
type: microservice
26+
schemaOnly: true
27+
databases:
28+
- app
29+
source:
30+
externalCluster: crunchy
31+
externalClusters:
32+
- name: crunchy
33+
connectionParameters:
34+
host: crunchy-primary.default.svc
35+
port: "5432"
36+
user: cnpg
37+
dbname: app
38+
password:
39+
name: crunchy-pguser-cnpg
40+
key: password
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: crunchy
5+
spec:
6+
postgresVersion: 17
7+
patroni:
8+
dynamicConfiguration:
9+
postgresql:
10+
parameters:
11+
wal_level: logical
12+
instances:
13+
- name: instance1
14+
replicas: 1
15+
dataVolumeClaimSpec:
16+
accessModes:
17+
- ReadWriteOnce
18+
resources:
19+
requests:
20+
storage: 5Gi
21+
backups:
22+
pgbackrest:
23+
repos:
24+
- name: repo1
25+
volume:
26+
volumeClaimSpec:
27+
accessModes:
28+
- ReadWriteOnce
29+
resources:
30+
requests:
31+
storage: 5Gi
32+
users:
33+
- name: app
34+
databases:
35+
- app
36+
- name: cnpg
37+
databases:
38+
- app
39+
options: "SUPERUSER"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: sample-data-init
5+
spec:
6+
template:
7+
spec:
8+
restartPolicy: Never
9+
containers:
10+
- name: psql
11+
image: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
12+
env:
13+
- name: PGPASSWORD
14+
valueFrom:
15+
secretKeyRef:
16+
name: crunchy-pguser-cnpg
17+
key: password
18+
command:
19+
- psql
20+
- -h
21+
- crunchy-primary.default.svc
22+
- -U
23+
- cnpg
24+
- app
25+
- -c
26+
- |
27+
CREATE TABLE orders (
28+
id SERIAL PRIMARY KEY,
29+
description TEXT NOT NULL,
30+
created_at TIMESTAMPTZ DEFAULT now()
31+
);
32+
INSERT INTO orders (description)
33+
SELECT 'Order ' || g FROM generate_series(1, 1000) AS g;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Subscription
3+
metadata:
4+
name: pg-app-migration
5+
spec:
6+
cluster:
7+
name: pg-app
8+
dbname: app
9+
name: migration
10+
externalClusterName: crunchy
11+
publicationName: migration
12+
subscriptionReclaimPolicy: delete

0 commit comments

Comments
 (0)