*** a/src/backend/access/transam/twophase.c
--- b/src/backend/access/transam/twophase.c
***************
*** 1078,1084 **** EndPrepare(GlobalTransaction gxact)
  	 * Note that at this stage we have marked the prepare, but still show as
  	 * running in the procarray (twice!) and continue to hold locks.
  	 */
! 	SyncRepWaitForLSN(gxact->prepare_lsn);
  
  	records.tail = records.head = NULL;
  }
--- 1078,1085 ----
  	 * Note that at this stage we have marked the prepare, but still show as
  	 * running in the procarray (twice!) and continue to hold locks.
  	 */
! 	if (max_wal_senders > 0)
! 		SyncRepWaitForLSN(gxact->prepare_lsn);
  
  	records.tail = records.head = NULL;
  }
***************
*** 2046,2052 **** RecordTransactionCommitPrepared(TransactionId xid,
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	SyncRepWaitForLSN(recptr);
  }
  
  /*
--- 2047,2054 ----
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	if (max_wal_senders > 0)
! 		SyncRepWaitForLSN(recptr);
  }
  
  /*
***************
*** 2133,2137 **** RecordTransactionAbortPrepared(TransactionId xid,
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	SyncRepWaitForLSN(recptr);
  }
--- 2135,2140 ----
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	if (max_wal_senders > 0)
! 		SyncRepWaitForLSN(recptr);
  }
*** a/src/backend/access/transam/xact.c
--- b/src/backend/access/transam/xact.c
***************
*** 1132,1138 **** RecordTransactionCommit(void)
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	SyncRepWaitForLSN(XactLastRecEnd);
  
  	/* Reset XactLastRecEnd until the next transaction writes something */
  	XactLastRecEnd.xrecoff = 0;
--- 1132,1139 ----
  	 * Note that at this stage we have marked clog, but still show as
  	 * running in the procarray and continue to hold locks.
  	 */
! 	if (max_wal_senders > 0)
! 		SyncRepWaitForLSN(XactLastRecEnd);
  
  	/* Reset XactLastRecEnd until the next transaction writes something */
  	XactLastRecEnd.xrecoff = 0;
*** a/src/backend/replication/syncrep.c
--- b/src/backend/replication/syncrep.c
***************
*** 96,101 **** SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
--- 96,102 ----
  	if (!SyncRepRequested() || !sync_standbys_defined)
  		return;
  
+ 	Assert(max_wal_senders > 0);
  	Assert(SHMQueueIsDetached(&(MyProc->syncRepLinks)));
  
  	/*
