public inbox for [email protected]
help / color / mirror / Atom feedFrom: Lakshmi N <[email protected]>
To: Bharath Rupireddy <[email protected]>
Cc: Jakub Wartak <[email protected]>
Cc: Thomas Munro <[email protected]>
Cc: SATYANARAYANA NARLAPURAM <[email protected]>
Cc: [email protected]
Subject: Re: log XLogPrefetch stats at end of recovery
Date: Thu, 26 Mar 2026 01:06:37 -0700
Message-ID: <CA+3i_M-nu4GcVf6NHf_M5p_-rY2ag7hO8aMfiPRhAB57UwBLZg@mail.gmail.com> (raw)
In-Reply-To: <CALj2ACVi1OtetQ_xNfvTMCWSFqS0FPvBosj-w4WJR0GyEnMPGA@mail.gmail.com>
References: <CA+3i_M-+WVyrRcfnxa4gt+KQUzH-LTQ8D2JCGE_O0WzJJtZfUg@mail.gmail.com>
<CAHg+QDfLh-yb+OacN6qPYF6H3SPDmVJUiors7vkSMq4yxfhNrA@mail.gmail.com>
<CALj2ACWovfe_A43LP5fi0mJenZ-i99_ux68YCzX6D2CO5mB-gg@mail.gmail.com>
<CAKZiRmwuKVHaQa_3PirbBqzoCKciuqcn2Tn4Df4d8icq4e3DCA@mail.gmail.com>
<CA+3i_M9s6T-jOsvSZk5y1HVvyz_RVbiEQZGdwPRQrw+zZcZ5Eg@mail.gmail.com>
<CAKZiRmz3n24HZVzQX4=25y4tMZ9PjYQjmbGhJkrziAQjdHru5g@mail.gmail.com>
<CA+3i_M8C+rK9vhwBm8U+ys2hbDifoBb4Xnws5Wmn2f4u7iqOpA@mail.gmail.com>
<CALj2ACVi1OtetQ_xNfvTMCWSFqS0FPvBosj-w4WJR0GyEnMPGA@mail.gmail.com>
Hi,
On Tue, Mar 24, 2026 at 8:23 PM Bharath Rupireddy <
[email protected]> wrote:
> Hi,
>
> On Tue, Mar 24, 2026 at 5:07 AM Lakshmi N <[email protected]> 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
Attachments:
[application/octet-stream] v3-0001-xlogprefetcher-redo-stats-logging.patch (2.9K, 3-v3-0001-xlogprefetcher-redo-stats-logging.patch)
download | inline diff:
From 64c96c20bb7345aad3dc6d3a1c2e9410b47ffdee Mon Sep 17 00:00:00 2001
From: Lakshmi N <[email protected]>
Date: Thu, 26 Mar 2026 01:02:57 -0700
Subject: [PATCH] xlogprefetcher: Log prefetch statistics at end of recovery
Add XLogPrefetchLogStats(), which emits a LOG message summarising the
prefetch counters (prefetch, hit, skip_init, skip_new, skip_fpw,
skip_rep) accumulated during recovery. The function is called from
PerformWalRecovery() immediately after the "redo done" message, giving
operators visibility into how effective WAL prefetching was over the
course of the recovery session.
No-op when recovery_prefetch = off.
---
src/backend/access/transam/xlogprefetcher.c | 25 +++++++++++++++++++++
src/backend/access/transam/xlogrecovery.c | 2 ++
src/include/access/xlogprefetcher.h | 1 +
3 files changed, 28 insertions(+)
diff --git a/src/backend/access/transam/xlogprefetcher.c b/src/backend/access/transam/xlogprefetcher.c
index c235eca7c51..879e6591c20 100644
--- a/src/backend/access/transam/xlogprefetcher.c
+++ b/src/backend/access/transam/xlogprefetcher.c
@@ -335,6 +335,31 @@ XLogPrefetchShmemInit(void)
}
}
+/*
+ * Log a summary of the XLogPrefetcher stats. Intended to be called
+ * at the end of recovery or when a standby is promoted.
+ */
+void
+XLogPrefetchLogStats(void)
+{
+ if (recovery_prefetch == RECOVERY_PREFETCH_OFF)
+ return;
+
+ elog(LOG,
+ "redo prefetch stats: prefetched %lu blocks, "
+ "skipped (%lu in the buffer pool, "
+ "%lu zero-initialized, "
+ "%lu non-existent, "
+ "%lu full page image, "
+ "%lu 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 6d2c4a86b96..7e5482fd976 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -1845,6 +1845,8 @@ PerformWalRecovery(void)
errmsg("redo done at %X/%08X system usage: %s",
LSN_FORMAT_ARGS(xlogreader->ReadRecPtr),
pg_rusage_show(&ru0)));
+
+ XLogPrefetchLogStats();
xtime = GetLatestXTime();
if (xtime)
ereport(LOG,
diff --git a/src/include/access/xlogprefetcher.h b/src/include/access/xlogprefetcher.h
index 7ec40c4b78b..5f9f48980cd 100644
--- a/src/include/access/xlogprefetcher.h
+++ b/src/include/access/xlogprefetcher.h
@@ -37,6 +37,7 @@ extern void XLogPrefetchReconfigure(void);
extern size_t XLogPrefetchShmemSize(void);
extern void XLogPrefetchShmemInit(void);
+extern void XLogPrefetchLogStats(void);
extern void XLogPrefetchResetStats(void);
extern XLogPrefetcher *XLogPrefetcherAllocate(XLogReaderState *reader);
--
2.43.0
view thread (11+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: log XLogPrefetch stats at end of recovery
In-Reply-To: <CA+3i_M-nu4GcVf6NHf_M5p_-rY2ag7hO8aMfiPRhAB57UwBLZg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox