mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
Merge pull request #1 from 2ndquadrant-it/master
Added function "write_primary_conninfo" which now adds the username to the primary_conninfo parameter in recovery.conf Author: Gabriele and Marco
This commit is contained in:
71
repmgr.c
71
repmgr.c
@@ -55,6 +55,7 @@ static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
static bool check_parameters_for_action(const int action);
|
static bool check_parameters_for_action(const int action);
|
||||||
static bool create_schema(PGconn *conn);
|
static bool create_schema(PGconn *conn);
|
||||||
static bool copy_configuration(PGconn *masterconn, PGconn *witnessconn);
|
static bool copy_configuration(PGconn *masterconn, PGconn *witnessconn);
|
||||||
|
static void write_primary_conninfo(char* line);
|
||||||
|
|
||||||
static void do_master_register(void);
|
static void do_master_register(void);
|
||||||
static void do_standby_register(void);
|
static void do_standby_register(void);
|
||||||
@@ -1599,39 +1600,7 @@ create_recovery_file(const char *data_dir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxlen_snprintf(line, "primary_conninfo = 'host=%s port=%s'\n", runtime_options.host,
|
write_primary_conninfo(line);
|
||||||
(runtime_options.masterport[0]) ? runtime_options.masterport : "5432");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Template a password into the connection string in recovery.conf
|
|
||||||
*
|
|
||||||
* Sometimes this is passed by the user explicitly, and otherwise
|
|
||||||
* we try to get it into the environment.
|
|
||||||
*
|
|
||||||
* XXX: This is pretty dirty, at least push this up to the caller rather
|
|
||||||
* than hitting environment variables at this level.
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
char *password = getenv("PGPASSWORD");
|
|
||||||
|
|
||||||
if (password != NULL)
|
|
||||||
{
|
|
||||||
maxlen_snprintf(line,
|
|
||||||
"primary_conninfo = 'host=%s port=%s password=%s'\n",
|
|
||||||
runtime_options.host,
|
|
||||||
(runtime_options.masterport[0]) ? runtime_options.masterport : "5432",
|
|
||||||
password);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (require_password)
|
|
||||||
{
|
|
||||||
log_err(_("%s: PGPASSWORD not set, but having one is required\n"),
|
|
||||||
progname);
|
|
||||||
exit(ERR_BAD_PASSWORD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fputs(line, recovery_file) == EOF)
|
if (fputs(line, recovery_file) == EOF)
|
||||||
{
|
{
|
||||||
@@ -2021,3 +1990,39 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function uses global variables to determine connection settings. Special
|
||||||
|
* usage of the PGPASSWORD variable is handled, but strongly discouraged */
|
||||||
|
static void
|
||||||
|
write_primary_conninfo(char* line)
|
||||||
|
{
|
||||||
|
char host_buf[MAXLEN] = "";
|
||||||
|
char conn_buf[MAXLEN] = "";
|
||||||
|
char user_buf[MAXLEN] = "";
|
||||||
|
char password_buf[MAXLEN] = "";
|
||||||
|
|
||||||
|
/* Environment variable for password (UGLY, please use .pgpass!) */
|
||||||
|
const char *password = getenv("PGPASSWORD");
|
||||||
|
if (password != NULL) {
|
||||||
|
maxlen_snprintf(password_buf, " password=%s", password);
|
||||||
|
}
|
||||||
|
else if (require_password) {
|
||||||
|
log_err(_("%s: PGPASSWORD not set, but having one is required\n"),
|
||||||
|
progname);
|
||||||
|
exit(ERR_BAD_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runtime_options.host[0]) {
|
||||||
|
maxlen_snprintf(host_buf, " host=%s", runtime_options.host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runtime_options.username[0]) {
|
||||||
|
maxlen_snprintf(user_buf, " user=%s", runtime_options.username);
|
||||||
|
}
|
||||||
|
|
||||||
|
maxlen_snprintf(conn_buf, "port=%s%s%s%s",
|
||||||
|
(runtime_options.masterport[0]) ? runtime_options.masterport : "5432", host_buf, user_buf, password_buf);
|
||||||
|
|
||||||
|
maxlen_snprintf(line, "primary_conninfo = '%s'", conn_buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user