1
1
-- predictability
2
2
SET synchronous_commit = on;
3
- SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot ', 'test_decoding');
3
+ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats ', 'test_decoding');
4
4
?column?
5
5
----------
6
6
init
23
23
ELSE (spill_txns > 0)
24
24
END
25
25
INTO updated
26
- FROM pg_stat_replication_slots WHERE slot_name='regression_slot ';
26
+ FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats ';
27
27
28
28
ELSE
29
29
32
32
ELSE (total_txns > 0)
33
33
END
34
34
INTO updated
35
- FROM pg_stat_replication_slots WHERE slot_name='regression_slot ';
35
+ FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats ';
36
36
37
37
END IF;
38
38
52
52
END
53
53
$$ LANGUAGE plpgsql;
54
54
-- non-spilled xact
55
+ SET logical_decoding_work_mem to '64MB';
55
56
INSERT INTO stats_test values(1);
56
- SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot ', NULL, NULL, 'skip-empty-xacts', '1');
57
+ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats ', NULL, NULL, 'skip-empty-xacts', '1');
57
58
count
58
59
-------
59
60
3
@@ -66,13 +67,14 @@ SELECT wait_for_decode_stats(false, false);
66
67
(1 row)
67
68
68
69
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;
69
- slot_name | spill_txns | spill_count | total_txns | total_bytes
70
- -----------------+------------+-------------+------------+-------------
71
- regression_slot | t | t | t | t
70
+ slot_name | spill_txns | spill_count | total_txns | total_bytes
71
+ ----------------------- +------------+-------------+------------+-------------
72
+ regression_slot_stats | t | t | t | t
72
73
(1 row)
73
74
75
+ RESET logical_decoding_work_mem;
74
76
-- reset the slot stats, and wait for stats collector's total txn to reset
75
- SELECT pg_stat_reset_replication_slot('regression_slot ');
77
+ SELECT pg_stat_reset_replication_slot('regression_slot_stats ');
76
78
pg_stat_reset_replication_slot
77
79
--------------------------------
78
80
@@ -85,16 +87,16 @@ SELECT wait_for_decode_stats(true, false);
85
87
(1 row)
86
88
87
89
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
88
- slot_name | spill_txns | spill_count | total_txns | total_bytes
89
- -----------------+------------+-------------+------------+-------------
90
- regression_slot | 0 | 0 | 0 | 0
90
+ slot_name | spill_txns | spill_count | total_txns | total_bytes
91
+ ----------------------- +------------+-------------+------------+-------------
92
+ regression_slot_stats | 0 | 0 | 0 | 0
91
93
(1 row)
92
94
93
95
-- spilling the xact
94
96
BEGIN;
95
97
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
96
98
COMMIT;
97
- SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot ', NULL, NULL, 'skip-empty-xacts', '1');
99
+ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats ', NULL, NULL, 'skip-empty-xacts', '1');
98
100
count
99
101
-------
100
102
5002
@@ -110,13 +112,13 @@ SELECT wait_for_decode_stats(false, true);
110
112
(1 row)
111
113
112
114
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;
113
- slot_name | spill_txns | spill_count | total_txns | total_bytes
114
- -----------------+------------+-------------+------------+-------------
115
- regression_slot | t | t | t | t
115
+ slot_name | spill_txns | spill_count | total_txns | total_bytes
116
+ ----------------------- +------------+-------------+------------+-------------
117
+ regression_slot_stats | t | t | t | t
116
118
(1 row)
117
119
118
120
-- reset the slot stats, and wait for stats collector to reset
119
- SELECT pg_stat_reset_replication_slot('regression_slot ');
121
+ SELECT pg_stat_reset_replication_slot('regression_slot_stats ');
120
122
pg_stat_reset_replication_slot
121
123
--------------------------------
122
124
@@ -129,13 +131,13 @@ SELECT wait_for_decode_stats(true, true);
129
131
(1 row)
130
132
131
133
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
132
- slot_name | spill_txns | spill_count | total_txns | total_bytes
133
- -----------------+------------+-------------+------------+-------------
134
- regression_slot | 0 | 0 | 0 | 0
134
+ slot_name | spill_txns | spill_count | total_txns | total_bytes
135
+ ----------------------- +------------+-------------+------------+-------------
136
+ regression_slot_stats | 0 | 0 | 0 | 0
135
137
(1 row)
136
138
137
139
-- decode and check stats again.
138
- SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot ', NULL, NULL, 'skip-empty-xacts', '1');
140
+ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats ', NULL, NULL, 'skip-empty-xacts', '1');
139
141
count
140
142
-------
141
143
5002
@@ -148,30 +150,30 @@ SELECT wait_for_decode_stats(false, true);
148
150
(1 row)
149
151
150
152
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;
151
- slot_name | spill_txns | spill_count | total_txns | total_bytes
152
- -----------------+------------+-------------+------------+-------------
153
- regression_slot | t | t | t | t
153
+ slot_name | spill_txns | spill_count | total_txns | total_bytes
154
+ ----------------------- +------------+-------------+------------+-------------
155
+ regression_slot_stats | t | t | t | t
154
156
(1 row)
155
157
156
158
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
157
159
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
158
160
BEGIN;
159
161
SELECT slot_name FROM pg_stat_replication_slots;
160
- slot_name
161
- -----------------
162
- regression_slot
162
+ slot_name
163
+ -----------------------
164
+ regression_slot_stats
163
165
(1 row)
164
166
165
167
SELECT slot_name FROM pg_stat_replication_slots;
166
- slot_name
167
- -----------------
168
- regression_slot
168
+ slot_name
169
+ -----------------------
170
+ regression_slot_stats
169
171
(1 row)
170
172
171
173
COMMIT;
172
174
DROP FUNCTION wait_for_decode_stats(bool, bool);
173
175
DROP TABLE stats_test;
174
- SELECT pg_drop_replication_slot('regression_slot ');
176
+ SELECT pg_drop_replication_slot('regression_slot_stats ');
175
177
pg_drop_replication_slot
176
178
--------------------------
177
179
0 commit comments