Add configuration file setting "use_primary_conninfo_password"

If, for whatever reason, the upstream server password needs to be set
in "primary_conninfo", enable it to be extracted from $PGPASSWORD.
This commit is contained in:
Ian Barwick
2017-08-31 14:57:07 +09:00
parent 677cd9073a
commit 0e0b221507
8 changed files with 45 additions and 28 deletions

View File

@@ -1220,7 +1220,7 @@ needs to follow another server which has become the new primary. Note that
these commands can be any valid shell script which results in one of these
two actions happening, but if `repmgr`'s `standby follow` or `standby promote`
commands are not executed (either directly as shown here, or from a script which
performs other actions), the `rempgr` metadata will not be updated and
performs other actions), the `repmgr` metadata will not be updated and
monitoring will no longer function reliably.
To demonstrate automatic failover, set up a 3-node replication cluster (one primary

View File

@@ -226,7 +226,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
memset(options->log_file, 0, sizeof(options->log_file));
options->log_status_interval = DEFAULT_LOG_STATUS_INTERVAL;
/* standby clone settings
/* standby action settings
* ----------------------- */
options->use_replication_slots = false;
memset(options->rsync_options, 0, sizeof(options->rsync_options));
@@ -238,6 +238,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
options->tablespace_mapping.head = NULL;
options->tablespace_mapping.tail = NULL;
memset(options->recovery_min_apply_delay, 0, sizeof(options->recovery_min_apply_delay));
options->use_primary_conninfo_password = false;
/* repmgrd settings
* ---------------- */
@@ -395,6 +396,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
strncpy(options->restore_command, value, MAXLEN);
else if (strcmp(name, "recovery_min_apply_delay") == 0)
parse_time_unit_parameter(name, value, options->recovery_min_apply_delay, error_list);
else if (strcmp(name, "use_primary_conninfo_password") == 0)
options->use_primary_conninfo_password = parse_bool(value, name, error_list);
/* node check settings */
else if (strcmp(name, "archive_ready_warning") == 0)

View File

@@ -68,7 +68,7 @@ typedef struct
char log_file[MAXLEN];
int log_status_interval;
/* standby clone settings */
/* standby action settings */
bool use_replication_slots;
char rsync_options[MAXLEN];
char ssh_options[MAXLEN];
@@ -76,6 +76,7 @@ typedef struct
char restore_command[MAXLEN];
TablespaceList tablespace_mapping;
char recovery_min_apply_delay[MAXLEN];
bool use_primary_conninfo_password;
/* node check settings */
int archive_ready_warning;
@@ -134,8 +135,8 @@ typedef struct
UNKNOWN_NODE_ID, "", "", "", "", "", REPLICATION_TYPE_PHYSICAL, \
/* log settings */ \
"", "", "", DEFAULT_LOG_STATUS_INTERVAL, \
/* standby clone settings */ \
false, "", "", "", "", { NULL, NULL }, "", \
/* standby action settings */ \
false, "", "", "", "", { NULL, NULL }, "", false, \
/* node check settings */ \
DEFAULT_ARCHIVE_READY_WARNING, DEFAULT_ARCHIVE_READY_CRITICAL, \
DEFAULT_REPLICATION_LAG_WARNING, DEFAULT_REPLICATION_LAG_CRITICAL, \

View File

@@ -101,7 +101,6 @@ static CheckStatus parse_node_check_replication_lag(const char *node_check_outpu
* --copy-external-config-files
* --recovery-min-apply-delay
* --replication-user (only required if no upstream record)
* --use-recovery-conninfo-password XXX not implemented!
* --without-barman
*/

View File

@@ -66,7 +66,6 @@ typedef struct
char replication_user[MAXLEN];
char upstream_conninfo[MAXLEN];
int upstream_node_id;
bool use_recovery_conninfo_password;
bool without_barman;
/* "standby register" options */
@@ -124,7 +123,7 @@ typedef struct
UNKNOWN_NODE_ID, "", "", \
/* "standby clone" options */ \
false, CONFIG_FILE_SAMEPATH, false, false, false, "", "", "", \
NO_UPSTREAM_NODE, false, false, \
NO_UPSTREAM_NODE, false, \
/* "standby register" options */ \
false, 0, \
/* "standby switchover" options */ \

View File

@@ -93,6 +93,8 @@ main(int argc, char **argv)
bool help_option = false;
char *foo = "";
set_progname(argv[0]);
/*
@@ -117,6 +119,10 @@ main(int argc, char **argv)
*/
initialize_conninfo_params(&default_conninfo, true);
/* foo = param_list_to_string(&default_conninfo);
printf("XX '%s'\n", foo);
exit(0);*/
for (c = 0; c < default_conninfo.size && default_conninfo.keywords[c]; c++)
{
if (strcmp(default_conninfo.keywords[c], "host") == 0 &&
@@ -349,10 +355,6 @@ main(int argc, char **argv)
strncpy(runtime_options.upstream_conninfo, optarg, MAXLEN);
break;
case OPT_USE_RECOVERY_CONNINFO_PASSWORD:
runtime_options.use_recovery_conninfo_password = true;
break;
case OPT_WITHOUT_BARMAN:
runtime_options.without_barman = true;
break;
@@ -1211,12 +1213,6 @@ check_cli_parameters(const int action)
if (*runtime_options.upstream_conninfo)
{
if (runtime_options.use_recovery_conninfo_password == true)
{
item_list_append(&cli_warnings,
_("--use-recovery-conninfo-password ineffective when specifying --upstream-conninfo"));
}
if (*runtime_options.replication_user)
{
item_list_append(&cli_warnings,
@@ -2662,8 +2658,12 @@ write_primary_conninfo(char *line, t_conninfo_param_list *param_list)
{
PQExpBufferData conninfo_buf;
bool application_name_provided = false;
bool password_provided = false;
int c;
char *escaped = NULL;
t_conninfo_param_list env_conninfo;
initialize_conninfo_params(&env_conninfo, true);
initPQExpBuffer(&conninfo_buf);
@@ -2680,9 +2680,10 @@ write_primary_conninfo(char *line, t_conninfo_param_list *param_list)
continue;
/* only include "password" if explicitly requested */
if (runtime_options.use_recovery_conninfo_password == false &&
strcmp(param_list->keywords[c], "password") == 0)
continue;
if (strcmp(param_list->keywords[c], "password") == 0)
{
password_provided = true;
}
if (conninfo_buf.len != 0)
appendPQExpBufferChar(&conninfo_buf, ' ');
@@ -2694,7 +2695,7 @@ write_primary_conninfo(char *line, t_conninfo_param_list *param_list)
appendConnStrVal(&conninfo_buf, param_list->values[c]);
}
/* `application_name` not provided - default to repmgr node name */
/* "application_name" not provided - default to repmgr node name */
if (application_name_provided == false)
{
if (strlen(config_file_options.node_name))
@@ -2707,12 +2708,27 @@ write_primary_conninfo(char *line, t_conninfo_param_list *param_list)
appendPQExpBuffer(&conninfo_buf, " application_name=repmgr");
}
}
escaped = escape_recovery_conf_value(conninfo_buf.data);
/* no password provided explicitly */
if (password_provided == false)
{
if (config_file_options.use_primary_conninfo_password == true)
{
const char *password = param_get(&env_conninfo, "password");
if (password != NULL)
{
appendPQExpBuffer(&conninfo_buf, " password=");
appendConnStrVal(&conninfo_buf, password);
}
}
}
escaped = escape_recovery_conf_value(conninfo_buf.data);
maxlen_snprintf(line, "primary_conninfo = '%s'\n", escaped);
free(escaped);
free_conninfo_params(&env_conninfo);
termPQExpBuffer(&conninfo_buf);
}

View File

@@ -49,8 +49,6 @@
#define OPT_REGISTER_WAIT 1014
#define OPT_LOG_TO_FILE 1015
#define OPT_UPSTREAM_CONNINFO 1016
/* replaces --no-conninfo-password */
#define OPT_USE_RECOVERY_CONNINFO_PASSWORD 1017
#define OPT_REPLICATION_USER 1018
#define OPT_EVENT 1019
#define OPT_LIMIT 1020
@@ -123,7 +121,6 @@ static struct option long_options[] =
{"replication-user", required_argument, NULL, OPT_REPLICATION_USER},
{"upstream-conninfo", required_argument, NULL, OPT_UPSTREAM_CONNINFO},
{"upstream-node-id", required_argument, NULL, OPT_UPSTREAM_NODE_ID},
{"use-recovery-conninfo-password", no_argument, NULL, OPT_USE_RECOVERY_CONNINFO_PASSWORD},
{"without-barman", no_argument, NULL, OPT_WITHOUT_BARMAN},
/* "standby register" options */

View File

@@ -126,7 +126,9 @@
# Debian/Ubuntu users: you will probably need to
# set this to the directory where `pg_ctl` is located,
# e.g. /usr/lib/postgresql/9.6/bin/
#use_primary_conninfo_password=false # explicitly set "password" in recovery.conf's
# "primary_conninfo" parameter using the value contained
# in the environment variable PGPASSWORD
#------------------------------------------------------------------------------
# external command options