At Mon, 15 Mar 2021 17:51:31 +0900 (JST), Kyotaro Horiguchi <horikyota....@gmail.com> wrote in > At Fri, 12 Mar 2021 22:20:40 -0800, Andres Freund <and...@anarazel.de> wrote > in > > Horiguchi-san, is there a chance you could add a few tests (on master) > > that test/document the way stats are kept across "normal" restarts, and > > thrown away after crash restarts/immediate restarts and also thrown away > > graceful streaming rep shutdowns? > > Roger. I'll give it a try.
Sorry, I forgot this. This is it. retards. -- Kyotaro Horiguchi NTT Open Source Software Center
# Verify stats data persistence use strict; use warnings; use PostgresNode; use TestLib; use Test::More tests => 6; my $backup_name = 'my_backup'; # Initialize a test cluster my $node_primary = get_new_node('primary'); $node_primary->init(allows_streaming => 1); $node_primary->start; $node_primary->safe_psql('postgres', 'CREATE TABLE t(); SELECT * from t;'); my $count = $node_primary->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '1', "counter is incremented"); # Stas numbers are restored after graceful restart $node_primary->restart; $count = $node_primary->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '1', "counter is correctly restored"); # Stas numbers are blown away after a crash $node_primary->stop('immediate'); $node_primary->start; $count = $node_primary->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '0', "counter is reset after crash"); # Create a standby $node_primary->backup($backup_name); my $node_standby = get_new_node('standby'); $node_standby->init_from_backup($node_primary, $backup_name, has_streaming => 1); $node_standby->start; # Stats numbers are initialized to zero $count = $node_standby->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '0', "counter is initialized"); # Stats numbers are incremented also on standby $node_standby->safe_psql('postgres', 'SELECT * from t;'); $count = $node_standby->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '1', "counter is incremented on standby"); # Stas numbers are always blown away even after graceful restart on standby $node_primary->restart; $count = $node_primary->safe_psql('postgres', 'SELECT seq_scan FROM pg_stat_user_tables'); is($count, '0', "counter is reset after restart on standby");