1CREATE TABLE table3_with_pk (a SERIAL, b VARCHAR(30), c TIMESTAMP NOT NULL, PRIMARY KEY(a, c));
2CREATE TABLE table3_without_pk (a SERIAL, b NUMERIC(5,2), c TEXT);
3
4SELECT 'init' FROM pg_create_logical_replication_slot('test_slot', 'wal2json');
5
6BEGIN;
7INSERT INTO table3_with_pk (b, c) VALUES('Backup and Restore', '2019-12-29 04:58:34.806671');
8INSERT INTO table3_with_pk (b, c) VALUES('Tuning', '2019-12-29 04:58:34.806671');
9INSERT INTO table3_with_pk (b, c) VALUES('Replication', '2019-12-29 04:58:34.806671');
10\o /dev/null
11SELECT pg_logical_emit_message(true, 'wal2json', 'this message will be delivered');
12SELECT pg_logical_emit_message(true, 'pgoutput', 'this message will be filtered');
13DELETE FROM table3_with_pk WHERE a < 3;
14SELECT pg_logical_emit_message(false, 'wal2json', 'this non-transactional message will be delivered even if you rollback the transaction');
15\o
16
17INSERT INTO table3_without_pk (b, c) VALUES(2.34, 'Tapir');
18-- it is not added to stream because there isn't a pk or a replica identity
19UPDATE table3_without_pk SET c = 'Anta' WHERE c = 'Tapir';
20COMMIT;
21
22SELECT data FROM pg_logical_slot_get_changes('test_slot', NULL, NULL, 'format-version', '2', 'add-msg-prefixes', 'wal2json');
23SELECT 'stop' FROM pg_drop_replication_slot('test_slot');
24
25DROP TABLE table3_with_pk;
26DROP TABLE table3_without_pk;