At Mon, 19 Sep 2022 18:46:17 +0530, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in
> walsener.c might work, but that didn't help either. Can anyone please
> let me know why the stats that I added aren't shown via pg_stat_wal
> view despite the walsender doing pgstat_initialize() ->
> pgstat_init_wal()? Am I missing something?
>
> I'm attaching here with the patch that I was using.
pgstat_report_wal() is supposed to be called on user-facing (or query
executing) backends. The function is called while in idle state on
such backends. Other processes need to call one or more friend
functions as needed. Checkpointer calls pgstat_report_checkpoint/wal()
at the end of an iteration of the main waiting loop. Walwriter does
the same with pgstat_report_wal(). Thus we need to do the same on
startup process somewhere within the redo loop but where that call
doesn't cause contention on shared stats area.
About what the patch does, it increments the xlogreader_cache_hits
counter when the WAL page to read have been already loaded, but it's
not a cache but a buffer. The counter would approximately shows the
number about mean-(raw)-records-per-wal-page *
wal-page-ever-read. (mean-records-per-wal-page = page-size /
mean-record-length). So I don't think that the value offers something
valuable. I guess that the same value (for the moment) can be
calculated from the result of pg_get_wal_records_info().
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center