基于官方的release 构建了一个docker 镜像,以下是测试使用
version: "3"services: mypg: image: dalongrong/wal2json:1.0 ports: - "5432:5432" environment: - "POSTGRES_PASSWORD:dalong"docker-compose up -dpg_recvlogical -h 127.0.0.1 -U postgres -d postgres --slot test_slot --create-slot -P wal2jsonpg_recvlogical -h 127.0.0.1 -U postgres -d postgres --slot test_slot --start -o pretty-print=1 -f -CREATE TABLE table_with_pk (a SERIAL, b VARCHAR(30), c TIMESTAMP NOT NULL, PRIMARY KEY(a, c));CREATE TABLE table_without_pk (a SERIAL, b NUMERIC(5,2), c TEXT);?BEGIN;INSERT INTO table_with_pk (b, c) VALUES(‘Backup and Restore‘, now());INSERT INTO table_with_pk (b, c) VALUES(‘Tuning‘, now());INSERT INTO table_with_pk (b, c) VALUES(‘Replication‘, now());DELETE FROM table_with_pk WHERE a < 3;?INSERT INTO table_without_pk (b, c) VALUES(2.34, ‘Tapir‘);-- it is not added to stream because there isn‘t a pk or a replica identityUPDATE table_without_pk SET c = ‘Anta‘ WHERE c = ‘Tapir‘;COMMIT;
添加数据
psql -At -f example1.sql -h 127.0.0.1 -U postgres -d postgres
wal2json 功能强大,同时提供的配置参数也是比较多的,netflix即将开源的dblog 对于pg 的处理也是基于此扩展,详细的一些使用
可以参考github 仓库代码
https://github.com/eulerto/wal2json
https://github.com/rongfengliang/wal2json-docker
https://github.com/rongfengliang/wal2json-docker-demo