From 5ccf89ad9ba9812273c1183daba6c942dd6e76da Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 30 Nov 2015 15:31:43 +0900 Subject: [PATCH] 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. --- repmgr.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/repmgr.c b/repmgr.c index 5db94ac9..341988cb 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1761,13 +1761,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); @@ -1777,6 +1784,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 */