From 18a56b266b8b744842fd38b2630cbcaaeb0cc0d7 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 28 Jun 2017 22:16:10 +0900 Subject: [PATCH] repmgr: fix generation of default "dbname" If not explicitly provided, "dbname" was being set early to the default "username" value, which was leading to different behaviour to libpq applications, where "dbname" defaults to "username" at connection time. --- README.md | 2 +- repmgr.c | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4c68a9e4..98edcdc0 100644 --- a/README.md +++ b/README.md @@ -1610,7 +1610,7 @@ which contains connection details for the local database. Creates a witness server as a separate PostgreSQL instance. This instance can be on a separate server or a server running an existing node. The - witness server contain a copy of the repmgr metadata tables but will not + witness server contains a copy of the repmgr metadata tables but will not be set up as a standby; instead it will update its metadata copy each time a failover occurs. diff --git a/repmgr.c b/repmgr.c index a6ac7826..3ae30bf6 100644 --- a/repmgr.c +++ b/repmgr.c @@ -283,7 +283,11 @@ main(int argc, char **argv) /* * Pre-set any defaults , which can be overwritten if matching - * command line parameters are provided + * command line parameters are provided. + * + * Note: PQconndefaults() does not provide a default value for + * "dbname", but if none is provided will default to "username" + * when the connection is made. */ for (c = 0; c < source_conninfo.size && source_conninfo.keywords[c]; c++) @@ -316,7 +320,6 @@ main(int argc, char **argv) } /* set default user for -R/--remote-user */ - { struct passwd *pw = NULL; @@ -330,15 +333,6 @@ main(int argc, char **argv) strncpy(runtime_options.username, pw->pw_name, MAXLEN); } - /* - * Though libpq will default to the username as dbname, PQconndefaults() - * doesn't return this - */ - if (runtime_options.dbname[0] == '\0') - { - strncpy(runtime_options.dbname, runtime_options.username, MAXLEN); - } - while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:f:R:w:k:FWIvb:rcL:tm:C:l:P", long_options, &optindex)) != -1) {