@@ -2139,9 +2139,8 @@ lazy_vacuum(LVRelState *vacrel, bool onecall)
2139
2139
* far in the past.
2140
2140
*
2141
2141
* From this point on the VACUUM operation will do no further index
2142
- * vacuuming or heap vacuuming. It will do any remaining pruning that
2143
- * may be required, plus other heap-related and relation-level
2144
- * maintenance tasks. But that's it.
2142
+ * vacuuming or heap vacuuming. This VACUUM operation won't end up
2143
+ * back here again.
2145
2144
*/
2146
2145
Assert (vacrel -> do_failsafe );
2147
2146
}
@@ -2534,8 +2533,11 @@ lazy_check_needs_freeze(Buffer buf, bool *hastup, LVRelState *vacrel)
2534
2533
* relfrozenxid and/or relminmxid that is dangerously far in the past.
2535
2534
*
2536
2535
* Triggering the failsafe makes the ongoing VACUUM bypass any further index
2537
- * vacuuming and heap vacuuming. It also stops the ongoing VACUUM from
2538
- * applying any cost-based delay that may be in effect.
2536
+ * vacuuming and heap vacuuming. Truncating the heap is also bypassed.
2537
+ *
2538
+ * Any remaining work (work that VACUUM cannot just bypass) is typically sped
2539
+ * up when the failsafe triggers. VACUUM stops applying any cost-based delay
2540
+ * that it started out with.
2539
2541
*
2540
2542
* Returns true when failsafe has been triggered.
2541
2543
*
@@ -3097,14 +3099,12 @@ lazy_cleanup_one_index(Relation indrel, IndexBulkDeleteResult *istat,
3097
3099
* Don't even think about it unless we have a shot at releasing a goodly
3098
3100
* number of pages. Otherwise, the time taken isn't worth it.
3099
3101
*
3102
+ * Also don't attempt it if wraparound failsafe is in effect. It's hard to
3103
+ * predict how long lazy_truncate_heap will take. Don't take any chances.
3104
+ *
3100
3105
* Also don't attempt it if we are doing early pruning/vacuuming, because a
3101
3106
* scan which cannot find a truncated heap page cannot determine that the
3102
- * snapshot is too old to read that page. We might be able to get away with
3103
- * truncating all except one of the pages, setting its LSN to (at least) the
3104
- * maximum of the truncated range if we also treated an index leaf tuple
3105
- * pointing to a missing heap page as something to trigger the "snapshot too
3106
- * old" error, but that seems fragile and seems like it deserves its own patch
3107
- * if we consider it.
3107
+ * snapshot is too old to read that page.
3108
3108
*
3109
3109
* This is split out so that we can test whether truncation is going to be
3110
3110
* called for before we actually do it. If you change the logic here, be
@@ -3118,6 +3118,9 @@ should_attempt_truncation(LVRelState *vacrel, VacuumParams *params)
3118
3118
if (params -> truncate == VACOPT_TERNARY_DISABLED )
3119
3119
return false;
3120
3120
3121
+ if (vacrel -> do_failsafe )
3122
+ return false;
3123
+
3121
3124
possibly_freeable = vacrel -> rel_pages - vacrel -> nonempty_pages ;
3122
3125
if (possibly_freeable > 0 &&
3123
3126
(possibly_freeable >= REL_TRUNCATE_MINIMUM ||
0 commit comments