Hi, Users may wish to speed up long-running vacuum of a large table by decreasing autovacuum_vacuum_cost_delay/vacuum_cost_delay, however the config file is only reloaded between tables (for autovacuum) or after the statement (for explicit vacuum). This has been brought up for autovacuum in [1].
Andres suggested that it might be possible to check ConfigReloadPending in vacuum_delay_point(), so I thought I would draft a rough patch and start a discussion. Since vacuum_delay_point() is also called by analyze and we do not want to reload the configuration file if we are in a user transaction, I widened the scope of the in_outer_xact variable in vacuum() and allowed analyze in a user transaction to default to the current configuration file reload cadence in PostgresMain(). I don't think I can set and leave vac_in_outer_xact the way I am doing it in this patch, since I use vac_in_outer_xact in vacuum_delay_point(), which I believe is reachable from codepaths that would not have called vacuum(). It seems that if a backend sets it, the outer transaction commits, and then the backend ends up calling vacuum_delay_point() in a different way later, it wouldn't be quite right. Apart from this, one higher level question I have is if there are other gucs whose modification would make reloading the configuration file during vacuum/analyze unsafe. - Melanie [1] https://www.postgresql.org/message-id/flat/22CA91B4-D341-4075-BD3C-4BAB52AF1E80%40amazon.com#37f05e33d2ce43680f96332fa1c0f3d4
From aea6fbfd93ab12e4e27869b755367ab8454e3eef Mon Sep 17 00:00:00 2001 From: Melanie Plageman <melanieplage...@gmail.com> Date: Thu, 23 Feb 2023 15:54:55 -0500 Subject: [PATCH v1] reload config file vac --- src/backend/commands/vacuum.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index aa79d9de4d..979d19222d 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -48,6 +48,7 @@ #include "pgstat.h" #include "postmaster/autovacuum.h" #include "postmaster/bgworker_internals.h" +#include "postmaster/interrupt.h" #include "storage/bufmgr.h" #include "storage/lmgr.h" #include "storage/proc.h" @@ -75,6 +76,7 @@ int vacuum_multixact_failsafe_age; /* A few variables that don't seem worth passing around as parameters */ static MemoryContext vac_context = NULL; static BufferAccessStrategy vac_strategy; +static bool vac_in_outer_xact = false; /* @@ -309,8 +311,7 @@ vacuum(List *relations, VacuumParams *params, static bool in_vacuum = false; const char *stmttype; - volatile bool in_outer_xact, - use_own_xacts; + volatile bool use_own_xacts; Assert(params != NULL); @@ -327,10 +328,10 @@ vacuum(List *relations, VacuumParams *params, if (params->options & VACOPT_VACUUM) { PreventInTransactionBlock(isTopLevel, stmttype); - in_outer_xact = false; + vac_in_outer_xact = false; } else - in_outer_xact = IsInTransactionBlock(isTopLevel); + vac_in_outer_xact = IsInTransactionBlock(isTopLevel); /* * Due to static variables vac_context, anl_context and vac_strategy, @@ -451,7 +452,7 @@ vacuum(List *relations, VacuumParams *params, Assert(params->options & VACOPT_ANALYZE); if (IsAutoVacuumWorkerProcess()) use_own_xacts = true; - else if (in_outer_xact) + else if (vac_in_outer_xact) use_own_xacts = false; else if (list_length(relations) > 1) use_own_xacts = true; @@ -469,7 +470,7 @@ vacuum(List *relations, VacuumParams *params, */ if (use_own_xacts) { - Assert(!in_outer_xact); + Assert(!vac_in_outer_xact); /* ActiveSnapshot is not set by autovacuum */ if (ActiveSnapshotSet()) @@ -521,7 +522,7 @@ vacuum(List *relations, VacuumParams *params, } analyze_rel(vrel->oid, vrel->relation, params, - vrel->va_cols, in_outer_xact, vac_strategy); + vrel->va_cols, vac_in_outer_xact, vac_strategy); if (use_own_xacts) { @@ -2214,6 +2215,12 @@ vacuum_delay_point(void) WAIT_EVENT_VACUUM_DELAY); ResetLatch(MyLatch); + if (ConfigReloadPending && !vac_in_outer_xact) + { + ConfigReloadPending = false; + ProcessConfigFile(PGC_SIGHUP); + } + VacuumCostBalance = 0; /* update balance values for workers */ -- 2.37.2