From 3eda7373ad114c12bfb0455c59bd48eb1b1423b0 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 25 Jul 2016 20:44:36 +0900 Subject: [PATCH] Prevent duplicated parameters being passed to pg_basebackup This was not a problem, but ugly. --- repmgr.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/repmgr.c b/repmgr.c index d71ff4d8..998b709e 100644 --- a/repmgr.c +++ b/repmgr.c @@ -4623,33 +4623,37 @@ run_basebackup(const char *data_dir, int server_version) appendPQExpBuffer(¶ms, " -D %s", data_dir); - if (opts != NULL && strlen(runtime_options.dbname)) + /* + * conninfo string provided - pass it to pg_basebackup as the -d option + * (pg_basebackup doesn't require or want a database name, but for + * consistency with other applications accepts a conninfo string + * under -d/--dbname) + */ + if (conninfo_provided == true) { appendPQExpBuffer(¶ms, " -d '%s'", runtime_options.dbname); } - if (strlen(runtime_options.host)) - { - appendPQExpBuffer(¶ms, " -h %s", runtime_options.host); - } - /* - * XXX -p and -U will be duplicated if provided in conninfo string - * but not as explict repmgr command line parameters, e.g.: - * - * pg_basebackup -l "repmgr base backup" -d 'host=localhost port=5501 dbname=repmgr user=repmgr' -p 5501 -U repmgr -X stream - * - * this is ugly but harmless; we should fix it some time - * + * Connection parameters not passed to repmgr as conninfo string - provide + * them individually to pg_basebackup (-d/--dbname not required) */ - if (strlen(runtime_options.masterport)) + if (conninfo_provided == false) { - appendPQExpBuffer(¶ms, " -p %s", runtime_options.masterport); - } + if (strlen(runtime_options.host)) + { + appendPQExpBuffer(¶ms, " -h %s", runtime_options.host); + } - if (strlen(runtime_options.username)) - { - appendPQExpBuffer(¶ms, " -U %s", runtime_options.username); + if (strlen(runtime_options.masterport)) + { + appendPQExpBuffer(¶ms, " -p %s", runtime_options.masterport); + } + + if (strlen(runtime_options.username)) + { + appendPQExpBuffer(¶ms, " -U %s", runtime_options.username); + } } if (runtime_options.fast_checkpoint) {