diff --git a/src/backend/access/common/bufmask.c b/src/backend/access/common/bufmask.c
index 3b06115e03585898a59be95c917cf337721e3bee..10253d33545f20e0a9e55deeb52ab855787e849a 100644
--- a/src/backend/access/common/bufmask.c
+++ b/src/backend/access/common/bufmask.c
@@ -5,7 +5,7 @@
  *	  in a page which can be different when the WAL is generated
  *	  and when the WAL is applied.
  *
- * Portions Copyright (c) 2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2016-2017, PostgreSQL Global Development Group
  *
  * Contains common routines required for masking a page.
  *
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 0be48fb3ee112cb97888851053f946a671137b02..af258366a207dcecdd22d29a640d0e35d06c3c77 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -9167,7 +9167,6 @@ heap_mask(char *pagedata, BlockNumber blkno)
 
 		if (ItemIdIsNormal(iid))
 		{
-
 			HeapTupleHeader page_htup = (HeapTupleHeader) page_item;
 
 			/*
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 2dcff7f54b5367182038f44cb1463739676aded2..f23e1086280c0e23392117be85e0872ca4494c23 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1360,6 +1360,16 @@ checkXLogConsistency(XLogReaderState *record)
 
 		Assert(XLogRecHasBlockImage(record, block_id));
 
+		if (XLogRecBlockImageApply(record, block_id))
+		{
+			/*
+			 * WAL record has already applied the page, so bypass the
+			 * consistency check as that would result in comparing the full
+			 * page stored in the record with itself.
+			 */
+			continue;
+		}
+
 		/*
 		 * Read the contents from the current buffer and store it in a
 		 * temporary page.
@@ -1390,7 +1400,7 @@ checkXLogConsistency(XLogReaderState *record)
 
 		/*
 		 * Read the contents from the backup copy, stored in WAL record and
-		 * store it in a temporary page. There is not need to allocate a new
+		 * store it in a temporary page. There is no need to allocate a new
 		 * page here, a local buffer is fine to hold its contents and a mask
 		 * can be directly applied on it.
 		 */
diff --git a/src/include/access/bufmask.h b/src/include/access/bufmask.h
index add2dc0cd145b0e0717605dffd841ad74a751943..722dfea8d877a2362cf6344fbecb5dade40a6427 100644
--- a/src/include/access/bufmask.h
+++ b/src/include/access/bufmask.h
@@ -7,7 +7,7 @@
  *	  individual rmgr, but we make things easier by providing some
  *	  common routines to handle cases which occur in multiple rmgrs.
  *
- * Portions Copyright (c) 2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2016-2017, PostgreSQL Global Development Group
  *
  * src/include/access/bufmask.h
  *