mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
pgstat: add/extend tests for resetting various kinds of stats.
- subscriber stats reset path was untested - slot stat sreset path for all slots was untested - pg_stat_database.sessions etc was untested - pg_stat_reset_shared() was untested, for any kind of shared stats - pg_stat_reset() was untested Author: Melanie Plageman <melanieplageman@gmail.com> Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
This commit is contained in:
@ -1,27 +1,41 @@
|
||||
-- predictability
|
||||
SET synchronous_commit = on;
|
||||
|
||||
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_stats', 'test_decoding');
|
||||
SELECT 'init' FROM
|
||||
pg_create_logical_replication_slot('regression_slot_stats1', 'test_decoding') s1,
|
||||
pg_create_logical_replication_slot('regression_slot_stats2', 'test_decoding') s2,
|
||||
pg_create_logical_replication_slot('regression_slot_stats3', 'test_decoding') s3;
|
||||
|
||||
CREATE TABLE stats_test(data text);
|
||||
|
||||
-- non-spilled xact
|
||||
SET logical_decoding_work_mem to '64MB';
|
||||
INSERT INTO stats_test values(1);
|
||||
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats2', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot_stats3', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
SELECT pg_stat_force_next_flush();
|
||||
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;
|
||||
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;
|
||||
RESET logical_decoding_work_mem;
|
||||
|
||||
-- reset the slot stats
|
||||
SELECT pg_stat_reset_replication_slot('regression_slot_stats');
|
||||
SELECT slot_name, spill_txns, spill_count, total_txns, total_bytes FROM pg_stat_replication_slots;
|
||||
-- reset stats for one slot, others should be unaffected
|
||||
SELECT pg_stat_reset_replication_slot('regression_slot_stats1');
|
||||
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;
|
||||
|
||||
-- reset stats for all slots
|
||||
SELECT pg_stat_reset_replication_slot(NULL);
|
||||
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;
|
||||
|
||||
-- verify accessing/resetting stats for non-existent slot does something reasonable
|
||||
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
|
||||
SELECT pg_stat_reset_replication_slot('do-not-exist');
|
||||
SELECT * FROM pg_stat_get_replication_slot('do-not-exist');
|
||||
|
||||
-- spilling the xact
|
||||
BEGIN;
|
||||
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
|
||||
COMMIT;
|
||||
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot_stats1', NULL, NULL, 'skip-empty-xacts', '1');
|
||||
|
||||
-- Check stats. We can't test the exact stats count as that can vary if any
|
||||
-- background transaction (say by autovacuum) happens in parallel to the main
|
||||
@ -37,4 +51,6 @@ SELECT slot_name FROM pg_stat_replication_slots;
|
||||
COMMIT;
|
||||
|
||||
DROP TABLE stats_test;
|
||||
SELECT pg_drop_replication_slot('regression_slot_stats');
|
||||
SELECT pg_drop_replication_slot('regression_slot_stats1'),
|
||||
pg_drop_replication_slot('regression_slot_stats2'),
|
||||
pg_drop_replication_slot('regression_slot_stats3');
|
||||
|
Reference in New Issue
Block a user