]> granicus.if.org Git - postgresql/commit
Fix pruning of locked and updated tuples.
authorAndres Freund <andres@anarazel.de>
Fri, 3 Nov 2017 14:52:29 +0000 (07:52 -0700)
committerAndres Freund <andres@anarazel.de>
Fri, 15 Dec 2017 02:20:48 +0000 (18:20 -0800)
commit937494c0e1f9b0589d32e00acb4c253ada9958b1
treecc235bcb4857bc092bc504f0b7c99475ea650073
parentc28e0b1e0ab951a434cc4774a82876628092f166
Fix pruning of locked and updated tuples.

Previously it was possible that a tuple was not pruned during vacuum,
even though its update xmax (i.e. the updating xid in a multixact with
both key share lockers and an updater) was below the cutoff horizon.

As the freezing code assumed, rightly so, that that's not supposed to
happen, xmax would be preserved (as a member of a new multixact or
xmax directly). That causes two problems: For one the tuple is below
the xmin horizon, which can cause problems if the clog is truncated or
once there's an xid wraparound. The bigger problem is that that will
break HOT chains, which in turn can lead two to breakages: First,
failing index lookups, which in turn can e.g lead to constraints being
violated. Second, future hot prunes / vacuums can end up making
invisible tuples visible again. There's other harmful scenarios.

Fix the problem by recognizing that tuples can be DEAD instead of
RECENTLY_DEAD, even if the multixactid has alive members, if the
update_xid is below the xmin horizon. That's safe because newer
versions of the tuple will contain the locking xids.

A followup commit will harden the code somewhat against future similar
bugs and already corrupted data.

Author: Andres Freund, with changes by Alvaro Herrera
Reported-By: Daniel Wood
Analyzed-By: Andres Freund, Alvaro Herrera, Robert Haas, Peter
   Geoghegan, Daniel Wood, Yi Wen Wong, Michael Paquier
Reviewed-By: Alvaro Herrera, Robert Haas, Michael Paquier
Discussion:
    https://postgr.es/m/E5711E62-8FDF-4DCA-A888-C200BF6B5742@amazon.com
    https://postgr.es/m/20171102112019.33wb7g5wp4zpjelu@alap3.anarazel.de
Backpatch: 9.3-
src/backend/utils/time/tqual.c
src/test/isolation/expected/freeze-the-dead.out
src/test/isolation/isolation_schedule
src/test/isolation/specs/freeze-the-dead.spec