|
48 | 48 | #include "pgstat.h"
|
49 | 49 | #include "postmaster/autovacuum.h"
|
50 | 50 | #include "postmaster/bgworker_internals.h"
|
| 51 | +#include "postmaster/interrupt.h" |
51 | 52 | #include "storage/bufmgr.h"
|
52 | 53 | #include "storage/lmgr.h"
|
53 | 54 | #include "storage/pmsignal.h"
|
@@ -523,9 +524,9 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
|
523 | 524 | {
|
524 | 525 | ListCell *cur;
|
525 | 526 |
|
526 |
| - VacuumUpdateCosts(); |
527 | 527 | in_vacuum = true;
|
528 |
| - VacuumCostActive = (vacuum_cost_delay > 0); |
| 528 | + VacuumFailsafeActive = false; |
| 529 | + VacuumUpdateCosts(); |
529 | 530 | VacuumCostBalance = 0;
|
530 | 531 | VacuumPageHit = 0;
|
531 | 532 | VacuumPageMiss = 0;
|
@@ -579,12 +580,20 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
|
579 | 580 | CommandCounterIncrement();
|
580 | 581 | }
|
581 | 582 | }
|
| 583 | + |
| 584 | + /* |
| 585 | + * Ensure VacuumFailsafeActive has been reset before vacuuming the |
| 586 | + * next relation. |
| 587 | + */ |
| 588 | + VacuumFailsafeActive = false; |
582 | 589 | }
|
583 | 590 | }
|
584 | 591 | PG_FINALLY();
|
585 | 592 | {
|
586 | 593 | in_vacuum = false;
|
587 | 594 | VacuumCostActive = false;
|
| 595 | + VacuumFailsafeActive = false; |
| 596 | + VacuumCostBalance = 0; |
588 | 597 | }
|
589 | 598 | PG_END_TRY();
|
590 | 599 |
|
@@ -2245,7 +2254,28 @@ vacuum_delay_point(void)
|
2245 | 2254 | /* Always check for interrupts */
|
2246 | 2255 | CHECK_FOR_INTERRUPTS();
|
2247 | 2256 |
|
2248 |
| - if (!VacuumCostActive || InterruptPending) |
| 2257 | + if (InterruptPending || |
| 2258 | + (!VacuumCostActive && !ConfigReloadPending)) |
| 2259 | + return; |
| 2260 | + |
| 2261 | + /* |
| 2262 | + * Autovacuum workers should reload the configuration file if requested. |
| 2263 | + * This allows changes to [autovacuum_]vacuum_cost_limit and |
| 2264 | + * [autovacuum_]vacuum_cost_delay to take effect while a table is being |
| 2265 | + * vacuumed or analyzed. |
| 2266 | + */ |
| 2267 | + if (ConfigReloadPending && IsAutoVacuumWorkerProcess()) |
| 2268 | + { |
| 2269 | + ConfigReloadPending = false; |
| 2270 | + ProcessConfigFile(PGC_SIGHUP); |
| 2271 | + VacuumUpdateCosts(); |
| 2272 | + } |
| 2273 | + |
| 2274 | + /* |
| 2275 | + * If we disabled cost-based delays after reloading the config file, |
| 2276 | + * return. |
| 2277 | + */ |
| 2278 | + if (!VacuumCostActive) |
2249 | 2279 | return;
|
2250 | 2280 |
|
2251 | 2281 | /*
|
@@ -2278,7 +2308,15 @@ vacuum_delay_point(void)
|
2278 | 2308 |
|
2279 | 2309 | VacuumCostBalance = 0;
|
2280 | 2310 |
|
2281 |
| - VacuumUpdateCosts(); |
| 2311 | + /* |
| 2312 | + * Balance and update limit values for autovacuum workers. We must do |
| 2313 | + * this periodically, as the number of workers across which we are |
| 2314 | + * balancing the limit may have changed. |
| 2315 | + * |
| 2316 | + * TODO: There may be better criteria for determining when to do this |
| 2317 | + * besides "check after napping". |
| 2318 | + */ |
| 2319 | + AutoVacuumUpdateCostLimit(); |
2282 | 2320 |
|
2283 | 2321 | /* Might have gotten an interrupt while sleeping */
|
2284 | 2322 | CHECK_FOR_INTERRUPTS();
|
|
0 commit comments