1-- predictability 2SET synchronous_commit = on; 3-- fail because we're creating a slot while in an xact with xid 4BEGIN; 5SELECT txid_current() = 0; 6 ?column? 7---------- 8 f 9(1 row) 10 11SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); 12ERROR: cannot create logical replication slot in transaction that has performed writes 13ROLLBACK; 14-- fail because we're creating a slot while in a subxact whose topxact has an xid 15BEGIN; 16SELECT txid_current() = 0; 17 ?column? 18---------- 19 f 20(1 row) 21 22SAVEPOINT barf; 23SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); 24ERROR: cannot create logical replication slot in transaction that has performed writes 25ROLLBACK TO SAVEPOINT barf; 26ROLLBACK; 27-- succeed, outside tx. 28SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); 29 ?column? 30---------- 31 init 32(1 row) 33 34SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); 35 ?column? 36---------- 37 stop 38(1 row) 39 40-- succeed, in tx without xid. 41BEGIN; 42SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); 43 ?column? 44---------- 45 init 46(1 row) 47 48COMMIT; 49CREATE TABLE nobarf(id serial primary key, data text); 50INSERT INTO nobarf(data) VALUES('1'); 51-- decoding works in transaction with xid 52BEGIN; 53SELECT txid_current() = 0; 54 ?column? 55---------- 56 f 57(1 row) 58 59-- don't show yet, haven't committed 60INSERT INTO nobarf(data) VALUES('2'); 61SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); 62 data 63----------------------------------------------------------- 64 BEGIN 65 table public.nobarf: INSERT: id[integer]:1 data[text]:'1' 66 COMMIT 67(3 rows) 68 69COMMIT; 70INSERT INTO nobarf(data) VALUES('3'); 71SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); 72 data 73----------------------------------------------------------- 74 BEGIN 75 table public.nobarf: INSERT: id[integer]:2 data[text]:'2' 76 COMMIT 77 BEGIN 78 table public.nobarf: INSERT: id[integer]:3 data[text]:'3' 79 COMMIT 80(6 rows) 81 82SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); 83 ?column? 84---------- 85 stop 86(1 row) 87 88