diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-11-07 21:39:40 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-11-07 21:39:40 -0500 |
commit | bbb6e559c4ea0fb4c346beda76736451dc24eb4e (patch) | |
tree | a49de5afba6376d371afaf3e78bcc1a117a6f37f /src/backend/access/heap/heapam.c | |
parent | bd2396988a1afbcb6424700e52a62f34d2951bdd (diff) | |
download | postgresql-bbb6e559c4ea0fb4c346beda76736451dc24eb4e.tar.gz postgresql-bbb6e559c4ea0fb4c346beda76736451dc24eb4e.zip |
Make VACUUM avoid waiting for a cleanup lock, where possible.
In a regular VACUUM, it's OK to skip pages for which a cleanup lock
isn't immediately available; the next VACUUM will deal with them. If
we're scanning the entire relation to advance relfrozenxid, we might
need to wait, but only if there are tuples on the page that actually
require freezing. These changes should greatly reduce the incidence
of of vacuum processes getting "stuck".
Simon Riggs and Robert Haas
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r-- | src/backend/access/heap/heapam.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index b2d19016e76..81422afa2f8 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -3841,6 +3841,44 @@ recheck_xvac: return changed; } +/* + * heap_tuple_needs_freeze + * + * Check to see whether any of the XID fields of a tuple (xmin, xmax, xvac) + * are older than the specified cutoff XID. If so, return TRUE. + * + * It doesn't matter whether the tuple is alive or dead, we are checking + * to see if a tuple needs to be removed or frozen to avoid wraparound. + */ +bool +heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid, + Buffer buf) +{ + TransactionId xid; + + xid = HeapTupleHeaderGetXmin(tuple); + if (TransactionIdIsNormal(xid) && + TransactionIdPrecedes(xid, cutoff_xid)) + return true; + + if (!(tuple->t_infomask & HEAP_XMAX_IS_MULTI)) + { + xid = HeapTupleHeaderGetXmax(tuple); + if (TransactionIdIsNormal(xid) && + TransactionIdPrecedes(xid, cutoff_xid)) + return true; + } + + if (tuple->t_infomask & HEAP_MOVED) + { + xid = HeapTupleHeaderGetXvac(tuple); + if (TransactionIdIsNormal(xid) && + TransactionIdPrecedes(xid, cutoff_xid)) + return true; + } + + return false; +} /* ---------------- * heap_markpos - mark scan position |