On Thu, Aug 6, 2026 at 4:42 PM Melanie Plageman <[email protected]> wrote: > > Instead, I propose we just take a small hit to the accounting and > simply clear the ReadBuffersOperations->strategy even of in-progress > IOs. It should only misattribute a bit of wait time -- and only for a > limited number of IOs once -- when we enter failsafe mode. It makes > for a simple, backpatchable solution. I've attached here what I intend > to commit later today.
Okay, I pushed it, but right after pushing it I suddenly had the thought, omg, it loops through all the ReadBuffersOperations and sets them to NULL for _every_ page after entering failsafe mode. And we obviously ought to fix that. Proposed patch to do that with a simple local variable is attached. This time I'll let this one sit for longer before pushing to avoid mistakes like last time. - Melanie
From 6942d141add0d40499d41d341d438de0d6e16b51 Mon Sep 17 00:00:00 2001 From: Melanie Plageman <[email protected]> Date: Thu, 6 Aug 2026 17:49:12 -0400 Subject: [PATCH] Only clear VACUUM's read stream strategy once in failsafe mode 112c2683807b4d690 restored failsafe vacuum's abandonment of a buffer access strategy by clearing the ReadBuffersOperations' strategy references. But it did so in lazy_scan_heap()'s main loop, meaning it looped through all the ReadBuffersOperations once per block after failsafe was engaged. Track it with a local flag and clear the strategy only once. Backpatch-through: 18 --- src/backend/access/heap/vacuumlazy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index d346344934c..cb9f23436f1 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1285,6 +1285,7 @@ lazy_scan_heap(LVRelState *vacrel) BlockNumber orig_eager_scan_success_limit = vacrel->eager_scan_remaining_successes; /* for logging */ Buffer vmbuffer = InvalidBuffer; + bool strategy_cleared = false; const int initprog_index[] = { PROGRESS_VACUUM_PHASE, PROGRESS_VACUUM_TOTAL_HEAP_BLKS, @@ -1389,10 +1390,14 @@ lazy_scan_heap(LVRelState *vacrel) * If the wraparound failsafe has engaged -- either via the check * above or during index vacuuming invoked from this loop -- stop * using the buffer access strategy so that the rest of the vacuum may - * use all of shared buffers. + * use all of shared buffers. Failsafe mode stays engaged once + * triggered, so we only need to do this once. */ - if (unlikely(VacuumFailsafeActive)) + if (unlikely(VacuumFailsafeActive) && !strategy_cleared) + { read_stream_clear_strategy(stream); + strategy_cleared = true; + } buf = read_stream_next_buffer(stream, &per_buffer_data); -- 2.47.3
