Skip to content

Commit 71a8251

Browse files
Make vacuum failsafe_active globally visible
While vacuuming a table in failsafe mode, VacuumCostActive should not be re-enabled. This currently isn't a problem because vacuum cost parameters are only refreshed in between vacuuming tables and failsafe status is reset for every table. In preparation for allowing vacuum cost parameters to be updated more frequently, elevate LVRelState->failsafe_active to a global, VacuumFailsafeActive, which will be checked when determining whether or not to re-enable vacuum cost-related delays. 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
1 parent 5499706 commit 71a8251

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/backend/access/heap/vacuumlazy.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ typedef struct LVRelState
153153
bool aggressive;
154154
/* Use visibility map to skip? (disabled by DISABLE_PAGE_SKIPPING) */
155155
bool skipwithvm;
156-
/* Wraparound failsafe has been triggered? */
157-
bool failsafe_active;
158156
/* Consider index vacuuming bypass optimization? */
159157
bool consider_bypass_optimization;
160158

@@ -391,7 +389,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
391389
Assert(params->index_cleanup != VACOPTVALUE_UNSPECIFIED);
392390
Assert(params->truncate != VACOPTVALUE_UNSPECIFIED &&
393391
params->truncate != VACOPTVALUE_AUTO);
394-
vacrel->failsafe_active = false;
392+
VacuumFailsafeActive = false;
395393
vacrel->consider_bypass_optimization = true;
396394
vacrel->do_index_vacuuming = true;
397395
vacrel->do_index_cleanup = true;
@@ -709,7 +707,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
709707
}
710708
else
711709
{
712-
if (!vacrel->failsafe_active)
710+
if (!VacuumFailsafeActive)
713711
appendStringInfoString(&buf, _("index scan bypassed: "));
714712
else
715713
appendStringInfoString(&buf, _("index scan bypassed by failsafe: "));
@@ -2293,7 +2291,7 @@ lazy_vacuum(LVRelState *vacrel)
22932291
* vacuuming or heap vacuuming. This VACUUM operation won't end up
22942292
* back here again.
22952293
*/
2296-
Assert(vacrel->failsafe_active);
2294+
Assert(VacuumFailsafeActive);
22972295
}
22982296

22992297
/*
@@ -2374,7 +2372,7 @@ lazy_vacuum_all_indexes(LVRelState *vacrel)
23742372
*/
23752373
Assert(vacrel->num_index_scans > 0 ||
23762374
vacrel->dead_items->num_items == vacrel->lpdead_items);
2377-
Assert(allindexes || vacrel->failsafe_active);
2375+
Assert(allindexes || VacuumFailsafeActive);
23782376

23792377
/*
23802378
* Increase and report the number of index scans.
@@ -2616,12 +2614,12 @@ static bool
26162614
lazy_check_wraparound_failsafe(LVRelState *vacrel)
26172615
{
26182616
/* Don't warn more than once per VACUUM */
2619-
if (vacrel->failsafe_active)
2617+
if (VacuumFailsafeActive)
26202618
return true;
26212619

26222620
if (unlikely(vacuum_xid_failsafe_check(&vacrel->cutoffs)))
26232621
{
2624-
vacrel->failsafe_active = true;
2622+
VacuumFailsafeActive = true;
26252623

26262624
/*
26272625
* Abandon use of a buffer access strategy to allow use of all of
@@ -2820,7 +2818,7 @@ should_attempt_truncation(LVRelState *vacrel)
28202818
{
28212819
BlockNumber possibly_freeable;
28222820

2823-
if (!vacrel->do_rel_truncate || vacrel->failsafe_active ||
2821+
if (!vacrel->do_rel_truncate || VacuumFailsafeActive ||
28242822
old_snapshot_threshold >= 0)
28252823
return false;
28262824

src/backend/commands/vacuum.c

+15
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ int vacuum_multixact_freeze_table_age;
7272
int vacuum_failsafe_age;
7373
int vacuum_multixact_failsafe_age;
7474

75+
/*
76+
* VacuumFailsafeActive is a defined as a global so that we can determine
77+
* whether or not to re-enable cost-based vacuum delay when vacuuming a table.
78+
* If failsafe mode has been engaged, we will not re-enable cost-based delay
79+
* for the table until after vacuuming has completed, regardless of other
80+
* settings.
81+
*
82+
* Only VACUUM code should inspect this variable and only table access methods
83+
* should set it to true. In Table AM-agnostic VACUUM code, this variable is
84+
* inspected to determine whether or not to allow cost-based delays. Table AMs
85+
* are free to set it if they desire this behavior, but it is false by default
86+
* and reset to false in between vacuuming each relation.
87+
*/
88+
bool VacuumFailsafeActive = false;
89+
7590
/*
7691
* Variables for cost-based parallel vacuum. See comments atop
7792
* compute_parallel_delay to understand how it works.

src/include/commands/vacuum.h

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ extern PGDLLIMPORT pg_atomic_uint32 *VacuumSharedCostBalance;
306306
extern PGDLLIMPORT pg_atomic_uint32 *VacuumActiveNWorkers;
307307
extern PGDLLIMPORT int VacuumCostBalanceLocal;
308308

309+
extern PGDLLIMPORT bool VacuumFailsafeActive;
309310

310311
/* in commands/vacuum.c */
311312
extern void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel);

0 commit comments

Comments
 (0)