Debian Codegraph @

contrib/test_decoding/expected/decoding_in_xact.out

raw
1 -- predictability
2 SET synchronous_commit = on;
3 -- fail because we're creating a slot while in an xact with xid
4 BEGIN;
5 SELECT pg_current_xact_id() = '0';
6 ?column?
7 ----------
8 f
9 (1 row)
10
11 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
12 ERROR: cannot create logical replication slot in transaction that has performed writes
13 ROLLBACK;
14 -- fail because we're creating a slot while in a subxact whose topxact has an xid
15 BEGIN;
16 SELECT pg_current_xact_id() = '0';
17 ?column?
18 ----------
19 f
20 (1 row)
21
22 SAVEPOINT barf;
23 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
24 ERROR: cannot create logical replication slot in transaction that has performed writes
25 ROLLBACK TO SAVEPOINT barf;
26 ROLLBACK;
27 -- succeed, outside tx.
28 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
29 ?column?
30 ----------
31 init
32 (1 row)
33
34 SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
35 ?column?
36 ----------
37 stop
38 (1 row)
39
40 -- succeed, in tx without xid.
41 BEGIN;
42 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
43 ?column?
44 ----------
45 init
46 (1 row)
47
48 COMMIT;
49 CREATE TABLE nobarf(id serial primary key, data text);
50 INSERT INTO nobarf(data) VALUES('1');
51 -- decoding works in transaction with xid
52 BEGIN;
53 SELECT pg_current_xact_id() = '0';
54 ?column?
55 ----------
56 f
57 (1 row)
58
59 -- don't show yet, haven't committed
60 INSERT INTO nobarf(data) VALUES('2');
61 SELECT 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
69 COMMIT;
70 INSERT INTO nobarf(data) VALUES('3');
71 SELECT 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
82 -- Decoding works in transaction that issues DDL
83 --
84 -- We had issues handling relcache invalidations with these, see
85 -- https://www.postgresql.org/message-id/[email protected]
86 CREATE TABLE tbl_created_outside_xact(id SERIAL PRIMARY KEY);
87 BEGIN;
88 -- TRUNCATE changes the relfilenode and sends relcache invalidation
89 TRUNCATE tbl_created_outside_xact;
90 INSERT INTO tbl_created_outside_xact(id) VALUES('1');
91 -- don't show yet, haven't committed
92 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
93 data
94 ------
95 (0 rows)
96
97 COMMIT;
98 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
99 data
100 --------------------------------------------------------------
101 BEGIN
102 table public.tbl_created_outside_xact: TRUNCATE: (no-flags)
103 table public.tbl_created_outside_xact: INSERT: id[integer]:1
104 COMMIT
105 (4 rows)
106
107 SET debug_logical_replication_streaming = immediate;
108 BEGIN;
109 CREATE TABLE tbl_created_in_xact(id SERIAL PRIMARY KEY);
110 INSERT INTO tbl_created_in_xact VALUES (1);
111 CHECKPOINT; -- Force WAL flush, so that the above changes will be streamed
112 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
113 data
114 ------------------------------------------
115 opening a streamed block for transaction
116 streaming change for transaction
117 closing a streamed block for transaction
118 (3 rows)
119
120 COMMIT;
121 RESET debug_logical_replication_streaming;
122 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
123 data
124 ---------------------------------------------------------
125 BEGIN
126 table public.tbl_created_in_xact: INSERT: id[integer]:1
127 COMMIT
128 (3 rows)
129
130 SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
131 ?column?
132 ----------
133 stop
134 (1 row)
135