11-- predictability
22SET 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;
47 ?column?
58----------
69 init
@@ -10,7 +13,19 @@ CREATE TABLE stats_test(data text);
1013-- non-spilled xact
1114SET logical_decoding_work_mem to '64MB';
1215INSERT 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');
1429 count
1530-------
1631 3
@@ -22,31 +37,65 @@ SELECT pg_stat_force_next_flush();
2237
2338(1 row)
2439
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)
3047
3148RESET 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 ');
3451 pg_stat_reset_replication_slot
3552--------------------------------
3653
3754(1 row)
3855
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 |
4392(1 row)
4493
4594-- spilling the xact
4695BEGIN;
4796INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
4897COMMIT;
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');
5099 count
51100-------
52101 5002
@@ -62,31 +111,39 @@ SELECT pg_stat_force_next_flush();
62111(1 row)
63112
64113SELECT 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)
69120
70121-- Ensure stats can be repeatedly accessed using the same stats snapshot. See
71122-- https://postgr.es/m/20210317230447.c7uc4g3vbs4wi32i%40alap3.anarazel.de
72123BEGIN;
73124SELECT 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)
78131
79132SELECT 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)
84139
85140COMMIT;
86141DROP 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+ | |
91148(1 row)
92149