Ensure pg_replslot directory is cleaned up after "standby clone" with rsync

This ensures the directory is in the same state as it would be
after cloning the standby with pg_basebackup, i.e. empty.
This commit is contained in:
Ian Barwick
2015-11-30 15:31:43 +09:00
parent 84d2a292b2
commit 864d57953a

View File

@@ -1799,13 +1799,20 @@ stop_backup:
exit(retval);
}
/*
* Remove existing WAL from the target directory, since
* rsync's --exclude option doesn't do it.
* Clean up any $PGDATA subdirectories which may contain
* files which won't be removed by rsync and which could
* be stale or are otherwise not required
*/
if (runtime_options.force)
if (runtime_options.rsync_only && runtime_options.force)
{
char script[MAXLEN];
/*
* Remove any existing WAL from the target directory, since
* rsync's --exclude option doesn't do it.
*/
maxlen_snprintf(script, "rm -rf %s/pg_xlog/*",
local_data_directory);
r = system(script);
@@ -1815,6 +1822,26 @@ stop_backup:
local_data_directory);
exit(ERR_BAD_RSYNC);
}
/*
* Remove any replication slot directories; this matches the
* behaviour a base backup, which would result in an empty
* pg_replslot directory.
*
* NOTE: watch out for any changes in the replication
* slot directory name (as of 9.4: "pg_replslot") and
* functionality of replication slots
*/
maxlen_snprintf(script, "rm -rf %s/pg_replslot/*",
local_data_directory);
r = system(script);
if (r != 0)
{
log_err(_("unable to empty replication slot directory %s/pg_replslot/\n"),
local_data_directory);
exit(ERR_BAD_RSYNC);
}
}
/* Finally, write the recovery.conf file */