diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c
index 188e33642f..aaf1a4a146 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -540,6 +540,7 @@ gist_indexsortbuild_pagestate_flush(GISTBuildState *state,
 	/* Re-initialize the page buffer for next page on this level. */
 	pagestate->page = palloc(BLCKSZ);
 	gistinitpage(pagestate->page, isleaf ? F_LEAF : 0);
+	GistPageGetOpaque(pagestate->page)->rightlink = blkno;
 }
 
 static void
