*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 2474,2484 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
  			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;
  			}
  
--- 2474,2494 ----
  			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,
+ 								 wal_segment_size);
  					ereport(PANIC,
  							(errcode_for_file_access(),
  							 errmsg("could not seek in log file %s to offset %u: %m",
! 									xlogfname, startoffset)));
! 				}
! 
  				openLogOff = startoffset;
  			}
  
***************
*** 2494,2507 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
  				pgstat_report_wait_end();
  				if (written <= 0)
  				{
  					if (errno == EINTR)
  						continue;
  					ereport(PANIC,
  							(errcode_for_file_access(),
  							 errmsg("could not write to log file %s "
  									"at offset %u, length %zu: %m",
! 									XLogFileNameP(ThisTimeLineID, openLogSegNo),
! 									openLogOff, nbytes)));
  				}
  				nleft -= written;
  				from += written;
--- 2504,2525 ----
  				pgstat_report_wait_end();
  				if (written <= 0)
  				{
+ 					/*
+ 					 * We are within a critical section here so we cannot use
+ 					 * XLogFileNameP. Use this buffer instead.
+ 					 */
+ 					char		xlogfname[MAXFNAMELEN];
+ 
  					if (errno == EINTR)
  						continue;
+ 
+ 					XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo,
+ 								 wal_segment_size);
  					ereport(PANIC,
  							(errcode_for_file_access(),
  							 errmsg("could not write to log file %s "
  									"at offset %u, length %zu: %m",
! 									xlogfname, openLogOff, nbytes)));
  				}
  				nleft -= written;
  				from += written;
***************
*** 3740,3749 **** 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;
  }
  
--- 3758,3776 ----
  #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, wal_segment_size);
  		ereport(PANIC,
  				(errcode_for_file_access(),
! 				 errmsg("could not close log file %s: %m", xlogfname)));
! 	}
! 
  	openLogFile = -1;
  }
  
***************
*** 10153,10158 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 10180,10193 ----
  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, wal_segment_size);
+ 
  	switch (sync_method)
  	{
  		case SYNC_METHOD_FSYNC:
***************
*** 10160,10166 **** 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:
--- 10195,10201 ----
  				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:
***************
*** 10168,10174 **** 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
--- 10203,10209 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fsync write-through log file %s: %m",
! 								xlogfname)));
  			break;
  #endif
  #ifdef HAVE_FDATASYNC
***************
*** 10177,10183 **** 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:
--- 10212,10218 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fdatasync log file %s: %m",
! 								xlogfname)));
  			break;
  #endif
  		case SYNC_METHOD_OPEN:
