diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index fd81d675570f3f7d8a0fa7055b8f084a560eb2eb..f559a2f3d80e6aaa34b041e4643e5fec5d06e4a1 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -552,7 +552,8 @@ shiftList(Relation index, Buffer metabuffer, BlockNumber newHead,
 		 * prepare the XLogInsert machinery for that before entering the
 		 * critical section.
 		 */
-		XLogEnsureRecordSpace(data.ndeleted, 0);
+		if (RelationNeedsWAL(index))
+			XLogEnsureRecordSpace(data.ndeleted, 0);
 
 		START_CRIT_SECTION();