1.首先用该工具来看我们的日志变化,需要先将test_decoding插件编译并安装(进入contrib,编译安装即可)
创建一个slot:
SELECT * FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding’);
获取slot记录的变更日志:
postgres=# insert into test values(1, 'test', now());
INSERT 0 1
postgres=# insert into test values(1, 'test', now());
INSERT 0 1
只获取变化,不消费slot:
postgres=# SELECT * FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL);
lsn | xid | data
-----------+-----+-------------------------------------------------------------------------------------------------------------------------------
0/16637F8 | 572 | BEGIN 572
0/16637F8 | 572 | table public.test: INSERT: id[integer]:1 info[text]:'test' crt_time[timestamp without time zone]:'2019-05-27 11:52:08.147527'
0/1663B20 | 572 | COMMIT 572
0/1663B58 | 573 | BEGIN 573
0/1663B58 | 573 | table public.test: INSERT: id[integer]:1 info[text]:'test' crt_time[timestamp without time zone]:'2019-05-27 11:52:09.67556'
0/1663BD8 | 5