diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index f4d0fe5..fd53495 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -45,10 +45,16 @@ spgistBuildCallback(Relation index, HeapTuple htup, Datum *values,
 	/* Work in temp context, and reset it after each tuple */
 	oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
 
-	/* No concurrent insertions can be happening, so failure is unexpected */
-	if (!spgdoinsert(index, &buildstate->spgstate, &htup->t_self,
-					 *values, *isnull))
-		elog(ERROR, "unexpected spgdoinsert() failure");
+	/* 
+	 * No concurrent insertions can be happening, but background
+	 * writer/checkpointer process could take a share lock on buffer 
+	 * during write.  
+	 */
+	while (!spgdoinsert(index, &buildstate->spgstate, &htup->t_self, *values, *isnull))
+	{
+		MemoryContextReset(buildstate->tmpCtx);
+	}
+
 
 	MemoryContextSwitchTo(oldCtx);
 	MemoryContextReset(buildstate->tmpCtx);
