diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c
index e8e06c62a9..2364d3af3f 100644
--- a/src/backend/access/hash/hash_xlog.c
+++ b/src/backend/access/hash/hash_xlog.c
@@ -655,7 +655,11 @@ hash_xlog_squeeze_page(XLogReaderState *record)
 		 */
 		(void) XLogReadBufferForRedoExtended(record, 0, RBM_NORMAL, true, &bucketbuf);
 
-		action = XLogReadBufferForRedo(record, 1, &writebuf);
+		if ((xldata->ntups == 0 && xldata->is_prev_bucket_same_wrt) ||
+			xldata->ntups > 0)
+			action = XLogReadBufferForRedo(record, 1, &writebuf);
+		else
+			action = BLK_NOTFOUND;
 	}
 
 	/* replay the record for adding entries in overflow buffer */
diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c
index 9d1ff20b92..2fc7760b17 100644
--- a/src/backend/access/hash/hashovfl.c
+++ b/src/backend/access/hash/hashovfl.c
@@ -668,9 +668,25 @@ _hash_freeovflpage(Relation rel, Buffer bucketbuf, Buffer ovflbuf,
 			XLogRegisterBuffer(0, bucketbuf, flags);
 		}
 
-		XLogRegisterBuffer(1, wbuf, REGBUF_STANDARD);
-		if (xlrec.ntups > 0)
+		/*
+		 * A write buffer needs to be registered even if no tuples are added to
+		 * it to ensure that we can acquire a cleanup lock on it if it is the
+		 * same as primary bucket buffer or update the nextblkno if it is same
+		 * as the previous bucket buffer.
+		 */
+		if (xlrec.ntups == 0 &&
+			(xlrec.is_prim_bucket_same_wrt || xlrec.is_prev_bucket_same_wrt))
+		{
+			bool		wbuf_flags;
+
+			wbuf_flags = REGBUF_STANDARD;
+			if (!xlrec.is_prev_bucket_same_wrt)
+				wbuf_flags |= REGBUF_NO_CHANGE;
+			XLogRegisterBuffer(1, wbuf, wbuf_flags);
+		}
+		else if (xlrec.ntups > 0)
 		{
+			XLogRegisterBuffer(1, wbuf, REGBUF_STANDARD);
 			XLogRegisterBufData(1, (char *) itup_offsets,
 								nitups * sizeof(OffsetNumber));
 			for (i = 0; i < nitups; i++)
