mirror of
https://github.com/postgres/postgres.git
synced 2025-12-04 12:02:48 +03:00
Separate vacuum cost variables from GUCs
Vacuum code run both by autovacuum workers and a backend doing VACUUM/ANALYZE previously inspected VacuumCostLimit and VacuumCostDelay, which are the global variables backing the GUCs vacuum_cost_limit and vacuum_cost_delay. Autovacuum workers needed to override these variables with their own values, derived from autovacuum_vacuum_cost_limit and autovacuum_vacuum_cost_delay and worker cost limit balancing logic. This led to confusing code which, in some cases, both derived and set a new value of VacuumCostLimit from VacuumCostLimit. In preparation for refreshing these GUC values more often, introduce new, independent global variables and add a function to update them using the GUCs and existing logic. Per suggestion by Kyotaro Horiguchi Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAAKRu_ZngzqnEODc7LmS1NH04Kt6Y9huSjz5pp7%2BDXhrjDA0gw%40mail.gmail.com
This commit is contained in:
@@ -1773,16 +1773,24 @@ FreeWorkerInfo(int code, Datum arg)
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the cost-based delay parameters, so that multiple workers consume
|
||||
* each a fraction of the total available I/O.
|
||||
* Update vacuum cost-based delay-related parameters for autovacuum workers and
|
||||
* backends executing VACUUM or ANALYZE using the value of relevant GUCs and
|
||||
* global state. This must be called during setup for vacuum and after every
|
||||
* config reload to ensure up-to-date values.
|
||||
*/
|
||||
void
|
||||
AutoVacuumUpdateDelay(void)
|
||||
VacuumUpdateCosts(void)
|
||||
{
|
||||
if (MyWorkerInfo)
|
||||
{
|
||||
VacuumCostDelay = MyWorkerInfo->wi_cost_delay;
|
||||
VacuumCostLimit = MyWorkerInfo->wi_cost_limit;
|
||||
vacuum_cost_delay = MyWorkerInfo->wi_cost_delay;
|
||||
vacuum_cost_limit = MyWorkerInfo->wi_cost_limit;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Must be explicit VACUUM or ANALYZE */
|
||||
vacuum_cost_delay = VacuumCostDelay;
|
||||
vacuum_cost_limit = VacuumCostLimit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2311,8 +2319,6 @@ do_autovacuum(void)
|
||||
autovac_table *tab;
|
||||
bool isshared;
|
||||
bool skipit;
|
||||
double stdVacuumCostDelay;
|
||||
int stdVacuumCostLimit;
|
||||
dlist_iter iter;
|
||||
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
@@ -2415,14 +2421,6 @@ do_autovacuum(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remember the prevailing values of the vacuum cost GUCs. We have to
|
||||
* restore these at the bottom of the loop, else we'll compute wrong
|
||||
* values in the next iteration of autovac_balance_cost().
|
||||
*/
|
||||
stdVacuumCostDelay = VacuumCostDelay;
|
||||
stdVacuumCostLimit = VacuumCostLimit;
|
||||
|
||||
/* Must hold AutovacuumLock while mucking with cost balance info */
|
||||
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
|
||||
|
||||
@@ -2436,7 +2434,7 @@ do_autovacuum(void)
|
||||
autovac_balance_cost();
|
||||
|
||||
/* set the active cost parameters from the result of that */
|
||||
AutoVacuumUpdateDelay();
|
||||
VacuumUpdateCosts();
|
||||
|
||||
/* done */
|
||||
LWLockRelease(AutovacuumLock);
|
||||
@@ -2533,10 +2531,6 @@ deleted:
|
||||
MyWorkerInfo->wi_tableoid = InvalidOid;
|
||||
MyWorkerInfo->wi_sharedrel = false;
|
||||
LWLockRelease(AutovacuumScheduleLock);
|
||||
|
||||
/* restore vacuum cost GUCs for the next iteration */
|
||||
VacuumCostDelay = stdVacuumCostDelay;
|
||||
VacuumCostLimit = stdVacuumCostLimit;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user