Add configuration file "passfile"

This will enable a custom .pgpass to be included in "primary_conninfo"
(provided it's supported by the libpq version on the standby).
This commit is contained in:
Ian Barwick
2017-11-14 19:30:25 +09:00
parent 2a898721c0
commit d459b92186
6 changed files with 46 additions and 3 deletions

View File

@@ -315,6 +315,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
memset(options->recovery_min_apply_delay, 0, sizeof(options->recovery_min_apply_delay));
options->recovery_min_apply_delay_provided = false;
options->use_primary_conninfo_password = false;
memset(options->passfile, 0, sizeof(options->passfile));
/*-----------------
* repmgrd settings
@@ -495,6 +496,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
}
else if (strcmp(name, "use_primary_conninfo_password") == 0)
options->use_primary_conninfo_password = parse_bool(value, name, error_list);
else if (strcmp(name, "passfile") == 0)
strncpy(options->passfile, value, sizeof(options->passfile));
/* node check settings */
else if (strcmp(name, "archive_ready_warning") == 0)

View File

@@ -90,6 +90,7 @@ typedef struct
char recovery_min_apply_delay[MAXLEN];
bool recovery_min_apply_delay_provided;
bool use_primary_conninfo_password;
char passfile[MAXPGPATH];
/* node check settings */
int archive_ready_warning;
@@ -153,7 +154,7 @@ typedef struct
/* log settings */ \
"", "", "", DEFAULT_LOG_STATUS_INTERVAL, \
/* standby action settings */ \
false, "", "", { NULL, NULL }, "", false, false, \
false, "", "", { NULL, NULL }, "", false, false, "", \
/* node check settings */ \
DEFAULT_ARCHIVE_READY_WARNING, DEFAULT_ARCHIVE_READY_CRITICAL, \
DEFAULT_REPLICATION_LAG_WARNING, DEFAULT_REPLICATION_LAG_CRITICAL, \

View File

@@ -594,7 +594,7 @@ parse_conninfo_string(const char *conninfo_str, t_conninfo_param_list *param_lis
(option->val != NULL && option->val[0] == '\0'))
continue;
/* Ignore application_name */
/* Ignore settings specific to the upstream node */
if (ignore_local_params == true)
{
if (strcmp(option->keyword, "application_name") == 0)
@@ -678,6 +678,33 @@ param_list_to_string(t_conninfo_param_list *param_list)
}
/*
* check whether the libpq version in use recognizes the "passfile" parameter
* (should be 9.6 and later)
*/
bool
has_passfile(void)
{
PQconninfoOption *defs = PQconndefaults();
PQconninfoOption *def = NULL;
bool has_passfile = false;
for (def = defs; def->keyword; def++)
{
if (strcmp(def->keyword, "passfile") == 0)
{
has_passfile = true;
break;
}
}
PQconninfoFree(defs);
return has_passfile;
}
/* ===================== */
/* transaction functions */
/* ===================== */

View File

@@ -357,6 +357,7 @@ void param_set_ine(t_conninfo_param_list *param_list, const char *param, const
char *param_get(t_conninfo_param_list *param_list, const char *param);
bool parse_conninfo_string(const char *conninfo_str, t_conninfo_param_list *param_list, char *errmsg, bool ignore_local_params);
char *param_list_to_string(t_conninfo_param_list *param_list);
bool has_passfile(void);
/* transaction functions */
bool begin_transaction(PGconn *conn);

View File

@@ -4970,6 +4970,17 @@ write_primary_conninfo(char *line, t_conninfo_param_list *param_list)
}
}
/* passfile provided as configuration option */
if (config_file_options.passfile[0] != '\n')
{
/* check if the libpq we're using supports "passfile=" */
if (has_passfile() == true)
{
appendPQExpBuffer(&conninfo_buf, " passfile=");
appendConnStrVal(&conninfo_buf, config_file_options.passfile);
}
}
escaped = escape_recovery_conf_value(conninfo_buf.data);
maxlen_snprintf(line, "primary_conninfo = '%s'\n", escaped);

View File

@@ -134,7 +134,7 @@
#use_primary_conninfo_password=false # explicitly set "password" in recovery.conf's
# "primary_conninfo" parameter using the value contained
# in the environment variable PGPASSWORD
#passfile='' # path to .pgpass file to include in "primary_conninfo"
#------------------------------------------------------------------------------
# external command options
#------------------------------------------------------------------------------