log XLogPrefetch stats at end of recovery
log XLogPrefetch stats at end of recovery
Hi,
While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
Regards,
Lakshmi
Re: log XLogPrefetch stats at end of recovery
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
Hi,
On Wed, Mar 18, 2026 at 12:18 AM Lakshmi N <lakshmin.jhs@gmail.com> wrote:
Hi,While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis. I am wondering if we can periodically log this in standby mode as well, not just before promoting?
2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
Thanks,
Satya
Re: log XLogPrefetch stats at end of recovery
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi,
On Sat, Mar 21, 2026 at 1:16 AM SATYANARAYANA NARLAPURAM
wrote:
>
> > While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
>
> Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis.
>
> 2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
This looks useful to understand how the prefetch helped during long recoveries.
> I am wondering if we can periodically log this in standby mode as well, not just before promoting?
Timer-based startup progress messaging allows logging such things
(ereport_startup_progress API). There was an attempt to enable "redo
in progress" for standbys, but that seemed to flood the standby logs
even at the default progress interval of 10 sec.
Having said that, the prefetcher stats could be added to the existing
ereport_startup_progress("redo in progress xxx") message that works
for crash recoveries—however, I don't prefer doing a bunch of atomic
reads every progress interval of 10 sec. Therefore, logging at the end
of recovery looks good to me.
I reviewed the patch. I have the following comment:
+ elog(LOG, "XLogPrefetcher stats: prefetch=%lu, hit=%lu,
skip_init=%lu, skip_new=%lu, skip_fpw=%lu, skip_rep=%lu",
XLogPrefetcher is an internal data structure name, how about "redo
prefetch stats: xxxx" to be consistent with other redo log messages?
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: log XLogPrefetch stats at end of recovery
От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
On Sun, Mar 22, 2026 at 1:43 AM Bharath Rupireddy
wrote:
Hi,
> On Sat, Mar 21, 2026 at 1:16 AM SATYANARAYANA NARLAPURAM
> wrote:
> >
> > > While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
> >
> > Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis.
> >
> > 2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
>
> This looks useful to understand how the prefetch helped during long recoveries.
>
> > I am wondering if we can periodically log this in standby mode as well, not just before promoting?
>
> Timer-based startup progress messaging allows logging such things
> (ereport_startup_progress API). There was an attempt to enable "redo
> in progress" for standbys, but that seemed to flood the standby logs
> even at the default progress interval of 10 sec.
>
> Having said that, the prefetcher stats could be added to the existing
> ereport_startup_progress("redo in progress xxx") message that works
> for crash recoveries—however, I don't prefer doing a bunch of atomic
> reads every progress interval of 10 sec.
> Therefore, logging at the end of recovery looks good to me.
+1 from me too to only of logging at the end of recovery (so -1 to logging
every now and then). If someone is interested in current state (or progress
over time) I think he can query pg_stat_recovery_prefetch view already, even
today, right?
> I reviewed the patch. I have the following comment:
>
> + elog(LOG, "XLogPrefetcher stats: prefetch=%lu, hit=%lu,
> skip_init=%lu, skip_new=%lu, skip_fpw=%lu, skip_rep=%lu",
>
> XLogPrefetcher is an internal data structure name, how about "redo
> prefetch stats: xxxx" to be consistent with other redo log messages?
+1
-J.
Re: log XLogPrefetch stats at end of recovery
Hi all,
Thank you for your feedback. Please see the attached patch.
On Mon, Mar 23, 2026 at 4:30 AM Jakub Wartak <jakub.wartak@enterprisedb.com> wrote:
On Sun, Mar 22, 2026 at 1:43 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
Hi,
> On Sat, Mar 21, 2026 at 1:16 AM SATYANARAYANA NARLAPURAM
> <satyanarlapuram@gmail.com> wrote:
> >
> > > While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
> >
> > Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis.
> >
> > 2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
>
> This looks useful to understand how the prefetch helped during long recoveries.
>
> > I am wondering if we can periodically log this in standby mode as well, not just before promoting?
>
> Timer-based startup progress messaging allows logging such things
> (ereport_startup_progress API). There was an attempt to enable "redo
> in progress" for standbys, but that seemed to flood the standby logs
> even at the default progress interval of 10 sec.
>
> Having said that, the prefetcher stats could be added to the existing
> ereport_startup_progress("redo in progress xxx") message that works
> for crash recoveries—however, I don't prefer doing a bunch of atomic
> reads every progress interval of 10 sec.
> Therefore, logging at the end of recovery looks good to me.
+1 from me too to only of logging at the end of recovery (so -1 to logging
every now and then). If someone is interested in current state (or progress
over time) I think he can query pg_stat_recovery_prefetch view already, even
today, right?
> I reviewed the patch. I have the following comment:
>
> + elog(LOG, "XLogPrefetcher stats: prefetch=%lu, hit=%lu,
> skip_init=%lu, skip_new=%lu, skip_fpw=%lu, skip_rep=%lu",
>
> XLogPrefetcher is an internal data structure name, how about "redo
> prefetch stats: xxxx" to be consistent with other redo log messages?
+1
please find the attached patch addressing this.
Regards,
Lakshmi
Re: log XLogPrefetch stats at end of recovery
От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
On Tue, Mar 24, 2026 at 9:28 AM Lakshmi N wrote:
>
> Hi all,
>
> Thank you for your feedback. Please see the attached patch.
>
> On Mon, Mar 23, 2026 at 4:30 AM Jakub Wartak wrote:
>>
>> On Sun, Mar 22, 2026 at 1:43 AM Bharath Rupireddy
>> wrote:
>>
>> Hi,
>>
>> > On Sat, Mar 21, 2026 at 1:16 AM SATYANARAYANA NARLAPURAM
>> > wrote:
>> > >
>> > > > While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
>> > >
>> > > Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis.
>> > >
>> > > 2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
>> >
>> > This looks useful to understand how the prefetch helped during long recoveries.
>> >
>> > > I am wondering if we can periodically log this in standby mode as well, not just before promoting?
>> >
>> > Timer-based startup progress messaging allows logging such things
>> > (ereport_startup_progress API). There was an attempt to enable "redo
>> > in progress" for standbys, but that seemed to flood the standby logs
>> > even at the default progress interval of 10 sec.
>> >
>> > Having said that, the prefetcher stats could be added to the existing
>> > ereport_startup_progress("redo in progress xxx") message that works
>> > for crash recoveries—however, I don't prefer doing a bunch of atomic
>> > reads every progress interval of 10 sec.
>>
>> > Therefore, logging at the end of recovery looks good to me.
>>
>> +1 from me too to only of logging at the end of recovery (so -1 to logging
>> every now and then). If someone is interested in current state (or progress
>> over time) I think he can query pg_stat_recovery_prefetch view already, even
>> today, right?
>>
>> > I reviewed the patch. I have the following comment:
>> >
>> > + elog(LOG, "XLogPrefetcher stats: prefetch=%lu, hit=%lu,
>> > skip_init=%lu, skip_new=%lu, skip_fpw=%lu, skip_rep=%lu",
>> >
>> > XLogPrefetcher is an internal data structure name, how about "redo
>> > prefetch stats: xxxx" to be consistent with other redo log messages?
>>
>> +1
>
>
> please find the attached patch addressing this.
Hi Lakshmi,
The pg_stat_get_recovery_prefetch view has 3 additional columns, but they are
showing current situation, maybe this $patch could be enhanced so that it also
calculates averages for some of them? I mean perhaps not just hit ratio would be
nice, but also the e.g. __average__ wal distance or average look ahead
(block distance).
I'm not sure maybe please also wait for input from others if they find
it a good idea
or not.
Also if we are adding such pretty cryptic fields as "skip_fpw" to log,
we would need some
place in documentaiton to explain their meaining probably.
monitoring.sgml already
explains them, so maybe just link to that. I mean if you look what we
have today (below),
they are little less crypting and have different format, not
"skip_fpw=123" but more
like "17 removed" so maybe "17 skipped due to FPW". Maybe
redo done at 0/75C7B290 system usage: CPU: user: 1.02 s, system: 0.51
s, elapsed: 1.53 s
checkpoint complete: end-of-recovery fast wait: wrote 16289 buffers
(99.4%), wrote 3 SLRU buffers; 0 WAL file(s) added, 17 removed, 0
recycled; write=0.049 s, sync=0.191 s, total=0.264 s; sync files=10,
longest=0.187 s, average=0.020 s; distance=287186 kB, estimate=287186
kB; lsn=0/75C7B2C8, redo lsn=0/75C7B2C8
so instead of like:
redo prefetch stats: prefetch=%lu, hit=%lu, skip_init=%lu,
skip_new=%lu, skip_fpw=%lu, skip_rep=%lu"
something like below ones:
redo prefetch stats: done %lu prefetches, %lu hit, %lu zero-initated, ..
redo prefetch stats: done %lu prefetches, (%d% hit ratio), %lu
zero-initated, .. or something like that
-J.
Re: log XLogPrefetch stats at end of recovery
Hi,
On Tue, Mar 24, 2026 at 1:53 AM Jakub Wartak <jakub.wartak@enterprisedb.com> wrote:
On Tue, Mar 24, 2026 at 9:28 AM Lakshmi N <lakshmin.jhs@gmail.com> wrote:
>
> Hi all,
>
> Thank you for your feedback. Please see the attached patch.
>
> On Mon, Mar 23, 2026 at 4:30 AM Jakub Wartak <jakub.wartak@enterprisedb.com> wrote:
>>
>> On Sun, Mar 22, 2026 at 1:43 AM Bharath Rupireddy
>> <bharath.rupireddyforpostgres@gmail.com> wrote:
>>
>> Hi,
>>
>> > On Sat, Mar 21, 2026 at 1:16 AM SATYANARAYANA NARLAPURAM
>> > <satyanarlapuram@gmail.com> wrote:
>> > >
>> > > > While investigating a long recovery, I noticed that XLogPrefetch stats were not logged at the end of recovery. This log message will be useful to understand how effective XLogPrefetch was during recovery. Adding a patch to address this.
>> > >
>> > > Applied this patch and validated the log message. This log message appears to be useful to me, particularly while doing fleet wide analysis.
>> > >
>> > > 2026-03-20 23:33:13.756 PDT [2265441] LOG: XLogPrefetcher stats: prefetch=14, hit=6, skip_init=5, skip_new=28, skip_fpw=18, skip_rep=996
>> >
>> > This looks useful to understand how the prefetch helped during long recoveries.
>> >
>> > > I am wondering if we can periodically log this in standby mode as well, not just before promoting?
>> >
>> > Timer-based startup progress messaging allows logging such things
>> > (ereport_startup_progress API). There was an attempt to enable "redo
>> > in progress" for standbys, but that seemed to flood the standby logs
>> > even at the default progress interval of 10 sec.
>> >
>> > Having said that, the prefetcher stats could be added to the existing
>> > ereport_startup_progress("redo in progress xxx") message that works
>> > for crash recoveries—however, I don't prefer doing a bunch of atomic
>> > reads every progress interval of 10 sec.
>>
>> > Therefore, logging at the end of recovery looks good to me.
>>
>> +1 from me too to only of logging at the end of recovery (so -1 to logging
>> every now and then). If someone is interested in current state (or progress
>> over time) I think he can query pg_stat_recovery_prefetch view already, even
>> today, right?
>>
>> > I reviewed the patch. I have the following comment:
>> >
>> > + elog(LOG, "XLogPrefetcher stats: prefetch=%lu, hit=%lu,
>> > skip_init=%lu, skip_new=%lu, skip_fpw=%lu, skip_rep=%lu",
>> >
>> > XLogPrefetcher is an internal data structure name, how about "redo
>> > prefetch stats: xxxx" to be consistent with other redo log messages?
>>
>> +1
>
>
> please find the attached patch addressing this.
Hi Lakshmi,
The pg_stat_get_recovery_prefetch view has 3 additional columns, but they are
showing current situation, maybe this $patch could be enhanced so that it also
calculates averages for some of them? I mean perhaps not just hit ratio would be
nice, but also the e.g. __average__ wal distance or average look ahead
(block distance).
I'm not sure maybe please also wait for input from others if they find
it a good idea
or not.
Also if we are adding such pretty cryptic fields as "skip_fpw" to log,
we would need some
place in documentaiton to explain their meaining probably.
monitoring.sgml already
explains them, so maybe just link to that. I mean if you look what we
have today (below),
they are little less crypting and have different format, not
"skip_fpw=123" but more
like "17 removed" so maybe "17 skipped due to FPW". Maybe
redo done at 0/75C7B290 system usage: CPU: user: 1.02 s, system: 0.51
s, elapsed: 1.53 s
checkpoint complete: end-of-recovery fast wait: wrote 16289 buffers
(99.4%), wrote 3 SLRU buffers; 0 WAL file(s) added, 17 removed, 0
recycled; write=0.049 s, sync=0.191 s, total=0.264 s; sync files=10,
longest=0.187 s, average=0.020 s; distance=287186 kB, estimate=287186
kB; lsn=0/75C7B2C8, redo lsn=0/75C7B2C8
so instead of like:
redo prefetch stats: prefetch=%lu, hit=%lu, skip_init=%lu,
skip_new=%lu, skip_fpw=%lu, skip_rep=%lu"
something like below ones:
redo prefetch stats: done %lu prefetches, %lu hit, %lu zero-initated, ..
redo prefetch stats: done %lu prefetches, (%d% hit ratio), %lu
zero-initated, .. or something like that
Please find the attached patch with the suggested changes. I referenced [1] to log the message as suggested.
2026-03-24 04:53:15.251 PDT [18898] LOG: redo prefetch stats: prefetched 27 blocks, skipped 22 blocks because they were already in the buffer pool, skipped 17 blocks because they would be zero-initialized, skipped 0 blocks because they didn't exist yet, skipped 28 blocks because a full page image was included in the WAL, skipped 155 blocks because they were already recently prefetched.
[1] https://www.postgresql.org/docs/devel/monitoring-stats.html#MONITORING-PG-STAT-RECOVERY-PREFETCH
Regards,
Lakshmi
Re: log XLogPrefetch stats at end of recovery
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi, On Tue, Mar 24, 2026 at 5:07 AM Lakshmi N wrote: > >> so instead of like: >> redo prefetch stats: prefetch=%lu, hit=%lu, skip_init=%lu, >> skip_new=%lu, skip_fpw=%lu, skip_rep=%lu" >> >> something like below ones: >> redo prefetch stats: done %lu prefetches, %lu hit, %lu zero-initated, .. >> redo prefetch stats: done %lu prefetches, (%d% hit ratio), %lu >> zero-initated, .. or something like that > > Please find the attached patch with the suggested changes. I referenced [1] to log the message as suggested. > > 2026-03-24 04:53:15.251 PDT [18898] LOG: redo prefetch stats: prefetched 27 blocks, skipped 22 blocks because they were already in the buffer pool, skipped 17 blocks because they would be zero-initialized, skipped 0 blocks because they didn't exist yet, skipped 28 blocks because a full page image was included in the WAL, skipped 155 blocks because they were already recently prefetched. IMHO, the above looks too verbose. +1 for Jakub's suggestion. Would something like the below work? I believe the developers looking at these logs for analysis will have some understanding of what each of these means. LOG: redo prefetch stats: prefetched 27, skipped (22 in buffer pool, 17 zero-inited, 0 non-existent, 28 FPI, 155 recently prefetched) -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: log XLogPrefetch stats at end of recovery
Hi,
On Tue, Mar 24, 2026 at 8:23 PM Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
Hi,
On Tue, Mar 24, 2026 at 5:07 AM Lakshmi N <lakshmin.jhs@gmail.com> wrote:
>
>> so instead of like:
>> redo prefetch stats: prefetch=%lu, hit=%lu, skip_init=%lu,
>> skip_new=%lu, skip_fpw=%lu, skip_rep=%lu"
>>
>> something like below ones:
>> redo prefetch stats: done %lu prefetches, %lu hit, %lu zero-initated, ..
>> redo prefetch stats: done %lu prefetches, (%d% hit ratio), %lu
>> zero-initated, .. or something like that
>
> Please find the attached patch with the suggested changes. I referenced [1] to log the message as suggested.
>
> 2026-03-24 04:53:15.251 PDT [18898] LOG: redo prefetch stats: prefetched 27 blocks, skipped 22 blocks because they were already in the buffer pool, skipped 17 blocks because they would be zero-initialized, skipped 0 blocks because they didn't exist yet, skipped 28 blocks because a full page image was included in the WAL, skipped 155 blocks because they were already recently prefetched.
IMHO, the above looks too verbose. +1 for Jakub's suggestion. Would
something like the below work? I believe the developers looking at
these logs for analysis will have some understanding of what each of
these means.
LOG: redo prefetch stats: prefetched 27, skipped (22 in buffer pool,
17 zero-inited, 0 non-existent, 28 FPI, 155 recently prefetched)
Address this in the attached patch. Please let me know if this looks good.
2026-03-26 00:51:19.797 PDT [91881] LOG: redo prefetch stats: prefetched 418376 blocks, skipped (362419 in the buffer pool, 418479 zero-initialized, 0 non-existent, 9 full page image, 39183318 recently prefetched)
Regards,
Lakshmi
Re: log XLogPrefetch stats at end of recovery
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi, On Thu, Mar 26, 2026 at 1:06 AM Lakshmi N wrote: > > Address this in the attached patch. Please let me know if this looks good. > 2026-03-26 00:51:19.797 PDT [91881] LOG: redo prefetch stats: prefetched 418376 blocks, skipped (362419 in the buffer pool, 418479 zero-initialized, 0 non-existent, 9 full page image, 39183318 recently prefetched) Thanks for sending the latest patch. It looks good to me with a nit:s/362419 in the buffer pool/362419 already in buffer pool. I will leave it to others' choice. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: log XLogPrefetch stats at end of recovery
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
On Thu, Mar 26, 2026 at 5:10 PM Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
Hi,
On Thu, Mar 26, 2026 at 1:06 AM Lakshmi N <lakshmin.jhs@gmail.com> wrote:
>
> Address this in the attached patch. Please let me know if this looks good.
> 2026-03-26 00:51:19.797 PDT [91881] LOG: redo prefetch stats: prefetched 418376 blocks, skipped (362419 in the buffer pool, 418479 zero-initialized, 0 non-existent, 9 full page image, 39183318 recently prefetched)
Thanks for sending the latest patch. It looks good to me with a
nit:s/362419 in the buffer pool/362419 already in buffer pool. I will
leave it to others' choice
LGTM too, I will leave it to the committer's choice.
Thanks,
Satya
Re: log XLogPrefetch stats at end of recovery
От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
On Wed, Oct 14, 2026 at 1:36 PM SATYANARAYANA NARLAPURAM wrote: > > > > On Thu, Mar 26, 2026 at 5:10 PM Bharath Rupireddy wrote: >> >> Hi, >> >> On Thu, Mar 26, 2026 at 1:06 AM Lakshmi N wrote: >> > >> > Address this in the attached patch. Please let me know if this looks good. >> > 2026-03-26 00:51:19.797 PDT [91881] LOG: redo prefetch stats: prefetched 418376 blocks, skipped (362419 in the buffer pool, 418479 zero-initialized, 0 non-existent, 9 full page image, 39183318 recently prefetched) >> >> Thanks for sending the latest patch. It looks good to me with a >> nit:s/362419 in the buffer pool/362419 already in buffer pool. I will >> leave it to others' choice > > > LGTM too, I will leave it to the committer's choice. > Hi, This was never added to the commitfest (even back then) or am I missing something? -J.
Re: log XLogPrefetch stats at end of recovery
Hi, On Wed, Oct 14, 2026 at 5:08 PM Jakub Wartak wrote: > > On Wed, Oct 14, 2026 at 1:36 PM SATYANARAYANA NARLAPURAM > wrote: > > > > > > > > On Thu, Mar 26, 2026 at 5:10 PM Bharath Rupireddy wrote: > >> > >> Hi, > >> > >> On Thu, Mar 26, 2026 at 1:06 AM Lakshmi N wrote: > >> > > >> > Address this in the attached patch. Please let me know if this looks good. > >> > 2026-03-26 00:51:19.797 PDT [91881] LOG: redo prefetch stats: prefetched 418376 blocks, skipped (362419 in the buffer pool, 418479 zero-initialized, 0 non-existent, 9 full page image, 39183318 recently prefetched) > >> > >> Thanks for sending the latest patch. It looks good to me with a > >> nit:s/362419 in the buffer pool/362419 already in buffer pool. I will > >> leave it to others' choice > > > > > > LGTM too, I will leave it to the committer's choice. > > > > Hi, > > This was never added to the commitfest (even back then) or am I missing > something? > I have created a CF entry for this in the name of Lakshmi N (the author of this patch). Also, I find that the patch has been idle for months and no longer applied, so I have rebased it (v4 attached) with some cosmetic changes. -- With Regards, Ashutosh Sharma.
Re: log XLogPrefetch stats at end of recovery
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi,
On Wed, Oct 14, 2026 at 9:05 AM Ashutosh Sharma wrote:
>
> I have created a CF entry for this in the name of Lakshmi N (the
> author of this patch). Also, I find that the patch has been idle for
> months and no longer applied, so I have rebased it (v4 attached) with
> some cosmetic changes.
Thanks. I reviewed the v4 patch.
I think reporting the prefetch stats into the server logs at the end
of recovery is useful for post hoc analysis, especially for long
recovery times, e.g., after a standby is promoted, after a long crash
recovery, or when recovering from a backup/snapshot. And, one can know
the prefetch progress using the stats function anyway.
Few comments:
1/ Using PRIu64 here looks good to me. Commits 15a79c731, a0ed19e0a. I
see some usages of PRId64 and PRIu64 for int64 and uint64 (WalUsage
for example).
2/ I think reporting it after reading the last valid or applied record
when finishing the WAL recovery would cover the last record's stats as
well, but the difference in the stats might be small, so reporting it
here after the redo loop is fine with me.
3/
+void
+XLogPrefetchLogStats(void)
+{
+ if (recovery_prefetch == RECOVERY_PREFETCH_OFF)
+ return;
Use RecoveryPrefetchEnabled() instead. Prefetch is enabled only on the
supported platforms and io concurrency also needs to be set.
4/ I think, in case of long recoveries, not reporting the accumulated
stats, if any, before prefetch was turned off seems a bit incomplete
and inconsistent. How about we just log the stats as-is (it's fine for
them to be all zeros), and also optionally log the value of the GUC as
of that moment? This log message is not going to flood the server
logs, as it happens only at the end of the recovery anyway.
5/
+/*
+ * Log a summary of the prefetch counters at the end of recovery.
+ */
+void
+XLogPrefetchLogStats(void)
I don't think there's anything that makes this function specific to
being called "at the end of recovery," other than the "redo" in the
log message. One can call it at any point in time and get the
accumulated stats as of that moment. This makes me think whether the
function needs to log the redo-specific message at all, or instead do
something like pg_rusage_show() does and leave the redo message to the
caller. I don't like exposing the shared stats pointer out of
xlogprefetcher.c. Or just rename the function to
XLogPrefetchLogStatsOnRecoveryEnd(). I prefer to rename it.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: log XLogPrefetch stats at end of recovery
Hi Bharath,
On Thu, Nov 5, 2026 at 12:17 AM Bharath Rupireddy
wrote:
>
> Hi,
>
> On Wed, Oct 14, 2026 at 9:05 AM Ashutosh Sharma wrote:
> >
> > I have created a CF entry for this in the name of Lakshmi N (the
> > author of this patch). Also, I find that the patch has been idle for
> > months and no longer applied, so I have rebased it (v4 attached) with
> > some cosmetic changes.
>
> Thanks. I reviewed the v4 patch.
>
> I think reporting the prefetch stats into the server logs at the end
> of recovery is useful for post hoc analysis, especially for long
> recovery times, e.g., after a standby is promoted, after a long crash
> recovery, or when recovering from a backup/snapshot. And, one can know
> the prefetch progress using the stats function anyway.
>
> Few comments:
>
> 1/ Using PRIu64 here looks good to me. Commits 15a79c731, a0ed19e0a. I
> see some usages of PRId64 and PRIu64 for int64 and uint64 (WalUsage
> for example).
>
> 2/ I think reporting it after reading the last valid or applied record
> when finishing the WAL recovery would cover the last record's stats as
> well, but the difference in the stats might be small, so reporting it
> here after the redo loop is fine with me.
>
> 3/
> +void
> +XLogPrefetchLogStats(void)
> +{
> + if (recovery_prefetch == RECOVERY_PREFETCH_OFF)
> + return;
>
> Use RecoveryPrefetchEnabled() instead. Prefetch is enabled only on the
> supported platforms and io concurrency also needs to be set.
>
> 4/ I think, in case of long recoveries, not reporting the accumulated
> stats, if any, before prefetch was turned off seems a bit incomplete
> and inconsistent. How about we just log the stats as-is (it's fine for
> them to be all zeros), and also optionally log the value of the GUC as
> of that moment? This log message is not going to flood the server
> logs, as it happens only at the end of the recovery anyway.
>
> 5/
> +/*
> + * Log a summary of the prefetch counters at the end of recovery.
> + */
> +void
> +XLogPrefetchLogStats(void)
>
> I don't think there's anything that makes this function specific to
> being called "at the end of recovery," other than the "redo" in the
> log message. One can call it at any point in time and get the
> accumulated stats as of that moment. This makes me think whether the
> function needs to log the redo-specific message at all, or instead do
> something like pg_rusage_show() does and leave the redo message to the
> caller. I don't like exposing the shared stats pointer out of
> xlogprefetcher.c. Or just rename the function to
> XLogPrefetchLogStatsOnRecoveryEnd(). I prefer to rename it.
>
Thanks for reviewing the patch.
I have addressed comments 4 and 5 in the attached v5 patch. Comments 1
and 2 do not appear to require changes and comment 3 conflicts with
comment 4, and I chose to implement 4 over 3.
To summarize, v5 adds these:
1) Reports accumulated prefetch statistics at the end of recovery,
regardless of whether prefetching is enabled at that point, and
includes the current recovery_prefetch setting.
2) Adds regression tests covering zero counters and statistics
retained after disabling prefetching.
3) Renames the function to XLogPrefetchLogStatsOnRecoveryEnd() to make
its intended use explicit.
Please take a look and let me know for any other comments.
--
With Regards,
Ashutosh Sharma.
Re: log XLogPrefetch stats at end of recovery
Hi, On Thu, Nov 5, 2026 at 11:04 PM Ashutosh Sharma wrote: > > I have addressed comments 4 and 5 in the attached v5 patch. Thanks for updating the patch. > To summarize, v5 adds these: > > 1) Reports accumulated prefetch statistics at the end of recovery, > regardless of whether prefetching is enabled at that point, and > includes the current recovery_prefetch setting. > > 2) Adds regression tests covering zero counters and statistics > retained after disabling prefetching. A TAP test is an overkill here. The code is already covered in the recovery tests [1]. > 3) Renames the function to XLogPrefetchLogStatsOnRecoveryEnd() to make > its intended use explicit. > > Please take a look and let me know for any other comments. I don't think we need to report whether recovery prefetch was on during the recovery in the log message (sorry for saying so upthread). BTW, even if we were to report it, RecoveryPrefetchEnabled() was the correct one to use. But I would drop it. Please have a look at the attached v6 with the above adjustments: moved the log message after the existing "last completed transaction..." message, reworded the commit message, and dropped the TAP test. I think it is RfC. Thoughts? [1] LOG: redo prefetch stats: prefetched 9 blocks, skipped (0 in the buffer pool, 5 zero-initialized, 344 non-existent, 16 full page image, 661 recently prefetched) LOG: redo prefetch stats: prefetched 1 blocks, skipped (0 in the buffer pool, 22 zero-initialized, 1408 non-existent, 3 full page image, 3568 recently prefetched) LOG: redo prefetch stats: prefetched 9 blocks, skipped (0 in the buffer pool, 5 zero-initialized, 344 non-existent, 16 full page image, 661 recently prefetched) LOG: redo prefetch stats: prefetched 8 blocks, skipped (1 in the buffer pool, 5 zero-initialized, 344 non-existent, 16 full page image, 661 recently prefetched) LOG: redo prefetch stats: prefetched 9 blocks, skipped (2 in the buffer pool, 1 zero-initialized, 0 non-existent, 24 full page image, 148 recently prefetched) -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: log XLogPrefetch stats at end of recovery
От:
Ashutosh Sharma <ashu.coek88@gmail.com>
Дата:
Hi Bharath, On Thu, Nov 12, 2026 at 2:28 AM Bharath Rupireddy wrote: > > Hi, > > On Thu, Nov 5, 2026 at 11:04 PM Ashutosh Sharma wrote: > > > > I have addressed comments 4 and 5 in the attached v5 patch. > > Thanks for updating the patch. > > > To summarize, v5 adds these: > > > > 1) Reports accumulated prefetch statistics at the end of recovery, > > regardless of whether prefetching is enabled at that point, and > > includes the current recovery_prefetch setting. > > > > 2) Adds regression tests covering zero counters and statistics > > retained after disabling prefetching. > > A TAP test is an overkill here. The code is already covered in the > recovery tests [1]. > > > 3) Renames the function to XLogPrefetchLogStatsOnRecoveryEnd() to make > > its intended use explicit. > > > > Please take a look and let me know for any other comments. > > I don't think we need to report whether recovery prefetch was on > during the recovery in the log message (sorry for saying so upthread). > BTW, even if we were to report it, RecoveryPrefetchEnabled() was the > correct one to use. But I would drop it. > > Please have a look at the attached v6 with the above adjustments: > moved the log message after the existing "last completed > transaction..." message, reworded the commit message, and dropped the > TAP test. I think it is RfC. Thoughts? > Thanks for sharing this. I don’t have any major comments, and the changes look good to me. I’d be happy to wait and hear what others think. -- With Regards, Ashutosh Sharma.
Re: log XLogPrefetch stats at end of recovery
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Nov 12, 2026 at 5:58 AM Bharath Rupireddy wrote: > I think it is RfC. Thoughts? I'm not sure how useful it is to log these statistics even though they are already available in pg_stat_recovery_prefetch. Currently, the counters in pg_stat_recovery_prefetch are not saved and restored by pgstat, so they are lost even across a clean restart. So, if the goal of this patch is to preserve them for later analysis, logging them could be useful. But, making these statistics persistent was already discussed when recovery prefetch was introduced [1]. If we eventually implement that in the future, the statistics could be queried from the view after a clean restart. So I'm wondering what additional value the log message would provide in that case.... Sorry if I'm missing something. Regards, [1] https://www.postgresql.org/message-id/CA%2BhUKGJ7OqpdnbSTq5oK%3DdjSeVW2JMnrVPSm8JC-_dbN6Y7bpw%40mail.gmail.com -- Fujii Masao