pgsql: Tighten up VACUUM's approach to setting VM bits. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Tighten up VACUUM's approach to setting VM bits.
Date
Msg-id E1pHTOF-00408U-Cv@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Tighten up VACUUM's approach to setting VM bits.

Tighten up the way that visibilitymap_set() is called: request that both
the all-visible and all-frozen bits get set whenever the all-frozen bit
is set, regardless of what we think we know about the present state of
the all-visible bit.  Also make sure that the page level PD_ALL_VISIBLE
flag is set in the same code path.

In practice there doesn't seem to be a concrete scenario in which the
previous approach could lead to inconsistencies.  It was almost possible
in scenarios involving concurrent HOT updates from transactions that
abort, but (unlike pruning) freezing can never remove XIDs > VACUUM's
OldestXmin, even those from transactions that are known to have aborted.
That was protective here.

These issues have been around since commit a892234f83, which added the
all-frozen bit to the VM fork.  There is no known live bug here, so no
backpatch.

In passing, add some defensive assertions to catch the issue, and stop
reading the existing state of the VM when setting the VM in VACUUM's
final heap pass.  We already know that affected pages must have had at
least one LP_DEAD item before we set it LP_UNUSED, so there is no point
in reading the VM when it is set like this.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAH2-WznuNGSzF8v6OsgjaC5aYsb3cZ6HW6MLm30X0d65cmSH6A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/980ae173108e353045e5ab4a842bb21e9dfe6715

Modified Files
--------------
src/backend/access/heap/vacuumlazy.c    | 96 ++++++++++++++++++++-------------
src/backend/access/heap/visibilitymap.c |  9 ++--
2 files changed, 65 insertions(+), 40 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Assorted improvements to SECURITY DEFINER functions documentatio
Next
From: Tom Lane
Date:
Subject: pgsql: Create common infrastructure for cross-version upgrade testing.