From ebbc2975e07822e49dc5a53c1fa107d3354ad44c Mon Sep 17 00:00:00 2001 From: Paul Guo Date: Thu, 18 Apr 2019 19:37:36 +0800 Subject: [PATCH v3 2/3] Add option to write recovery configuration information in pg_rewind. --- src/bin/pg_rewind/pg_rewind.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c index 14260bb883..b31a193e5a 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -76,6 +76,7 @@ usage(const char *progname) printf(_(" -D, --target-pgdata=DIRECTORY existing data directory to modify\n")); printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n")); printf(_(" --source-server=CONNSTR source server to synchronize with\n")); + printf(_(" -R, --write-recovery-conf write configuration for replication\n")); printf(_(" -n, --dry-run stop before modifying anything\n")); printf(_(" -N, --no-sync do not wait for changes to be written\n" " safely to disk\n")); @@ -93,6 +94,7 @@ main(int argc, char **argv) static struct option long_options[] = { {"help", no_argument, NULL, '?'}, {"target-pgdata", required_argument, NULL, 'D'}, + {"write-recovery-conf", no_argument, NULL, 'R'}, {"source-pgdata", required_argument, NULL, 1}, {"source-server", required_argument, NULL, 2}, {"version", no_argument, NULL, 'V'}, @@ -135,7 +137,7 @@ main(int argc, char **argv) } } - while ((c = getopt_long(argc, argv, "D:nNP", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "D:nNPR", long_options, &option_index)) != -1) { switch (c) { @@ -155,6 +157,10 @@ main(int argc, char **argv) do_sync = false; break; + case 'R': + writerecoveryconf = true; + break; + case 3: debug = true; pg_logging_set_level(PG_LOG_DEBUG); @@ -301,6 +307,11 @@ main(int argc, char **argv) if (!rewind_needed) { pg_log_info("no rewind required"); + if (writerecoveryconf && connstr_source) + { + GenerateRecoveryConf(); + WriteRecoveryConf(datadir_target); + } exit(0); } @@ -398,6 +409,12 @@ main(int argc, char **argv) pg_log_info("syncing target data directory"); syncTargetDirectory(); + if (writerecoveryconf && connstr_source) + { + GenerateRecoveryConf(); + WriteRecoveryConf(datadir_target); + } + pg_log_info("Done!"); return 0; -- 2.17.2