1
1
-- predictability
2
2
SET synchronous_commit = on;
3
- SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
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;
4
7
?column?
5
8
----------
6
9
init
@@ -10,7 +13,19 @@ CREATE TABLE stats_test(data text);
10
13
-- non-spilled xact
11
14
SET logical_decoding_work_mem to '64MB';
12
15
INSERT INTO stats_test values(1);
13
- SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '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');
14
29
count
15
30
-------
16
31
3
@@ -22,31 +37,65 @@ SELECT pg_stat_force_next_flush();
22
37
23
38
(1 row)
24
39
25
- 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;
26
- slot_name | spill_txns | spill_count | total_txns | total_bytes
27
- -----------------------+------------+-------------+------------+-------------
28
- regression_slot_stats | t | t | t | t
29
- (1 row)
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)
30
47
31
48
RESET logical_decoding_work_mem;
32
- -- resetthe slot stats
33
- SELECT pg_stat_reset_replication_slot('regression_slot_stats ');
49
+ -- resetstats for one slot, others should be unaffected
50
+ SELECT pg_stat_reset_replication_slot('regression_slot_stats1 ');
34
51
pg_stat_reset_replication_slot
35
52
--------------------------------
36
53
37
54
(1 row)
38
55
39
- SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
40
- slot_name | spill_txns | spill_count | total_txns | total_bytes
41
- -----------------------+------------+-------------+------------+-------------
42
- regression_slot_stats | 0 | 0 | 0 | 0
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 |
43
92
(1 row)
44
93
45
94
-- spilling the xact
46
95
BEGIN;
47
96
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
48
97
COMMIT;
49
- SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats ', NULL, NULL, 'skip-empty-xacts', '1');
98
+ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats1 ', NULL, NULL, 'skip-empty-xacts', '1');
50
99
count
51
100
-------
52
101
5002
@@ -62,31 +111,39 @@ SELECT pg_stat_force_next_flush();
62
111
(1 row)
63
112
64
113
SELECT slot_name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
65
- slot_name | spill_txns | spill_count
66
- -----------------------+------------+-------------
67
- regression_slot_stats | t | t
68
- (1 row)
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)
69
120
70
121
-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
71
122
-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
72
123
BEGIN;
73
124
SELECT slot_name FROM pg_stat_replication_slots;
74
- slot_name
75
- -----------------------
76
- regression_slot_stats
77
- (1 row)
125
+ slot_name
126
+ ------------------------
127
+ regression_slot_stats1
128
+ regression_slot_stats2
129
+ regression_slot_stats3
130
+ (3 rows)
78
131
79
132
SELECT slot_name FROM pg_stat_replication_slots;
80
- slot_name
81
- -----------------------
82
- regression_slot_stats
83
- (1 row)
133
+ slot_name
134
+ ------------------------
135
+ regression_slot_stats1
136
+ regression_slot_stats2
137
+ regression_slot_stats3
138
+ (3 rows)
84
139
85
140
COMMIT;
86
141
DROP TABLE stats_test;
87
- SELECT pg_drop_replication_slot('regression_slot_stats');
88
- pg_drop_replication_slot
89
- --------------------------
90
-
142
+ SELECT pg_drop_replication_slot('regression_slot_stats1'),
143
+ pg_drop_replication_slot('regression_slot_stats2'),
144
+ pg_drop_replication_slot('regression_slot_stats3');
145
+ pg_drop_replication_slot | pg_drop_replication_slot | pg_drop_replication_slot
146
+ --------------------------+--------------------------+--------------------------
147
+ | |
91
148
(1 row)
92
149