diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 5b9289fd4b..dcb114ebe7 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -938,7 +938,8 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 		OffsetNumber offnum,
 					maxoff;
 		bool		tupgone,
-					hastup;
+					hastup,
+					will_freeze = false;
 		int			prev_dead_count;
 		int			nfrozen;
 		Size		freespace;
@@ -1145,6 +1146,8 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 					vacrelstats->nonempty_pages = blkno + 1;
 				continue;
 			}
+			else
+				will_freeze = true;
 			LockBuffer(buf, BUFFER_LOCK_UNLOCK);
 			LockBufferForCleanup(buf);
 			/* drop through to normal processing */
@@ -1242,6 +1245,15 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 										 &vacrelstats->latestRemovedXid,
 										 &vacrelstats->offnum);
 
+		/*
+		 * Check to see if we need to freeze, based on the user requested
+		 * cutoff values. If we are going to freeze then we freeze
+		 * every tuple visible to all, using OldestXmin.
+		 */
+		if (!will_freeze &&
+			lazy_check_needs_freeze(buf, &hastup, vacrelstats))
+				will_freeze = true;
+
 		/*
 		 * Now scan the page to collect vacuumable items and check for tuples
 		 * requiring freezing.
@@ -1446,7 +1458,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 				tups_vacuumed += 1;
 				has_dead_tuples = true;
 			}
-			else
+			else if (will_freeze)
 			{
 				bool		tuple_totally_frozen;
 
@@ -1459,7 +1471,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 				 */
 				if (heap_prepare_freeze_tuple(tuple.t_data,
 											  relfrozenxid, relminmxid,
-											  FreezeLimit, MultiXactCutoff,
+											  OldestXmin, OldestXmin,
 											  &frozen[nfrozen],
 											  &tuple_totally_frozen))
 					frozen[nfrozen++].offset = offnum;
@@ -1568,7 +1580,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 		{
 			uint8		flags = VISIBILITYMAP_ALL_VISIBLE;
 
-			if (all_frozen)
+			if (nfrozen > 0 && all_frozen)
 				flags |= VISIBILITYMAP_ALL_FROZEN;
 
 			/*
@@ -1637,6 +1649,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
 		 * all_visible is true, so we must check both.
 		 */
 		else if (all_visible_according_to_vm && all_visible && all_frozen &&
+				 nfrozen > 0 &&
 				 !VM_ALL_FROZEN(onerel, blkno, &vmbuffer))
 		{
 			/*
