v20-0003-Makes-the-wal-receiver-report-WAL-statistics.patch
text/x-patch
Filename: v20-0003-Makes-the-wal-receiver-report-WAL-statistics.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
Series: patch v20-0003
| File | + | − |
|---|---|---|
| doc/src/sgml/monitoring.sgml | 4 | 2 |
| doc/src/sgml/wal.sgml | 14 | 2 |
| src/backend/replication/walreceiver.c | 9 | 0 |
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index db4b4e460c..281b13b9fa 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -3493,7 +3493,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
</para>
<para>
Number of times WAL buffers were written out to disk via
- <function>XLogWrite</function> request.
+ <function>XLogWrite</function> request and WAL data were written
+ out to disk by the WAL receiver process.
See <xref linkend="wal-configuration"/> for more information about
the internal WAL function <function>XLogWrite</function>.
</para></entry>
@@ -3521,7 +3522,8 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
</para>
<para>
Total amount of time spent writing WAL buffers to disk via
- <function>XLogWrite</function> request, in milliseconds
+ <function>XLogWrite</function> request and WAL data to disk
+ by the WAL receiver process, in milliseconds
(if <xref linkend="guc-track-wal-io-timing"/> is enabled,
otherwise zero). This includes the sync time when
<varname>wal_sync_method</varname> is either
diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml
index ae4a3c1293..39e7028c96 100644
--- a/doc/src/sgml/wal.sgml
+++ b/doc/src/sgml/wal.sgml
@@ -769,7 +769,7 @@
</para>
<para>
- There are two internal functions to write WAL data to disk:
+ There are two internal functions to write generated WAL data to disk:
<function>XLogWrite</function> and <function>issue_xlog_fsync</function>.
When <xref linkend="guc-track-wal-io-timing"/> is enabled, the total
amounts of time <function>XLogWrite</function> writes and
@@ -795,7 +795,19 @@
<function>issue_xlog_fsync</function> syncs WAL data to disk are also
counted as <literal>wal_write</literal> and <literal>wal_sync</literal>
in <structname>pg_stat_wal</structname>, respectively.
- </para>
+ To write replicated WAL data to disk by the WAL receiver is almost the same
+ as above except for some points. First, there is a dedicated code path for the
+ WAL receiver to write data although <function>issue_xlog_fsync</function> is
+ the same for syncing data.
+ Second, the WAL receiver writes replicated WAL data per bytes from the local
+ memory although the generated WAL data is written per WAL buffer pages.
+ The counters of <literal>wal_write</literal>, <literal>wal_sync</literal>,
+ <literal>wal_write_time</literal>, and <literal>wal_sync_time</literal> are
+ common statistics for writing/syncing both generated and replicated WAL data.
+ But, you can distinguish them because the generated WAL data is written/synced
+ in the primary server and the replicated WAL data is written/synced in
+ the standby server.
+ </para>
</sect1>
<sect1 id="wal-internals">
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index a7a94d2a83..df028c5039 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -771,6 +771,9 @@ WalRcvDie(int code, Datum arg)
/* Ensure that all WAL records received are flushed to disk */
XLogWalRcvFlush(true);
+ /* Send WAL statistics to the stats collector before terminating */
+ pgstat_send_wal(true);
+
/* Mark ourselves inactive in shared memory */
SpinLockAcquire(&walrcv->mutex);
Assert(walrcv->walRcvState == WALRCV_STREAMING ||
@@ -910,6 +913,12 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
XLogArchiveForceDone(xlogfname);
else
XLogArchiveNotify(xlogfname);
+
+ /*
+ * Send WAL statistics to the stats collector when finishing
+ * the current WAL segment file to avoid overloading it.
+ */
+ pgstat_send_wal(false);
}
recvFile = -1;