wal2json docker 试用
基于官方的release 构建了一个docker 镜像,以下是测试使用
环境准备
- docker-compose 文件
version: "3"
services:
mypg:
image: dalongrong/wal2json:1.0
ports:
- "5432:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
- 启动
docker-compose up -d
测试
- 创建slot 以及使用插件
pg_recvlogical -h 127.0.0.1 -U postgres -d postgres --slot test_slot --create-slot -P wal2json
- 监听变动
pg_recvlogical -h 127.0.0.1 -U postgres -d postgres --slot test_slot --start -o pretty-print=1 -f -
- 添加数据查看变动
demo sql
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 identity
UPDATE 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 仓库代码