Debian Codegraph @

contrib/test_decoding/expected/stats.out

raw
1 -- predictability
2 SET synchronous_commit = on;
3 SELECT 'init' FROM
4 pg_create_logical_replication_slot('regression_slot_stats1', 'test_decoding') s1,
5 pg_create_logical_replication_slot('regression_slot_stats2', 'test_decoding') s2,
6 pg_create_logical_replication_slot('regression_slot_stats3', 'test_decoding') s3;
7 ?column?
8 ----------
9 init
10 (1 row)
11
12 CREATE TABLE stats_test(data text);
13 -- non-spilled xact
14 SET logical_decoding_work_mem to '64MB';
15 INSERT INTO stats_test values(1);
16 SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
17 count
18 -------
19 3
20 (1 row)
21
22 SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
23 count
24 -------
25 3
26 (1 row)
27
28 SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
29 count
30 -------
31 3
32 (1 row)
33
34 SELECT pg_stat_force_next_flush();
35 pg_stat_force_next_flush
36 --------------------------
37
38 (1 row)
39
40 SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
41 slot_name | spill_txns | spill_count | total_txns | total_bytes
42 ------------------------+------------+-------------+------------+-------------
43 regression_slot_stats1 | t | t | t | t
44 regression_slot_stats2 | t | t | t | t
45 regression_slot_stats3 | t | t | t | t
46 (3 rows)
47
48 RESET logical_decoding_work_mem;
49 -- reset stats for one slot, others should be unaffected
50 SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
51 pg_stat_reset_replication_slot
52 --------------------------------
53
54 (1 row)
55
56 SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
57 slot_name | spill_txns | spill_count | total_txns | total_bytes
58 ------------------------+------------+-------------+------------+-------------
59 regression_slot_stats1 | t | t | f | f
60 regression_slot_stats2 | t | t | t | t
61 regression_slot_stats3 | t | t | t | t
62 (3 rows)
63
64 -- reset stats for all slots
65 SELECT pg_stat_reset_replication_slot(NULL);
66 pg_stat_reset_replication_slot
67 --------------------------------
68
69 (1 row)
70
71 SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count, total_txns > 0 AS total_txns, total_bytes > 0 AS total_bytes FROM pg_stat_replication_slots ORDER BY slot_name;
72 slot_name | spill_txns | spill_count | total_txns | total_bytes
73 ------------------------+------------+-------------+------------+-------------
74 regression_slot_stats1 | t | t | f | f
75 regression_slot_stats2 | t | t | f | f
76 regression_slot_stats3 | t | t | f | f
77 (3 rows)
78
79 -- verify accessing/resetting stats for non-existent slot does something reasonable
80 SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
81 slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
82 --------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
83 do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
84 (1 row)
85
86 SELECT pg_stat_reset_replication_slot('do-not-exist');
87 ERROR: replication slot "do-not-exist" does not exist
88 SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
89 slot_name | spill_txns | spill_count | spill_bytes | stream_txns | stream_count | stream_bytes | total_txns | total_bytes | stats_reset
90 --------------+------------+-------------+-------------+-------------+--------------+--------------+------------+-------------+-------------
91 do-not-exist | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
92 (1 row)
93
94 -- spilling the xact
95 BEGIN;
96 INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
97 COMMIT;
98 SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
99 count
100 -------
101 5002
102 (1 row)
103
104 -- Check stats. We can't test the exact stats count as that can vary if any
105 -- background transaction (say by autovacuum) happens in parallel to the main
106 -- transaction.
107 SELECT pg_stat_force_next_flush();
108 pg_stat_force_next_flush
109 --------------------------
110
111 (1 row)
112
113 SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
114 slot_name | spill_txns | spill_count
115 ------------------------+------------+-------------
116 regression_slot_stats1 | t | t
117 regression_slot_stats2 | f | f
118 regression_slot_stats3 | f | f
119 (3 rows)
120
121 -- Ensure stats can be repeatedly accessed using the same stats snapshot. See
122 -- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
123 BEGIN;
124 SELECT slot_name FROM pg_stat_replication_slots;
125 slot_name
126 ------------------------
127 regression_slot_stats1
128 regression_slot_stats2
129 regression_slot_stats3
130 (3 rows)
131
132 SELECT slot_name FROM pg_stat_replication_slots;
133 slot_name
134 ------------------------
135 regression_slot_stats1
136 regression_slot_stats2
137 regression_slot_stats3
138 (3 rows)
139
140 COMMIT;
141 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats4_twophase', 'test_decoding', false, true) s4;
142 ?column?
143 ----------
144 init
145 (1 row)
146
147 -- The INSERT changes are large enough to be spilled but will not be, because
148 -- the transaction is aborted. The logical decoding skips collecting further
149 -- changes too. The transaction is prepared to make sure the decoding processes
150 -- the aborted transaction.
151 BEGIN;
152 INSERT INTO stats_test SELECT 'serialize-toobig--1:'||g.i FROM generate_series(1, 5000) g(i);
153 PREPARE TRANSACTION 'test1_abort';
154 ROLLBACK PREPARED 'test1_abort';
155 SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats4_twophase', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
156 count
157 -------
158 1
159 (1 row)
160
161 -- Verify that the decoding doesn't spill already-aborted transaction's changes.
162 SELECT pg_stat_force_next_flush();
163 pg_stat_force_next_flush
164 --------------------------
165
166 (1 row)
167
168 SELECT slot_name, spill_txns, spill_count FROM pg_stat_replication_slots WHERE slot_name = 'regression_slot_stats4_twophase';
169 slot_name | spill_txns | spill_count
170 ---------------------------------+------------+-------------
171 regression_slot_stats4_twophase | 0 | 0
172 (1 row)
173
174 DROP TABLE stats_test;
175 SELECT pg_drop_replication_slot('regression_slot_stats1'),
176 pg_drop_replication_slot('regression_slot_stats2'),
177 pg_drop_replication_slot('regression_slot_stats3'),
178 pg_drop_replication_slot('regression_slot_stats4_twophase');
179 pg_drop_replication_slot | pg_drop_replication_slot | pg_drop_replication_slot | pg_drop_replication_slot
180 --------------------------+--------------------------+--------------------------+--------------------------
181 | | |
182 (1 row)
183