Hi, On Thu, Nov 5, 2026 at 11:04 PM Ashutosh Sharma <[email protected]> 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
From 0a1cdacf2cc875890ee745fa3eb0ae68b748f35e Mon Sep 17 00:00:00 2001 From: Ashutosh Sharma <[email protected]> Date: Fri, 6 Nov 2026 06:48:49 +0000 Subject: [PATCH v6] Emit prefetch statistics into the server log at end of recovery Emitting the prefetch statistics into the server log at the end of recovery is useful for post hoc analysis, especially when recovery runs long, e.g., after a standby is promoted, after a long crash recovery, or when recovering from a backup or snapshot. This commit adds a log message at the end of the redo loop in PerformWalRecovery(). The recovery prefetch stats view can be used while recovery is in progress, but the log message is more for post hoc analysis purposes. Author: Lakshmi N <[email protected]> Co-authored-by: Ashutosh Sharma <[email protected]> Reviewed-by: Bharath Rupireddy <[email protected]> Reviewed-by: Satyanarayana Narlapuram <[email protected]> Reviewed-by: Jakub Wartak <[email protected]> Discussion: https://postgr.es/m/CA%2B3i_M-%2BWVyrRcfnxa4gt%2BKQUzH-LTQ8D2JCGE_O0WzJJtZfUg%40mail.gmail.com --- src/backend/access/transam/xlogprefetcher.c | 15 +++++++++++++++ src/backend/access/transam/xlogrecovery.c | 2 ++ src/include/access/xlogprefetcher.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/backend/access/transam/xlogprefetcher.c b/src/backend/access/transam/xlogprefetcher.c index 288cdbd34c4..f04ebc8c4f7 100644 --- a/src/backend/access/transam/xlogprefetcher.c +++ b/src/backend/access/transam/xlogprefetcher.c @@ -337,6 +337,21 @@ XLogPrefetchResetStats(void) pg_atomic_write_u64(&SharedStats->skip_rep, 0); } +/* + * Log a summary of the prefetch counters at the end of recovery. + */ +void +XLogPrefetchLogStatsOnRecoveryEnd(void) +{ + ereport(LOG, + errmsg("redo prefetch stats: prefetched %" PRIu64 " blocks, skipped (%" PRIu64 " in the buffer pool, %" PRIu64 " zero-initialized, %" PRIu64 " non-existent, %" PRIu64 " full page image, %" PRIu64 " recently prefetched)", + pg_atomic_read_u64(&SharedStats->prefetch), + pg_atomic_read_u64(&SharedStats->hit), + pg_atomic_read_u64(&SharedStats->skip_init), + pg_atomic_read_u64(&SharedStats->skip_new), + pg_atomic_read_u64(&SharedStats->skip_fpw), + pg_atomic_read_u64(&SharedStats->skip_rep))); +} /* * Called when any GUC is changed that affects prefetching. diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 52ac6d58423..a49a5758675 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -1878,6 +1878,8 @@ PerformWalRecovery(void) (errmsg("last completed transaction was at log time %s", timestamptz_to_str(xtime)))); + XLogPrefetchLogStatsOnRecoveryEnd(); + InRedo = false; } else diff --git a/src/include/access/xlogprefetcher.h b/src/include/access/xlogprefetcher.h index 56a81676d92..65d0ac6397d 100644 --- a/src/include/access/xlogprefetcher.h +++ b/src/include/access/xlogprefetcher.h @@ -34,6 +34,7 @@ typedef struct XLogPrefetcher XLogPrefetcher; extern void XLogPrefetchReconfigure(void); +extern void XLogPrefetchLogStatsOnRecoveryEnd(void); extern void XLogPrefetchResetStats(void); extern XLogPrefetcher *XLogPrefetcherAllocate(XLogReaderState *reader); -- 2.47.3
