*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 2463,2473 **** 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;
  			}
  
--- 2463,2482 ----
  			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;
  			}
  
***************
*** 2481,2494 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
  				written = write(openLogFile, from, nleft);
  				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;
--- 2490,2510 ----
  				written = write(openLogFile, from, nleft);
  				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);
  					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;
***************
*** 3669,3678 **** 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;
  }
  
--- 3685,3703 ----
  #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;
  }
  
***************
*** 9799,9804 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 9824,9837 ----
  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:
***************
*** 9806,9812 **** 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:
--- 9839,9845 ----
  				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:
***************
*** 9814,9820 **** 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
--- 9847,9853 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  					  errmsg("could not fsync write-through log file %s: %m",
! 							 xlogfname)));
  			break;
  #endif
  #ifdef HAVE_FDATASYNC
***************
*** 9823,9829 **** 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:
--- 9856,9862 ----
  				ereport(PANIC,
  						(errcode_for_file_access(),
  						 errmsg("could not fdatasync log file %s: %m",
! 								xlogfname)));
  			break;
  #endif
  		case SYNC_METHOD_OPEN:
