diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index 64537d0..9513faf 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -159,16 +159,25 @@ GetNewTransactionId(bool isSubXact)
 	 *
 	 * Extend pg_subtrans too.
 	 */
-	ExtendCLOG(xid);
-	ExtendSUBTRANS(xid);
+	{
+		int		incr = pg_lrand48() & 0x7FF;
 
-	/*
-	 * Now advance the nextXid counter.  This must not happen until after we
-	 * have successfully completed ExtendCLOG() --- if that routine fails, we
-	 * want the next incoming transaction to try it again.	We cannot assign
-	 * more XIDs until there is CLOG space for them.
-	 */
-	TransactionIdAdvance(ShmemVariableCache->nextXid);
+		for (; incr > 0; incr--)
+		{
+			xid = ShmemVariableCache->nextXid;
+
+			ExtendCLOG(xid);
+			ExtendSUBTRANS(xid);
+
+			/*
+			 * Now advance the nextXid counter.  This must not happen until after we
+			 * have successfully completed ExtendCLOG() --- if that routine fails, we
+			 * want the next incoming transaction to try it again.	We cannot assign
+			 * more XIDs until there is CLOG space for them.
+			 */
+			TransactionIdAdvance(ShmemVariableCache->nextXid);
+		}
+	}
 
 	/*
 	 * We must store the new XID into the shared ProcArray before releasing
