diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c
index 66c52d6dd6..387b1f7d18 100644
--- a/src/backend/access/gist/gistutil.c
+++ b/src/backend/access/gist/gistutil.c
@@ -1017,8 +1017,7 @@ gistGetFakeLSN(Relation rel)
 	 * XXX before commit fix this.  This is not correct for
 	 * RELPERSISTENCE_PERMANENT, but it suffices to make tests pass.
 	 */
-	if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP
-		|| rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
+	if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
 	{
 		/*
 		 * Temporary relations are only accessible in our session, so a simple
@@ -1026,6 +1025,15 @@ gistGetFakeLSN(Relation rel)
 		 */
 		return counter++;
 	}
+	else if (rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT)
+	{
+		/*
+		 * Even though we are skipping WAL-logging of a permanent relations,
+		 * the LSN must be a real one because WAL-logging starts after commit.
+		 */
+		Assert(!RelationNeedsWAL(rel));
+		return GetXLogInsertRecPtr();
+	}
 	else
 	{
 		/*
