@@ -7,50 +7,6 @@ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', '
7
7
(1 row)
8
8
9
9
CREATE TABLE stats_test(data text);
10
- -- function to wait for counters to advance
11
- CREATE FUNCTION wait_for_decode_stats(check_reset bool, check_spill_txns bool) RETURNS void AS $$
12
- DECLARE
13
- start_time timestamptz := clock_timestamp();
14
- updated bool;
15
- BEGIN
16
- -- we don't want to wait forever; loop will exit after 30 seconds
17
- FOR i IN 1 .. 300 LOOP
18
-
19
- IF check_spill_txns THEN
20
-
21
- -- check to see if all updates have been reset/updated
22
- SELECT CASE WHEN check_reset THEN (spill_txns = 0)
23
- ELSE (spill_txns > 0)
24
- END
25
- INTO updated
26
- FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
27
-
28
- ELSE
29
-
30
- -- check to see if all updates have been reset/updated
31
- SELECT CASE WHEN check_reset THEN (total_txns = 0)
32
- ELSE (total_txns > 0)
33
- END
34
- INTO updated
35
- FROM pg_stat_replication_slots WHERE slot_name='regression_slot_stats';
36
-
37
- END IF;
38
-
39
- exit WHEN updated;
40
-
41
- -- wait a little
42
- perform pg_sleep_for('100 milliseconds');
43
-
44
- -- reset stats snapshot so we can test again
45
- perform pg_stat_clear_snapshot();
46
-
47
- END LOOP;
48
-
49
- -- report time waited in postmaster log (where it won't change test output)
50
- RAISE LOG 'wait_for_decode_stats delayed % seconds',
51
- extract(epoch from clock_timestamp() - start_time);
52
- END
53
- $$ LANGUAGE plpgsql;
54
10
-- non-spilled xact
55
11
SET logical_decoding_work_mem to '64MB';
56
12
INSERT INTO stats_test values(1);
@@ -60,9 +16,9 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL,
60
16
3
61
17
(1 row)
62
18
63
- SELECT wait_for_decode_stats(false, false );
64
- wait_for_decode_stats
65
- -----------------------
19
+ SELECT pg_stat_force_next_flush( );
20
+ pg_stat_force_next_flush
21
+ --------------------------
66
22
67
23
(1 row)
68
24
@@ -73,19 +29,13 @@ SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count,
73
29
(1 row)
74
30
75
31
RESET logical_decoding_work_mem;
76
- -- reset the slot stats, and wait for stats collector's total txn to reset
32
+ -- reset the slot stats
77
33
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
78
34
pg_stat_reset_replication_slot
79
35
--------------------------------
80
36
81
37
(1 row)
82
38
83
- SELECT wait_for_decode_stats(true, false);
84
- wait_for_decode_stats
85
- -----------------------
86
-
87
- (1 row)
88
-
89
39
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
90
40
slot_name | spill_txns | spill_count | total_txns | total_bytes
91
41
-----------------------+------------+-------------+------------+-------------
@@ -102,12 +52,12 @@ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL,
102
52
5002
103
53
(1 row)
104
54
105
- -- Check stats, wait for the stats collector to update. We can't test the
106
- -- exact stats count as that can vary if any background transaction (say by
107
- -- autovacuum) happens in parallel to the main transaction.
108
- SELECT wait_for_decode_stats(false, true );
109
- wait_for_decode_stats
110
- -----------------------
55
+ -- Check stats. We can't test the exact stats count as that can vary if any
56
+ -- background transaction (say by autovacuum) happens in parallel to the main
57
+ -- transaction.
58
+ SELECT pg_stat_force_next_flush( );
59
+ pg_stat_force_next_flush
60
+ --------------------------
111
61
112
62
(1 row)
113
63
@@ -133,7 +83,6 @@ SELECT slot_name FROM pg_stat_replication_slots;
133
83
(1 row)
134
84
135
85
COMMIT;
136
- DROP FUNCTION wait_for_decode_stats(bool, bool);
137
86
DROP TABLE stats_test;
138
87
SELECT pg_drop_replication_slot('regression_slot_stats');
139
88
pg_drop_replication_slot
0 commit comments