pgsql: Add wraparound failsafe to VACUUM.

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add wraparound failsafe to VACUUM.
Date: 2021-04-07 19:39:07
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Add wraparound failsafe to VACUUM.

Add a failsafe mechanism that is triggered by VACUUM when it notices
that the table's relfrozenxid and/or relminmxid are dangerously far in
the past. VACUUM checks the age of the table dynamically, at regular

When the failsafe triggers, VACUUM takes extraordinary measures to
finish as quickly as possible so that relfrozenxid and/or relminmxid can
be advanced. VACUUM will stop applying any cost-based delay that may be
in effect. VACUUM will also bypass any further index vacuuming and heap
vacuuming -- it only completes whatever remaining pruning and freezing
is required. Bypassing index/heap vacuuming is enabled by commit
8523492d, which made it possible to dynamically trigger the mechanism
already used within VACUUM when it is run with INDEX_CLEANUP off.

It is expected that the failsafe will almost always trigger within an
autovacuum to prevent wraparound, long after the autovacuum began.
However, the failsafe mechanism can trigger in any VACUUM operation.
Even in a non-aggressive VACUUM, where we're likely to not advance
relfrozenxid, it still seems like a good idea to finish off remaining
pruning and freezing. An aggressive/anti-wraparound VACUUM will be
launched immediately afterwards. Note that the anti-wraparound VACUUM
that follows will itself trigger the failsafe, usually before it even
begins its first (and only) pass over the heap.

The failsafe is controlled by two new GUCs: vacuum_failsafe_age, and
vacuum_multixact_failsafe_age. There are no equivalent reloptions,
since that isn't expected to be useful. The GUCs have rather high
defaults (both default to 1.6 billion), and are expected to generally
only be used to make the failsafe trigger sooner/more frequently.

Author: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Author: Peter Geoghegan <pg(at)bowt(dot)ie>



Modified Files
doc/src/sgml/config.sgml | 66 ++++++++++
src/backend/access/heap/vacuumlazy.c | 176 ++++++++++++++++++++++++--
src/backend/commands/vacuum.c | 58 +++++++++
src/backend/utils/misc/guc.c | 23 +++-
src/backend/utils/misc/postgresql.conf.sample | 2 +
src/include/commands/vacuum.h | 4 +
6 files changed, 316 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2021-04-07 19:53:35 pgsql: SQL-standard function body
Previous Message Bruce Momjian 2021-04-07 18:04:09 pgsql: Make use of in-core query id added by commit 5fd9dfa5f5