diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c
index c9de128..0e23d71 100644
--- a/src/backend/access/hash/hashovfl.c
+++ b/src/backend/access/hash/hashovfl.c
@@ -131,6 +131,7 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf, bool retain_pin)
 	uint32		i,
 				j;
 	bool		page_found = false;
+	bool		metap_dirty = false;
 
 	/*
 	 * Write-lock the tail page.  Here, we need to maintain locking order such
@@ -341,9 +342,10 @@ found:
 			metap->hashm_mapp[metap->hashm_nmaps] = BufferGetBlockNumber(newmapbuf);
 			metap->hashm_nmaps++;
 			metap->hashm_spares[splitnum]++;
-			MarkBufferDirty(metabuf);
 		}
 
+		metap_dirty = true;
+
 		/*
 		 * for new overflow page, we don't need to explicitly set the bit in
 		 * bitmap page, as by default that will be set to "in use".
@@ -357,9 +359,12 @@ found:
 	if (metap->hashm_firstfree == orig_firstfree)
 	{
 		metap->hashm_firstfree = bit + 1;
-		MarkBufferDirty(metabuf);
+		metap_dirty = true;
 	}
 
+	if (metap_dirty)
+		MarkBufferDirty(metabuf);
+
 	/* initialize new overflow page */
 	ovflpage = BufferGetPage(ovflbuf);
 	ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
