Commit 2aa6e331 authored by Michael Paquier's avatar Michael Paquier

Skip redundant anti-wraparound vacuums

An anti-wraparound vacuum has to be by definition aggressive as it needs
to work on all the pages of a relation.  However it can happen that due
to some concurrent activity an anti-wraparound vacuum is marked as
non-aggressive, which makes it redundant with a previous run, and
it is actually useless as an anti-wraparound vacuum should process all
the pages of a relation.  This commit makes such vacuums to be skipped.

An anti-wraparound vacuum not aggressive can be found easily by mixing
low values of autovacuum_freeze_max_age (to control anti-wraparound) and
autovacuum_freeze_table_age (to control the aggressiveness).

28a8fa98 has added some extra logging printing all the possible
combinations of anti-wraparound and aggressive vacuums, which now gets
simplified as an anti-wraparound vacuum also non-aggressive gets
skipped.

Per discussion mainly between Andrew Dunstan, Robert Haas, Álvaro
Herrera, Kyotaro Horiguchi, Masahiko Sawada, and myself.

Author: Kyotaro Horiguchi, Michael Paquier
Reviewed-by: Andrew Dunstan, Álvaro Herrera
Discussion: https://postgr.es/m/20180914153554.562muwr3uwujno75@alvherre.pgsql
parent 47b3c266
...@@ -248,6 +248,23 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, ...@@ -248,6 +248,23 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params,
if (params->options & VACOPT_DISABLE_PAGE_SKIPPING) if (params->options & VACOPT_DISABLE_PAGE_SKIPPING)
aggressive = true; aggressive = true;
/*
* Normally the relfrozenxid for an anti-wraparound vacuum will be old
* enough to force an aggressive vacuum. However, a concurrent vacuum
* might have already done this work that the relfrozenxid in relcache has
* been updated. If that happens this vacuum is redundant, so skip it.
*/
if (params->is_wraparound && !aggressive)
{
ereport(DEBUG1,
(errmsg("skipping redundant vacuum to prevent wraparound of table \"%s.%s.%s\"",
get_database_name(MyDatabaseId),
get_namespace_name(RelationGetNamespace(onerel)),
RelationGetRelationName(onerel))));
pgstat_progress_end_command();
return;
}
vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats)); vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
vacrelstats->old_rel_pages = onerel->rd_rel->relpages; vacrelstats->old_rel_pages = onerel->rd_rel->relpages;
...@@ -375,10 +392,9 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, ...@@ -375,10 +392,9 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params,
initStringInfo(&buf); initStringInfo(&buf);
if (params->is_wraparound) if (params->is_wraparound)
{ {
if (aggressive) /* an anti-wraparound vacuum has to be aggressive */
Assert(aggressive);
msgfmt = _("automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n"); msgfmt = _("automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
else
msgfmt = _("automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment