public inbox for [email protected]  
help / color / mirror / Atom feed
From: Melanie Plageman <[email protected]>
To: Andres Freund <[email protected]>
Cc: [email protected]
Cc: Heikki Linnakangas <[email protected]>
Cc: Peter Geoghegan <[email protected]>
Subject: Re: Unlogged rel fake lsn vs GetVictimBuffer()
Date: Wed, 11 Mar 2026 14:03:36 -0400
Message-ID: <CAAKRu_b2ujALda3VrGOzoQT7Nm3WRrOEVWPnmHY9qt0R4nYVNA@mail.gmail.com> (raw)
In-Reply-To: <CAAKRu_Ypx4+a3ycAJm276E0F3UiQfo-XeusOmjOzOajHCLNHZA@mail.gmail.com>
References: <fmkqmyeyy7bdpvcgkheb6yaqewemkik3ls6aaveyi5ibmvtxnd@nu2kvy5rq3a6>
	<CAAKRu_a0w7wVZCysJ1s6tEPkdsGyYR4iBSEUefa3Y2nWLx2vSw@mail.gmail.com>
	<tsoi4ahsvxl7ln3ltmkhi4wn6p5b36uiokll5j2mzsfhpl6i7w@brc33vsxcdum>
	<CAAKRu_b8+MYK1JsppdtUNV-f3UgEg3F7YihiSWvxoHeWgEN7BA@mail.gmail.com>
	<CAAKRu_bwpjonq5ag2EBm2xDRRyfU8PpCFioG1o=8Ed9VKkRBfQ@mail.gmail.com>
	<CAAKRu_Ypx4+a3ycAJm276E0F3UiQfo-XeusOmjOzOajHCLNHZA@mail.gmail.com>

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


Attachments:

  [text/x-patch] v3-0001-Avoid-WAL-flush-checks-for-unlogged-buffers-in-Ge.patch (1.6K, 2-v3-0001-Avoid-WAL-flush-checks-for-unlogged-buffers-in-Ge.patch)
  download | inline diff:
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



view thread (7+ 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]
  Subject: Re: Unlogged rel fake lsn vs GetVictimBuffer()
  In-Reply-To: <CAAKRu_b2ujALda3VrGOzoQT7Nm3WRrOEVWPnmHY9qt0R4nYVNA@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