1-- predictability
2SET synchronous_commit = on;
3SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
4 ?column?
5----------
6 init
7(1 row)
8
9CREATE TABLE xact_test(data text);
10INSERT INTO xact_test VALUES ('before-test');
11-- bug #13844, xids in non-decoded records need to be inspected
12BEGIN;
13-- perform operation in xact that creates and logs xid, but isn't decoded
14SELECT * FROM xact_test FOR UPDATE;
15    data
16-------------
17 before-test
18(1 row)
19
20SAVEPOINT foo;
21-- and now actually insert in subxact, xid is expected to be known
22INSERT INTO xact_test VALUES ('after-assignment');
23COMMIT;
24-- and now show those changes
25SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
26                             data
27---------------------------------------------------------------
28 BEGIN
29 table public.xact_test: INSERT: data[text]:'before-test'
30 COMMIT
31 BEGIN
32 table public.xact_test: INSERT: data[text]:'after-assignment'
33 COMMIT
34(6 rows)
35
36-- bug #14279, do not propagate null snapshot from subtransaction
37BEGIN;
38-- first insert
39INSERT INTO xact_test VALUES ('main-txn');
40SAVEPOINT foo;
41-- now perform operation in subxact that creates and logs xid, but isn't decoded
42SELECT 1 FROM xact_test FOR UPDATE LIMIT 1;
43 ?column?
44----------
45        1
46(1 row)
47
48COMMIT;
49-- and now show those changes
50SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
51                         data
52-------------------------------------------------------
53 BEGIN
54 table public.xact_test: INSERT: data[text]:'main-txn'
55 COMMIT
56(3 rows)
57
58DROP TABLE xact_test;
59SELECT pg_drop_replication_slot('regression_slot');
60 pg_drop_replication_slot
61--------------------------
62
63(1 row)
64
65