diff options
author | Andres Freund <andres@anarazel.de> | 2023-02-08 20:53:42 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2023-02-08 20:53:42 -0800 |
commit | 28e626bde00efe8051fbd677227c97b1aa3c6a1a (patch) | |
tree | 4f54973fcd7b65d71d5003f2385aafbda771c27b /src/include/utils/pgstat_internal.h | |
parent | 49c2c5fcb1e1e4311f08687f78dd9121330ae637 (diff) | |
download | postgresql-28e626bde00efe8051fbd677227c97b1aa3c6a1a.tar.gz postgresql-28e626bde00efe8051fbd677227c97b1aa3c6a1a.zip |
pgstat: Infrastructure for more detailed IO statistics
This commit adds the infrastructure for more detailed IO statistics. The calls
to actually count IOs, a system view to access the new statistics,
documentation and tests will be added in subsequent commits, to make review
easier.
While we already had some IO statistics, e.g. in pg_stat_bgwriter and
pg_stat_database, they did not provide sufficient detail to understand what
the main sources of IO are, or whether configuration changes could avoid
IO. E.g., pg_stat_bgwriter.buffers_backend does contain the number of buffers
written out by a backend, but as that includes extending relations (always
done by backends) and writes triggered by the use of buffer access strategies,
it cannot easily be used to tune background writer or checkpointer. Similarly,
pg_stat_database.blks_read cannot easily be used to tune shared_buffers /
compute a cache hit ratio, as the use of buffer access strategies will often
prevent a large fraction of the read blocks to end up in shared_buffers.
The new IO statistics count IO operations (evict, extend, fsync, read, reuse,
and write), and are aggregated for each combination of backend type (backend,
autovacuum worker, bgwriter, etc), target object of the IO (relations, temp
relations) and context of the IO (normal, vacuum, bulkread, bulkwrite).
What is tracked in this series of patches, is sufficient to perform the
aforementioned analyses. Further details, e.g. tracking the number of buffer
hits, would make that even easier, but was left out for now, to keep the scope
of the already large patchset manageable.
Bumps PGSTAT_FILE_FORMAT_ID.
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/20200124195226.lth52iydq2n2uilq@alap3.anarazel.de
Diffstat (limited to 'src/include/utils/pgstat_internal.h')
-rw-r--r-- | src/include/utils/pgstat_internal.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h index 12fd51f1ae3..6badb2fde4b 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -329,6 +329,17 @@ typedef struct PgStatShared_Checkpointer PgStat_CheckpointerStats reset_offset; } PgStatShared_Checkpointer; +/* Shared-memory ready PgStat_IO */ +typedef struct PgStatShared_IO +{ + /* + * locks[i] protects stats.stats[i]. locks[0] also protects + * stats.stat_reset_timestamp. + */ + LWLock locks[BACKEND_NUM_TYPES]; + PgStat_IO stats; +} PgStatShared_IO; + typedef struct PgStatShared_SLRU { /* lock protects ->stats */ @@ -419,6 +430,7 @@ typedef struct PgStat_ShmemControl PgStatShared_Archiver archiver; PgStatShared_BgWriter bgwriter; PgStatShared_Checkpointer checkpointer; + PgStatShared_IO io; PgStatShared_SLRU slru; PgStatShared_Wal wal; } PgStat_ShmemControl; @@ -442,6 +454,8 @@ typedef struct PgStat_Snapshot PgStat_CheckpointerStats checkpointer; + PgStat_IO io; + PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]; PgStat_WalStats wal; @@ -550,6 +564,15 @@ extern bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait); /* + * Functions in pgstat_io.c + */ + +extern bool pgstat_flush_io(bool nowait); +extern void pgstat_io_reset_all_cb(TimestampTz ts); +extern void pgstat_io_snapshot_cb(void); + + +/* * Functions in pgstat_relation.c */ @@ -644,6 +667,13 @@ extern PGDLLIMPORT PgStat_LocalState pgStatLocal; /* + * Variables in pgstat_io.c + */ + +extern PGDLLIMPORT bool have_iostats; + + +/* * Variables in pgstat_slru.c */ |