*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 1641,1651 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
  			if (openLogOff != startoffset)
  			{
  				if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
  					ereport(PANIC,
  							(errcode_for_file_access(),
  					 errmsg("could not seek in log file %s to offset %u: %m",
! 							XLogFileNameP(ThisTimeLineID, openLogSegNo),
! 							startoffset)));
  				openLogOff = startoffset;
  			}
  
--- 1641,1660 ----
  			if (openLogOff != startoffset)
  			{
  				if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
+ 				{
+ 					/*
+ 					 * We are within a critical section here so we cannot use
+ 					 * XLogFileNameP. Use this buffer instead.
+ 					 */
+ 					char		xlogfname[MAXFNAMELEN];
+  
+ 					XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
  					ereport(PANIC,
  							(errcode_for_file_access(),
  					 errmsg("could not seek in log file %s to offset %u: %m",
! 							xlogfname, startoffset)));
! 				}
! 
  				openLogOff = startoffset;
  			}
  
***************
*** 1655,1660 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
--- 1664,1677 ----
  			errno = 0;
  			if (write(openLogFile, from, nbytes) != nbytes)
  			{
+ 				/*
+ 				 * We are within a critical section here so we cannot use
+ 				 * XLogFileNameP. Use this buffer instead.
+ 				 */
+ 				char		xlogfname[MAXFNAMELEN];
+ 
+ 				XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
+ 
  				/* if write didn't set errno, assume no disk space */
  				if (errno == 0)
  					errno = ENOSPC;
***************
*** 1662,1668 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
  						(errcode_for_file_access(),
  						 errmsg("could not write to log file %s "
  								"at offset %u, length %lu: %m",
! 								XLogFileNameP(ThisTimeLineID, openLogSegNo),
  								openLogOff, (unsigned long) nbytes)));
  			}
  
--- 1679,1685 ----
  						(errcode_for_file_access(),
  						 errmsg("could not write to log file %s "
  								"at offset %u, length %lu: %m",
! 								xlogfname,
  								openLogOff, (unsigned long) nbytes)));
  			}
  
***************
*** 2802,2811 **** XLogFileClose(void)
  #endif
  
  	if (close(openLogFile))
  		ereport(PANIC,
  				(errcode_for_file_access(),
! 				 errmsg("could not close log file %s: %m",
! 						XLogFileNameP(ThisTimeLineID, openLogSegNo))));
  	openLogFile = -1;
  }
  
--- 2819,2837 ----
  #endif
  
  	if (close(openLogFile))
+ 	{
+ 		/*
+ 		 * We are within a critical section here so we cannot use
+ 		 * XLogFileNameP. Use this buffer instead.
+ 		 */
+ 		char		xlogfname[MAXFNAMELEN];
+ 
+ 		XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
  		ereport(PANIC,
  				(errcode_for_file_access(),
! 				 errmsg("could not close log file %s: %m", xlogfname)));
! 	}
! 
  	openLogFile = -1;
  }
  
***************
*** 8607,8612 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 8633,8646 ----
  void
  issue_xlog_fsync(int fd, XLogSegNo segno)
  {
+ 	/*
+ 	 * We are within a critical section here so we cannot use let
+ 	 * XLogFileNameP. Use this buffer instead.
+ 	 */
+ 	char		xlogfname[MAXFNAMELEN];
+ 
+ 	XLogFileName(xlogfname, ThisTimeLineID, segno);
+ 
  	switch (sync_method)
  	{
  		case SYNC_METHOD_FSYNC:
***************
*** 8614,8620 **** issue_xlog_fsync(int fd, XLogSegNo segno)
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fsync log file %s: %m",
! 								XLogFileNameP(ThisTimeLineID, segno))));
  			break;
  #ifdef HAVE_FSYNC_WRITETHROUGH
  		case SYNC_METHOD_FSYNC_WRITETHROUGH:
--- 8648,8654 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fsync log file %s: %m",
! 								xlogfname)));
  			break;
  #ifdef HAVE_FSYNC_WRITETHROUGH
  		case SYNC_METHOD_FSYNC_WRITETHROUGH:
***************
*** 8622,8628 **** issue_xlog_fsync(int fd, XLogSegNo segno)
  				ereport(PANIC,
  						(errcode_for_file_access(),
  					  errmsg("could not fsync write-through log file %s: %m",
! 							 XLogFileNameP(ThisTimeLineID, segno))));
  			break;
  #endif
  #ifdef HAVE_FDATASYNC
--- 8656,8662 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  					  errmsg("could not fsync write-through log file %s: %m",
! 							 xlogfname)));
  			break;
  #endif
  #ifdef HAVE_FDATASYNC
***************
*** 8631,8637 **** issue_xlog_fsync(int fd, XLogSegNo segno)
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fdatasync log file %s: %m",
! 								XLogFileNameP(ThisTimeLineID, segno))));
  			break;
  #endif
  		case SYNC_METHOD_OPEN:
--- 8665,8671 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fdatasync log file %s: %m",
! 								xlogfname)));
  			break;
  #endif
  		case SYNC_METHOD_OPEN:
