From 967a25ec5ad9d515a432360dfb9c67d92d8ea491 Mon Sep 17 00:00:00 2001 From: Satya Narlapuram Date: Tue, 5 May 2026 07:12:10 +0000 Subject: [PATCH] Apply data-checksum worker throttling parameters The DataChecksumsWorker accepts cost_delay and cost_limit parameters from pg_enable_data_checksums() so users can throttle the rewrite I/O caused by enabling checksums online, but the values were silently ignored: * The worker assigned the user-supplied values to VacuumCostDelay and VacuumCostLimit (the GUC-bound globals in globals.c), but vacuum_delay_point() consults vacuum_cost_delay/vacuum_cost_limit declared in vacuum.c. The two pairs are kept in sync by VacuumUpdateCosts(), which the worker never called. As a result the napping formula in vacuum_delay_point() always saw the boot defaults (vacuum_cost_delay = 0), so no throttling occurred. * The worker also reset VacuumCostPageHit/Miss/Dirty to 0 at startup. With all per-page weights at zero, VacuumCostBalance never reaches vacuum_cost_limit, which would defeat the throttling on its own even if the first issue had not existed. Fix both issues by calling VacuumUpdateCosts() after assigning the user values (both at worker startup and on the runtime cost-update path), and by leaving the page-cost weights at their GUC-controlled defaults. --- src/backend/postmaster/datachecksum_state.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/datachecksum_state.c b/src/backend/postmaster/datachecksum_state.c index d0d6acdd..c7c05933 100644 --- a/src/backend/postmaster/datachecksum_state.c +++ b/src/backend/postmaster/datachecksum_state.c @@ -1538,14 +1538,14 @@ DataChecksumsWorkerMain(Datum arg) * provides rather than inventing something bespoke. This is an internal * implementation detail and care should be taken to avoid it bleeding * through to the user to avoid confusion. + * + * VacuumUpdateCosts() propagates the values to the variables actually + * read by vacuum_delay_point(). */ VacuumCostDelay = DataChecksumState->cost_delay; VacuumCostLimit = DataChecksumState->cost_limit; - VacuumCostActive = (VacuumCostDelay > 0); + VacuumUpdateCosts(); VacuumCostBalance = 0; - VacuumCostPageHit = 0; - VacuumCostPageMiss = 0; - VacuumCostPageDirty = 0; /* * Create and set the vacuum strategy as our buffer strategy. @@ -1602,7 +1602,7 @@ DataChecksumsWorkerMain(Datum arg) costs_updated = true; VacuumCostDelay = DataChecksumState->launch_cost_delay; VacuumCostLimit = DataChecksumState->launch_cost_limit; - VacuumCostActive = (VacuumCostDelay > 0); + VacuumUpdateCosts(); DataChecksumState->cost_delay = DataChecksumState->launch_cost_delay; DataChecksumState->cost_limit = DataChecksumState->launch_cost_limit; -- 2.43.0