summaryrefslogtreecommitdiff
path: root/src/include/executor/instrument.h
diff options
context:
space:
mode:
authorFujii Masao2021-05-19 02:38:34 +0000
committerFujii Masao2021-05-19 02:38:34 +0000
commitd8735b8b4651f5ed50afc472e236a8e6120f07f2 (patch)
tree5e8f879c7997ffaa46bb4bc8e274975eb1bc9dd0 /src/include/executor/instrument.h
parent694da1983e9569b2a2f96cd786ead6b8dba31f1d (diff)
Fix issues in pg_stat_wal.
1) Previously there were both pgstat_send_wal() and pgstat_report_wal() in order to send WAL activity to the stats collector. With the former being used by wal writer, the latter by most other processes. They were a bit redundant and so this commit merges them into pgstat_send_wal() to simplify the code. 2) Previously WAL global statistics counters were calculated and then compared with zero-filled buffer in order to determine whether any WAL activity has happened since the last submission. These calculation and comparison were not cheap. This was regularly exercised even in read-only workloads. This commit fixes the issue by making some WAL activity counters directly be checked to determine if there's WAL activity stats to send. 3) Previously pgstat_report_stat() did not check if there's WAL activity stats to send as part of the "Don't expend a clock check if nothing to do" check at the top. It's probably rare to have pending WAL stats without also passing one of the other conditions, but for safely this commit changes pgstat_report_stats() so that it checks also some WAL activity counters at the top. This commit also adds the comments about the design of WAL stats. Reported-by: Andres Freund Author: Masahiro Ikeda Reviewed-by: Kyotaro Horiguchi, Atsushi Torikoshi, Andres Freund, Fujii Masao Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/include/executor/instrument.h')
-rw-r--r--src/include/executor/instrument.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h
index fc87eed4fb2..2f9905b7c8e 100644
--- a/src/include/executor/instrument.h
+++ b/src/include/executor/instrument.h
@@ -16,6 +16,11 @@
#include "portability/instr_time.h"
+/*
+ * BufferUsage and WalUsage counters keep being incremented infinitely,
+ * i.e., must never be reset to zero, so that we can calculate how much
+ * the counters are incremented in an arbitrary period.
+ */
typedef struct BufferUsage
{
int64 shared_blks_hit; /* # of shared buffer hits */
@@ -32,6 +37,13 @@ typedef struct BufferUsage
instr_time blk_write_time; /* time spent writing */
} BufferUsage;
+/*
+ * WalUsage tracks only WAL activity like WAL records generation that
+ * can be measured per query and is displayed by EXPLAIN command,
+ * pg_stat_statements extension, etc. It does not track other WAL activity
+ * like WAL writes that it's not worth measuring per query. That's tracked
+ * by WAL global statistics counters in WalStats, instead.
+ */
typedef struct WalUsage
{
int64 wal_records; /* # of WAL records produced */