mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 08:06:29 +00:00
Consolidate code for establishing a superuser connection
This commit is contained in:
40
dbutils.c
40
dbutils.c
@@ -236,6 +236,46 @@ establish_db_connection_quiet(const char *conninfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PGconn *
|
||||||
|
establish_db_connection_with_replacement_param(const char *conninfo,
|
||||||
|
const char *param,
|
||||||
|
const char *value,
|
||||||
|
const bool exit_on_error)
|
||||||
|
{
|
||||||
|
t_conninfo_param_list node_conninfo = T_CONNINFO_PARAM_LIST_INITIALIZER;
|
||||||
|
char *errmsg = NULL;
|
||||||
|
bool parse_success = false;
|
||||||
|
PGconn *conn = NULL;
|
||||||
|
|
||||||
|
initialize_conninfo_params(&node_conninfo, false);
|
||||||
|
|
||||||
|
parse_success = parse_conninfo_string(conninfo,
|
||||||
|
&node_conninfo,
|
||||||
|
&errmsg, false);
|
||||||
|
|
||||||
|
if (parse_success == false)
|
||||||
|
{
|
||||||
|
log_error(_("unable to parse conninfo string \"%s\" for local node"),
|
||||||
|
conninfo);
|
||||||
|
log_detail("%s", errmsg);
|
||||||
|
|
||||||
|
if (exit_on_error == true)
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
param_set(&node_conninfo,
|
||||||
|
param,
|
||||||
|
value);
|
||||||
|
|
||||||
|
conn = establish_db_connection_by_params(&node_conninfo, exit_on_error);
|
||||||
|
|
||||||
|
free_conninfo_params(&node_conninfo);
|
||||||
|
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
PGconn *
|
PGconn *
|
||||||
establish_primary_db_connection(PGconn *conn,
|
establish_primary_db_connection(PGconn *conn,
|
||||||
const bool exit_on_error)
|
const bool exit_on_error)
|
||||||
|
|||||||
@@ -388,6 +388,10 @@ PGconn *establish_db_connection(const char *conninfo,
|
|||||||
PGconn *establish_db_connection_quiet(const char *conninfo);
|
PGconn *establish_db_connection_quiet(const char *conninfo);
|
||||||
PGconn *establish_db_connection_by_params(t_conninfo_param_list *param_list,
|
PGconn *establish_db_connection_by_params(t_conninfo_param_list *param_list,
|
||||||
const bool exit_on_error);
|
const bool exit_on_error);
|
||||||
|
PGconn *establish_db_connection_with_replacement_param(const char *conninfo,
|
||||||
|
const char *param,
|
||||||
|
const char *value,
|
||||||
|
const bool exit_on_error);
|
||||||
PGconn *establish_replication_connection_from_conn(PGconn *conn, const char *repluser);
|
PGconn *establish_replication_connection_from_conn(PGconn *conn, const char *repluser);
|
||||||
PGconn *establish_replication_connection_from_conninfo(const char *conninfo, const char *repluser);
|
PGconn *establish_replication_connection_from_conninfo(const char *conninfo, const char *repluser);
|
||||||
|
|
||||||
|
|||||||
@@ -744,12 +744,16 @@ do_node_check(void)
|
|||||||
|
|
||||||
if (runtime_options.superuser[0] != '\0')
|
if (runtime_options.superuser[0] != '\0')
|
||||||
{
|
{
|
||||||
param_set(&node_conninfo,
|
conn = establish_db_connection_with_replacement_param(
|
||||||
"user",
|
config_file_options.conninfo,
|
||||||
runtime_options.superuser);
|
"user",
|
||||||
|
runtime_options.superuser,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn = establish_db_connection_by_params(&node_conninfo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = establish_db_connection_by_params(&node_conninfo, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2030,37 +2034,21 @@ do_node_service(void)
|
|||||||
|
|
||||||
if (config_file_options.conninfo[0] != '\0')
|
if (config_file_options.conninfo[0] != '\0')
|
||||||
{
|
{
|
||||||
t_conninfo_param_list node_conninfo = T_CONNINFO_PARAM_LIST_INITIALIZER;
|
|
||||||
char *errmsg = NULL;
|
|
||||||
bool parse_success = false;
|
|
||||||
|
|
||||||
initialize_conninfo_params(&node_conninfo, false);
|
|
||||||
|
|
||||||
parse_success = parse_conninfo_string(config_file_options.conninfo,
|
|
||||||
&node_conninfo,
|
|
||||||
&errmsg, false);
|
|
||||||
|
|
||||||
if (parse_success == false)
|
|
||||||
{
|
|
||||||
log_error(_("unable to parse conninfo string \"%s\" for local node"),
|
|
||||||
config_file_options.conninfo);
|
|
||||||
log_detail("%s", errmsg);
|
|
||||||
|
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If --superuser option provided, attempt to connect as the specified user
|
* If --superuser option provided, attempt to connect as the specified user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (runtime_options.superuser[0] != '\0')
|
if (runtime_options.superuser[0] != '\0')
|
||||||
{
|
{
|
||||||
param_set(&node_conninfo,
|
conn = establish_db_connection_with_replacement_param(
|
||||||
"user",
|
config_file_options.conninfo,
|
||||||
runtime_options.superuser);
|
"user",
|
||||||
|
runtime_options.superuser,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn = establish_db_connection(config_file_options.conninfo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = establish_db_connection_by_params(&node_conninfo, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user