*** a/src/bin/pg_rewind/filemap.c
--- b/src/bin/pg_rewind/filemap.c
***************
*** 21,26 ****
--- 21,27 ----
  #include "common/string.h"
  #include "catalog/pg_tablespace.h"
  #include "storage/fd.h"
+ #include "access/xlog_internal.h"
  
  filemap_t  *filemap = NULL;
  
***************
*** 168,179 **** process_source_file(const char *path, file_type_t type, size_t newsize,
--- 169,191 ----
  				 *
  				 * An exception: PG_VERSIONs should be identical, but avoid
  				 * overwriting it for paranoia.
+ 				 *
+ 				 * Another exception: Do not copy WAL files before the
+ 				 * divergence and the WAL files after the current WAL insert
+ 				 * location of the source server for performance reasons.
  				 */
  				if (pg_str_endswith(path, "PG_VERSION"))
  				{
  					action = FILE_ACTION_NONE;
  					oldsize = statbuf.st_size;
  				}
+ 				else if (strncmp(path, "pg_wal", 6) == 0 && IsXLogFileName(path + 7) &&
+ 						 (strcmp(path + 7 + 8, divergence_wal_filename + 8) < 0 ||
+ 						  strcmp(path + 7 + 8, last_source_wal_filename + 8) > 0))
+ 				{
+ 					action = FILE_ACTION_NONE;
+ 					oldsize = exists ? statbuf.st_size : 0;
+ 				}
  				else
  				{
  					action = FILE_ACTION_COPY;
***************
*** 303,310 **** process_target_file(const char *path, file_type_t type, size_t oldsize,
  	exists = (bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
  					  path_cmp) != NULL);
  
! 	/* Remove any file or folder that doesn't exist in the source system. */
! 	if (!exists)
  	{
  		entry = pg_malloc(sizeof(file_entry_t));
  		entry->path = pg_strdup(path);
--- 315,326 ----
  	exists = (bsearch(&key_ptr, map->array, map->narray, sizeof(file_entry_t *),
  					  path_cmp) != NULL);
  
! 	/* Remove any file or folder that doesn't exist in the source system
! 	 * except the WAL files before the divergence.
! 	 */
! 	if (!exists &&
! 		!(strncmp(path, "pg_wal", 6) == 0 && IsXLogFileName(path + 7) &&
! 		  strcmp(path + 7 + 8, divergence_wal_filename + 8) < 0))
  	{
  		entry = pg_malloc(sizeof(file_entry_t));
  		entry->path = pg_strdup(path);
*** a/src/bin/pg_rewind/pg_rewind.c
--- b/src/bin/pg_rewind/pg_rewind.c
***************
*** 27,32 ****
--- 27,33 ----
  #include "common/restricted_token.h"
  #include "getopt_long.h"
  #include "storage/bufpage.h"
+ #include "access/xlog_internal.h"
  
  static void usage(const char *progname);
  
***************
*** 58,63 **** bool		dry_run = false;
--- 59,68 ----
  TimeLineHistoryEntry *targetHistory;
  int			targetNentries;
  
+ /* WAL location */
+ char		divergence_wal_filename[MAXFNAMELEN];
+ char		last_source_wal_filename[MAXFNAMELEN];
+ 
  static void
  usage(const char *progname)
  {
***************
*** 103,108 **** main(int argc, char **argv)
--- 108,115 ----
  	XLogRecPtr	endrec;
  	TimeLineID	endtli;
  	ControlFileData ControlFile_new;
+ 	XLogSegNo	startsegno;
+ 	XLogSegNo	endsegno;
  
  	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_rewind"));
  	progname = get_progname(argv[0]);
***************
*** 280,285 **** main(int argc, char **argv)
--- 287,317 ----
  		   chkpttli);
  
  	/*
+ 	 * Save the WAL filenames of the divergence and the current WAL insert
+ 	 * location of the source server. Later only the WAL files between those
+ 	 * would be copied to the target data directory.
+ 	 * Note:The later generated WAL files in the source server before the end
+ 	 * of the copy of the data files must be made available when the target
+ 	 * server is started. This can be done by configuring the target server as
+ 	 * a standby of the source server.
+ 	 */
+ 	if (connstr_source)
+ 	{
+ 		endrec = libpqGetCurrentXlogInsertLocation();
+ 		endtli = ControlFile_source.checkPointCopy.ThisTimeLineID;
+ 	}
+ 	else
+ 	{
+ 		endrec = ControlFile_source.checkPoint;
+ 		endtli = ControlFile_source.checkPointCopy.ThisTimeLineID;
+ 	}
+ 
+ 	XLByteToSeg(divergerec, startsegno);
+ 	XLogFileName(divergence_wal_filename, targetHistory[lastcommontliIndex].tli, startsegno);
+ 	XLByteToPrevSeg(endrec, endsegno);
+ 	XLogFileName(last_source_wal_filename, endtli, endsegno);
+ 
+ 	/*
  	 * Build the filemap, by comparing the source and target data directories.
  	 */
  	filemap_create();
*** a/src/bin/pg_rewind/pg_rewind.h
--- b/src/bin/pg_rewind/pg_rewind.h
***************
*** 29,34 **** extern bool dry_run;
--- 29,38 ----
  extern TimeLineHistoryEntry *targetHistory;
  extern int	targetNentries;
  
+ /* WAL location */
+ extern char	divergence_wal_filename[];
+ extern char	last_source_wal_filename[];
+ 
  /* in parsexlog.c */
  extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
  			   int tliIndex, XLogRecPtr endpoint);
