diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 5c554f9465..82be8c81f3 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -248,6 +248,25 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, if (params->options & VACOPT_DISABLE_PAGE_SKIPPING) aggressive = true; + /* + * When running an anti-wraparound vacuum, we expect relfrozenxid to be + * old enough so as aggressive is always set. If this is not the case, + * it could be possible that another concurrent vacuum process has done + * the work for this relation so that relfrozenxid in relcache has + * already been moved forward enough, causing this vacuum run to be + * non-aggressive. If that happens, note that this relation no longer + * needs to be vacuumed, so just skip it. + */ + if (params->is_wraparound && !aggressive) + { + ereport(LOG, + (errmsg_internal("found vacuum to prevent wraparound of table \"%s.%s.%s\" to be not aggressive, so skipping", + get_database_name(MyDatabaseId), + get_namespace_name(RelationGetNamespace(onerel)), + RelationGetRelationName(onerel)))); + return; + } + vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats)); vacrelstats->old_rel_pages = onerel->rd_rel->relpages; @@ -375,10 +394,9 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, initStringInfo(&buf); if (params->is_wraparound) { - if (aggressive) - 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"); + /* 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"); } else {