@@ -7,50 +7,6 @@ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', '
77(1 row)
88
99CREATE 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;
5410-- non-spilled xact
5511SET logical_decoding_work_mem to '64MB';
5612INSERT INTO stats_test values(1);
@@ -60,9 +16,9 @@ SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL,
6016 3
6117(1 row)
6218
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+ --------------------------
6622
6723(1 row)
6824
@@ -73,19 +29,13 @@ SELECT slot_name, spill_txns = 0 AS spill_txns, spill_count = 0 AS spill_count,
7329(1 row)
7430
7531RESET logical_decoding_work_mem;
76- -- reset the slot stats, and wait for stats collector's total txn to reset
32+ -- reset the slot stats
7733SELECT pg_stat_reset_replication_slot('regression_slot_stats');
7834 pg_stat_reset_replication_slot
7935--------------------------------
8036
8137(1 row)
8238
83- SELECT wait_for_decode_stats(true, false);
84- wait_for_decode_stats
85- -----------------------
86-
87- (1 row)
88-
8939SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
9040 slot_name | spill_txns | spill_count | total_txns | total_bytes
9141-----------------------+------------+-------------+------------+-------------
@@ -102,12 +52,12 @@ SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL,
10252 5002
10353(1 row)
10454
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+ --------------------------
11161
11262(1 row)
11363
@@ -133,7 +83,6 @@ SELECT slot_name FROM pg_stat_replication_slots;
13383(1 row)
13484
13585COMMIT;
136- DROP FUNCTION wait_for_decode_stats(bool, bool);
13786DROP TABLE stats_test;
13887SELECT pg_drop_replication_slot('regression_slot_stats');
13988 pg_drop_replication_slot
0 commit comments