On Tue, Mar 10, 2026 at 3:46 PM Melanie Plageman
<[email protected]> wrote:
>
> Now, I'm thinking that I should allow BufferNeedsWALFlush() to be
> called on local buffers. I removed it in v2 because Andres mentioned
> it could never happen when called by StrategyRejectBuffer() (because
> we don't use strategies on local buffers), but there's no reason
> BufferNeedsWALFlush() can't be used more widely in the future.

Well, due to 82467f627bd478569de, this is now a tiny one-liner. Will
push in an hour or so barring objections.

- Melanie
From 0e26a8f6b54121432f2b5ef78764c8586521c766 Mon Sep 17 00:00:00 2001
From: Melanie Plageman <[email protected]>
Date: Wed, 11 Mar 2026 13:57:13 -0400
Subject: [PATCH v3] Avoid WAL-flush checks for unlogged buffers in
 GetVictimBuffer()

GetVictimBuffer() rejects a victim buffer if it is from a bulkread
strategy ring and reusing it would require flushing WAL. Unlogged table
buffers can have fake LSNs (e.g. unlogged GiST pages) and calling
XLogNeedsFlush() on a fake LSN is meaningless.

This is a bit of future-proofing because currently the bulkread strategy
is not used for relations with fake LSNs.

Author: Melanie Plageman <[email protected]>
Reported-by: Andres Freund <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Earlier version reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/flat/fmkqmyeyy7bdpvcgkheb6yaqewemkik3ls6aaveyi5ibmvtxnd%40nu2kvy5rq3a6
---
 src/backend/storage/buffer/bufmgr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 0546ee0193c..26b195b5359 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2527,8 +2527,9 @@ again:
 		{
 			XLogRecPtr	lsn = BufferGetLSN(buf_hdr);
 
-			if (XLogNeedsFlush(lsn)
-				&& StrategyRejectBuffer(strategy, buf_hdr, from_ring))
+			if (buf_state & BM_PERMANENT &&
+				XLogNeedsFlush(lsn) &&
+				StrategyRejectBuffer(strategy, buf_hdr, from_ring))
 			{
 				LockBuffer(buf, BUFFER_LOCK_UNLOCK);
 				UnpinBuffer(buf_hdr);
-- 
2.43.0

Reply via email to