diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index f0e3653..2430d6f 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -960,11 +960,14 @@ PageCalcChecksum16(Page page, BlockNumber blkno)
 	 * Save pd_checksum and set it to zero, so that the checksum calculation
 	 * isn't affected by the checksum stored on the page. We do this to
 	 * allow optimization of the checksum calculation on the whole block
-	 * in one go.
+	 * in one go. Memory barriers are required to avoid rearrangement here.
 	 */
 	save_checksum = phdr->pd_checksum;
+	pg_memory_barrier();
 	phdr->pd_checksum = 0;
+	pg_memory_barrier();
 	checksum = checksum_block(page, BLCKSZ);
+	pg_memory_barrier();
 	phdr->pd_checksum = save_checksum;
 
 	/* mix in the block number to detect transposed pages */
