8000 Don't balance vacuum cost delay when per-table settings are in effect · pykello/postgres@06646f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06646f5

Browse files
committed
Don't balance vacuum cost delay when per-table settings are in effect
When there are cost-delay-related storage options set for a table, trying to make that table participate in the autovacuum cost-limit balancing algorithm produces undesirable results: instead of using the configured values, the global values are always used, as illustrated by Mark Kirkwood in http://www.postgresql.org/message-id/52FACF15.8020507@catalyst.net.nz Since the mechanism is already complicated, just disable it for those cases rather than trying to make it cope. There are undesirable side-effects from this too, namely that the total I/O impact on the system will be higher whenever such tables are vacuumed. However, this is seen as less harmful than slowing down vacuum, because that would cause bloat to accumulate. Anyway, in the new system it is possible to tweak options to get t 10000 he precise behavior one wants, whereas with the previous system one was simply hosed. This has been broken forever, so backpatch to all supported branches. This might affect systems where cost_limit and cost_delay have been set for individual tables.
1 parent f270a16 commit 06646f5

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

doc/src/sgml/maintenance.sgml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,13 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
688688
</para>
689689

690690
<para>
691-
When multiple workers are running, the cost limit is
691+
When multiple workers are running, the cost delay parameters are
692692
<quote>balanced</quote> among all the running workers, so that the
693-
total impact on the system is the same, regardless of the number
694-
of workers actually running.
693+
total I/O impact on the system is the same regardless of the number
694+
of workers actually running. However, any workers processing tables whose
695+
<literal>autovacuum_vacuum_cost_delay</> or
696+
<literal>autovacuum_vacuum_cost_limit</> have been set are not considered
697+
in the balancing algorithm.
695698
</para>
696699
</sect2>
697700
</sect1>

src/backend/postmaster/autovacuum.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ typedef struct autovac_table
177177
int at_freeze_table_age;
178178
int at_vacuum_cost_delay;
179179
int at_vacuum_cost_limit;
180+
bool at_dobalance;
180181
bool at_wraparound;
181182
char *at_relname;
182183
char *at_nspname;
@@ -207,6 +208,7 @@ typedef struct WorkerInfoData
207208
Oid wi_tableoid;
208209
PGPROC *wi_proc;
209210
TimestampTz wi_launchtime;
211+
bool wi_dobalance;
210212
int wi_cost_delay;
211213
int wi_cost_limit;
212214
int wi_cost_limit_base;
@@ -1680,6 +1682,7 @@ FreeWorkerInfo(int code, Datum arg)
16801682
MyWorkerInfo->wi_tableoid = InvalidOid;
16811683
MyWorkerInfo->wi_proc = NULL;
16821684
MyWorkerInfo->wi_launchtime = 0;
1685+
MyWorkerInfo->wi_dobalance = false;
16831686
MyWorkerInfo->wi_cost_delay = 0;
16841687
MyWorkerInfo->wi_cost_limit = 0;
16851688
MyWorkerInfo->wi_cost_limit_base = 0;
@@ -1739,14 +1742,15 @@ autovac_balance_cost(void)
17391742
if (vac_cost_limit <= 0 || vac_cost_delay <= 0)
17401743
return;
17411744

1742-
/* caculate the total base cost limit of active workers */
1745+
/* calculate the total base cost limit of participating active workers */
17431746
cost_total = 0.0;
17441747
worker = (WorkerInfo) SHMQueueNext(&AutoVacuumShmem->av_runningWorkers,
17451748
&AutoVacuumShmem->av_runningWorkers,
17461749
offsetof(WorkerInfoData, wi_links));
17471750
while (worker)
17481751
{
17491752
if (worker->wi_proc != NULL &&
1753+
worker->wi_dobalance &&
17501754
worker->wi_cost_limit_base > 0 && worker->wi_cost_delay > 0)
17511755
cost_total +=
17521756
(double) worker->wi_cost_limit_base / worker->wi_cost_delay;
@@ -1755,6 +1759,7 @@ autovac_balance_cost(void)
17551759
&worker->wi_links,
17561760
offsetof(WorkerInfoData, wi_links));
17571761
}
1762+
17581763
/* there are no cost limits -- nothing to do */
17591764
if (cost_total <= 0)
17601765
return;
@@ -1770,6 +1775,7 @@ autovac_balance_cost(void)
17701775
while (worker)
17711776
{
17721777
if (worker->wi_proc != NULL &&
1778+
worker->wi_dobalance &&
17731779
worker->wi_cost_limit_base > 0 && worker->wi_cost_delay > 0)
17741780
{
17751781
int limit = (int)
@@ -1784,12 +1790,14 @@ autovac_balance_cost(void)
17841790
worker->wi_cost_limit = Max(Min(limit,
17851791
worker->wi_cost_limit_base),
17861792
1);
1793+
}
17871794

1788-
elog(DEBUG2, "autovac_balance_cost(pid=%u db=%u, rel=%u, cost_limit=%d, cost_limit_base=%d, cost_delay=%d)",
1795+
if (worker->wi_proc != NULL)
1796+
elog(DEBUG2, "autovac_balance_cost(pid=%u db=%u, rel=%u, dobalance=%s cost_limit=%d, cost_limit_base=%d, cost_delay=%d)",
17891797
worker->wi_proc->pid, worker->wi_dboid, worker->wi_tableoid,
1798+
worker->wi_dobalance ? "yes" : "no",
17901799
worker->wi_cost_limit, worker->wi_cost_limit_base,
17911800
worker->wi_cost_delay);
1792-
}
17931801

17941802
worker = (WorkerInfo) SHMQueueNext(&AutoVacuumShmem->av_runningWorkers,
17951803
&worker->wi_links,
@@ -2259,6 +2267,7 @@ do_autovacuum(void)
22592267
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
22602268

22612269
/* advertise my cost delay parameters for the balancing algorithm */
2270+
MyWorkerInfo->wi_dobalance = tab->at_dobalance;
22622271
MyWorkerInfo->wi_cost_delay = tab->at_vacuum_cost_delay;
22632272
MyWorkerInfo->wi_cost_limit = tab->at_vacuum_cost_limit;
22642273
MyWorkerInfo->wi_cost_limit_base = tab->at_vacuum_cost_limit;
@@ -2539,6 +2548,14 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
25392548
tab->at_relname = NULL;
25402549
tab->at_nspname = NULL;
25412550
tab->at_datname = NULL;
2551+
2552+
/*
2553+
* If any of the cost delay parameters has been set individually for
2554+
* this table, disable the balancing algorithm.
2555+
*/
2556+
tab->at_dobalance =
2557+
!(avopts && (avopts->vacuum_cost_limit > 0 ||
2558+
avopts->vacuum_cost_delay > 0));
25422559
}
25432560

25442561
heap_freetuple(classTup);

0 commit comments

Comments
 (0)
0