diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml
index 32dc83f..bb1d640 100644
--- a/doc/src/sgml/ref/pg_rewind.sgml
+++ b/doc/src/sgml/ref/pg_rewind.sgml
@@ -49,12 +49,13 @@ PostgreSQL documentation
The result is equivalent to replacing the target data directory with the
- source one. All files are copied, including configuration files. The
- advantage of pg_rewind> over taking a new base backup, or
- tools like rsync>, is that pg_rewind> does
- not require reading through all unchanged files in the cluster. That makes
- it a lot faster when the database is large and only a small portion of it
- differs between the clusters.
+ source one. All files in the data directory are copied, including
+ configuration files, but excluding the WAL log directory,
+ pg_xlog>. The advantage of pg_rewind> over
+ taking a new base backup, or tools like rsync>, is that
+ pg_rewind> does not require reading through all unchanged
+ files in the cluster. That makes it a lot faster when the database is
+ large and only a small portion of it differs between the clusters.
@@ -74,12 +75,12 @@ PostgreSQL documentation
When the target server is started up for the first time after running
pg_rewind>, it will go into recovery mode and replay all
WAL generated in the source server after the point of divergence.
- If some of the WAL was no longer available in the source server when
- pg_rewind> was run, and therefore could not be copied by
- pg_rewind> session, it needs to be made available when the
- target server is started up. That can be done by creating a
- recovery.conf> file in the target data directory with a
- suitable restore_command>.
+ Like after restoring from a base backup using continous archiving,
+ the source server's WAL must be made available to the rewound server.
+ This can be done by creating a recovery.conf> file in the
+ target data directory with a suitable restore_command> or
+ primary_conninfo> line, or by copying the required WAL files
+ manually into pg_xlog> in the target data directory.
diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm
index db5e90b..4d0fe6d 100644
--- a/src/bin/pg_rewind/RewindTest.pm
+++ b/src/bin/pg_rewind/RewindTest.pm
@@ -290,6 +290,21 @@ sub run_pg_rewind
"--source-pgdata=$test_standby_datadir",
"--target-pgdata=$test_master_datadir"],
'pg_rewind local');
+
+ # Copy WAL files from the source server so that recovery will find
+ # them. (In remote mode, the source server is still running, and the
+ # rewound server will use streaming replication to connect to the
+ # source server and fetch the WAL from there.)
+ opendir(DIR,"$test_standby_datadir/pg_xlog") or
+ die "Cannot open $test_standby_datadir/pg_xlog\n";
+ my @xlogfiles = readdir(DIR);
+ closedir(DIR);
+
+ foreach my $xlogfile (@xlogfiles)
+ {
+ copy("$test_standby_datadir/pg_xlog/$xlogfile",
+ "$test_master_datadir/pg_xlog/");
+ }
}
elsif ($test_mode eq "remote")
{
diff --git a/src/bin/pg_rewind/copy_fetch.c b/src/bin/pg_rewind/copy_fetch.c
index 224fad1..f437391 100644
--- a/src/bin/pg_rewind/copy_fetch.c
+++ b/src/bin/pg_rewind/copy_fetch.c
@@ -74,6 +74,9 @@ recurse_dir(const char *datadir, const char *parentpath,
strcmp(xlde->d_name, "..") == 0)
continue;
+ if (parentpath == NULL && strcmp(xlde->d_name, "pg_xlog") == 0)
+ continue;
+
snprintf(fullpath, MAXPGPATH, "%s/%s", fullparentpath, xlde->d_name);
if (lstat(fullpath, &fst) < 0)
diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c
index 1979fbc..bf99e9a 100644
--- a/src/bin/pg_rewind/libpq_fetch.c
+++ b/src/bin/pg_rewind/libpq_fetch.c
@@ -154,6 +154,7 @@ libpqProcessFileList(void)
" SELECT '' AS path, filename, size, isdir FROM\n"
" (SELECT pg_ls_dir('.', true, false) AS filename) AS fn,\n"
" pg_stat_file(fn.filename, true) AS this\n"
+ " WHERE filename <> 'pg_xlog'"
" UNION ALL\n"
" SELECT parent.path || parent.filename || '/' AS path,\n"
" fn, this.size, this.isdir\n"