From 7c25cdb1ebf64b1e1c9053ca27f9552c9a528a12 Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Fri, 7 Aug 2026 09:59:55 -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. Reported-by: Melanie Plageman Discussion: https://postgr.es/m/CAAKRu_Zse14nSNeCgtnE1LUAH8Of7OmYR%2BCc3O_DAzxt3m6T-g%40mail.gmail.com 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 7d22d0e7439..989fb491e55 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1206,6 +1206,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, @@ -1311,10 +1312,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);