Skip to content

Commit 6517481

Browse files
committed
feat: add wal2json extension
Signed-off-by: Alper Kanat <me@alperkan.at>
1 parent 69ec927 commit 6517481

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

wal2json/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 apt-get update && \
10+
apt-get install -y --no-install-recommends "postgresql-${PG_MAJOR}-wal2json=${EXT_VERSION}"
11+
12+
FROM scratch
13+
ARG PG_MAJOR
14+
15+
# Licenses
16+
COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-wal2json/copyright /licenses/postgresql-${PG_MAJOR}-wal2json/
17+
18+
# Libraries
19+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/wal2json* /lib/
20+
21+
USER 65532:65532

wal2json/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# wal2json
2+
3+
[wal2json](https://github.com/eulerto/wal2json) is an open-source logical decoding
4+
output plugin for PostgreSQL that converts WAL (Write-Ahead Log) changes to JSON format.
5+
6+
This image provides a convenient way to deploy and manage `wal2json` with
7+
[CloudNativePG](https://cloudnative-pg.io/).
8+
9+
## Usage
10+
11+
### 1. Add the wal2json plugin image to your Cluster
12+
13+
Define the `wal2json` plugin under the `postgresql.extensions` section of
14+
your `Cluster` resource. For example:
15+
16+
```yaml
17+
apiVersion: postgresql.cnpg.io/v1
18+
kind: Cluster
19+
metadata:
20+
name: cluster-wal2json
21+
spec:
22+
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
23+
instances: 1
24+
25+
storage:
26+
size: 1Gi
27+
28+
postgresql:
29+
parameters:
30+
wal_level: logical
31+
32+
extensions:
33+
- name: wal2json
34+
image:
35+
# renovate: suite=trixie-pgdg depName=postgresql-18-wal2json
36+
reference: ghcr.io/cloudnative-pg/wal2json:2.6-18-trixie
37+
```
38+
39+
### 2. Configure logical replication
40+
41+
To use `wal2json`, you need to:
42+
43+
1. Set `wal_level` to `logical` in your PostgreSQL configuration (as shown above)
44+
2. Create a logical replication slot using the `wal2json` output plugin
45+
46+
Connect to your database and create a replication slot:
47+
48+
```sql
49+
SELECT * FROM pg_create_logical_replication_slot('wal2json_slot', 'wal2json');
50+
```
51+
52+
### 3. Use the replication slot
53+
54+
You can now use the replication slot to stream changes in JSON format. For example,
55+
using `pg_recvlogical`:
56+
57+
```bash
58+
pg_recvlogical -d your_database -h your_host -U your_user \
59+
--slot wal2json_slot --start -f -
60+
```
61+
62+
### 4. Verify installation
63+
64+
To verify that `wal2json` is available, you can check the available output plugins:
65+
66+
```sql
67+
SELECT * FROM pg_available_logical_replication_slots;
68+
```
69+
70+
Or check if the library is loaded:
71+
72+
```sql
73+
SELECT * FROM pg_show_replication_slots();
74+
```

wal2json/metadata.hcl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
metadata = {
2+
name = "wal2json"
3+
sql_name = "wal2json"
4+
image_name = "wal2json"
5+
shared_preload_libraries = []
6+
extension_control_path = []
7+
dynamic_library_path = []
8+
ld_library_path = []
9+
auto_update_os_libs = false
10+
11+
versions = {
12+
bookworm = {
13+
// renovate: suite=bookworm-pgdg depName=postgresql-18-wal2json
14+
"18" = "2.6-3.pgdg12+1"
15+
}
16+
trixie = {
17+
// renovate: suite=trixie-pgdg depName=postgresql-18-wal2json
18+
"18" = "2.6-3.pgdg13+1"
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)