mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Add data for WAL in pg_stat_io and backend statistics
This commit adds WAL IO stats to both pg_stat_io view and per-backend IO
statistics (pg_stat_get_backend_io()). This change is possible since
f92c854cf4, as WAL IO is not counted in blocks in some code paths
where its stats data is measured (like WAL read in xlogreader.c).
IOContext gains IOCONTEXT_INIT and IOObject IOOBJECT_WAL, with the
following combinations allowed:
- IOOBJECT_WAL/IOCONTEXT_NORMAL is used to track I/O operations done on
already-created WAL segments.
- IOOBJECT_WAL/IOCONTEXT_INIT is used for tracking I/O operations done
when initializing WAL segments.
The core changes are done in pg_stat_io.c, backend statistics inherit
them. Backend statistics and pg_stat_io are now available for the WAL
writer, the WAL receiver and the WAL summarizer processes.
I/O timing data is controlled by the GUC track_io_timing, like the
existing data of pg_stat_io for consistency. The timings related to
IOOBJECT_WAL show up if the GUC is enabled (disabled by default).
Bump pgstats file version, due to the additions in IOObject and
IOContext, impacting the amount of data written for the fixed-numbered
IO stats kind in the pgstats file.
Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot, Nitin Jadhav, Amit Kapila, Michael
Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAN55FZ3AiQ+ZMxUuXnBpd0Rrh1YhwJ5FudkHg=JU0P+-W8T4Vg@mail.gmail.com
This commit is contained in:
@@ -442,6 +442,20 @@ SELECT (current_schemas(true))[1] = ('pg_temp_' || beid::text) AS match
|
||||
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
|
||||
-----
|
||||
@@ -602,6 +616,7 @@ SELECT pg_stat_get_subscription_stats(NULL);
|
||||
-- - extends of relations using shared buffers
|
||||
-- - fsyncs done to ensure the durability of data dirtying shared buffers
|
||||
-- - shared buffer hits
|
||||
-- - WAL writes and fsyncs in IOContext IOCONTEXT_NORMAL
|
||||
|
||||
-- There is no test for blocks evicted from shared buffers, because we cannot
|
||||
-- be sure of the state of shared buffers at the point the test is run.
|
||||
@@ -621,6 +636,9 @@ SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
|
||||
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
|
||||
FROM pg_stat_get_backend_io(pg_backend_pid())
|
||||
WHERE object = 'relation' \gset my_io_sum_shared_before_
|
||||
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
|
||||
FROM pg_stat_io
|
||||
WHERE context = 'normal' AND object = 'wal' \gset io_sum_wal_normal_before_
|
||||
CREATE TABLE test_io_shared(a int);
|
||||
INSERT INTO test_io_shared SELECT i FROM generate_series(1,100)i;
|
||||
SELECT pg_stat_force_next_flush();
|
||||
@@ -649,6 +667,13 @@ SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
|
||||
SELECT :my_io_sum_shared_after_writes >= :my_io_sum_shared_before_writes;
|
||||
SELECT current_setting('fsync') = 'off'
|
||||
OR :my_io_sum_shared_after_fsyncs >= :my_io_sum_shared_before_fsyncs;
|
||||
SELECT sum(writes) AS writes, sum(fsyncs) AS fsyncs
|
||||
FROM pg_stat_io
|
||||
WHERE context = 'normal' AND object = 'wal' \gset io_sum_wal_normal_after_
|
||||
SELECT current_setting('synchronous_commit') = 'on';
|
||||
SELECT :io_sum_wal_normal_after_writes > :io_sum_wal_normal_before_writes;
|
||||
SELECT current_setting('fsync') = 'off'
|
||||
OR :io_sum_wal_normal_after_fsyncs > :io_sum_wal_normal_before_fsyncs;
|
||||
|
||||
-- Change the tablespace so that the table is rewritten directly, then SELECT
|
||||
-- from it to cause it to be read back into shared buffers.
|
||||
|
||||
Reference in New Issue
Block a user