|
| 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 | +``` |
0 commit comments