Skip to content

Commit 7f7f324

Browse files
committed
Add more monitoring data for WAL writes in the WAL receiver
This commit adds two improvements related to the monitoring of WAL writes for the WAL receiver. First, write counts and timings are now counted in pg_stat_io for the WAL receiver. These have been discarded from pg_stat_wal in ff99918 due to performance concerns, related to the fact that we still relied on an on-disk file for the stats back then, even with track_wal_io_timing to avoid the overhead of the timestamp calculations. This implementation is simpler than the original proposal as it is possible to rely on the APIs of pgstat_io.c to do the job. Like the fsync and read data, track_wal_io_timing needs to be enabled to track the timings. Second, a wait event is added around the pg_pwrite() call in charge of the writes, using the exiting WAIT_EVENT_WAL_WRITE. This is useful as the WAL receiver data is tracked in pg_stat_activity. Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/Z8gFnH4o3jBm5BRz@ip-10-97-1-34.eu-west-3.compute.internal
1 parent 393e0d2 commit 7f7f324

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/replication/walreceiver.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, TimeLineID tli)
922922
{
923923
int startoff;
924924
int byteswritten;
925+
instr_time start;
925926

926927
Assert(tli != 0);
927928

@@ -952,7 +953,18 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, TimeLineID tli)
952953
/* OK to write the logs */
953954
errno = 0;
954955

956+
/*
957+
* Measure I/O timing to write WAL data, for pg_stat_io.
958+
*/
959+
start = pgstat_prepare_io_time(track_wal_io_timing);
960+
961+
pgstat_report_wait_start(WAIT_EVENT_WAL_WRITE);
955962
byteswritten = pg_pwrite(recvFile, buf, segbytes, (off_t) startoff);
963+
pgstat_report_wait_end();
964+
965+
pgstat_count_io_op_time(IOOBJECT_WAL, IOCONTEXT_NORMAL,
966+
IOOP_WRITE, start, 1, byteswritten);
967+
956968
if (byteswritten <= 0)
957969
{
958970
char xlogfname[MAXFNAMELEN];

0 commit comments

Comments
 (0)