my $connect_db = 'postgres';
my $db_under_test = 'test';
+my $sect = "startup";
+
+# Check some WAL statistics after a fresh startup. The startup process
+# should have done WAL reads, and initialization some WAL writes.
+my $standalone_io_stats = io_stats('init', 'wal', 'standalone backend');
+my $startup_io_stats = io_stats('normal', 'wal', 'startup');
+cmp_ok(
+ '0', '<',
+ $standalone_io_stats->{writes},
+ "$sect: increased standalone backend IO writes");
+cmp_ok(
+ '0', '<',
+ $startup_io_stats->{reads},
+ "$sect: increased startup IO reads");
+
# create test objects
$node->safe_psql($connect_db, "CREATE DATABASE $db_under_test");
$node->safe_psql($db_under_test,
trigger_funcrel_stat();
# verify stats objects exist
-my $sect = "initial";
+$sect = "initial";
is(have_stats('database', $dboid, 0), 't', "$sect: db stats do exist");
is(have_stats('function', $dboid, $funcoid),
't', "$sect: function stats do exist");
return \%results;
}
+
+sub io_stats
+{
+ my ($context, $object, $backend_type) = @_;
+ my %results;
+
+ $results{writes} = $node->safe_psql(
+ $connect_db, qq{SELECT writes FROM pg_stat_io
+ WHERE context = '$context' AND object = '$object' AND
+ backend_type = '$backend_type'});
+ $results{reads} = $node->safe_psql(
+ $connect_db, qq{SELECT reads FROM pg_stat_io
+ WHERE context = '$context' AND object = '$object' AND
+ backend_type = '$backend_type'});
+
+ return \%results;
+}
t
(1 row)
--- Test pg_stat_io for WAL in an init context, that should do writes
--- and syncs.
-SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
- FROM pg_stat_io
- WHERE context = 'init' AND object = 'wal' \gset io_sum_wal_init_
-SELECT :io_sum_wal_init_writes > 0;
- ?column?
-----------
- t
-(1 row)
-
-SELECT current_setting('fsync') = 'off'
- OR :io_sum_wal_init_fsyncs > 0;
- ?column?
-----------
- t
-(1 row)
-
--- Test pg_stat_io for WAL in a normal context, that should do reads as well.
-SELECT SUM(reads) > 0
- FROM pg_stat_io
- WHERE context = 'normal' AND object = 'wal';
- ?column?
-----------
- t
-(1 row)
-
-----
-- Test that resetting stats works for reset timestamp
-----
FROM pg_stat_get_backend_idset() beid
WHERE pg_stat_get_backend_pid(beid) = pg_backend_pid();
--- Test pg_stat_io for WAL in an init context, that should do writes
--- and syncs.
-SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
- FROM pg_stat_io
- WHERE context = 'init' AND object = 'wal' \gset io_sum_wal_init_
-SELECT :io_sum_wal_init_writes > 0;
-SELECT current_setting('fsync') = 'off'
- OR :io_sum_wal_init_fsyncs > 0;
-
--- Test pg_stat_io for WAL in a normal context, that should do reads as well.
-SELECT SUM(reads) > 0
- FROM pg_stat_io
- WHERE context = 'normal' AND object = 'wal';
-
-----
-- Test that resetting stats works for reset timestamp
-----