repmgr standby promote: suppress master database connection error message

Otherwise the first line of output is an ERROR, which is confusing,
even though it's expected.
This commit is contained in:
Ian Barwick
2017-06-21 13:21:44 +09:00
parent 0c531e07e7
commit 6cdf73b4cb
3 changed files with 29 additions and 4 deletions

View File

@@ -19,6 +19,8 @@ static PGconn *_establish_db_connection(const char *conninfo,
const bool log_notice, const bool log_notice,
const bool verbose_only); const bool verbose_only);
static PGconn *_get_master_connection(PGconn *standby_conn, int *master_id, char *master_conninfo_out, bool quiet);
static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery); static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery);
static int _get_node_record(PGconn *conn, char *sqlquery, t_node_info *node_info); static int _get_node_record(PGconn *conn, char *sqlquery, t_node_info *node_info);
static void _populate_node_record(PGresult *res, t_node_info *node_info, int row); static void _populate_node_record(PGresult *res, t_node_info *node_info, int row);
@@ -892,8 +894,8 @@ get_recovery_type(PGconn *conn)
*/ */
PGconn * PGconn *
get_master_connection(PGconn *conn, _get_master_connection(PGconn *conn,
int *master_id, char *master_conninfo_out) int *master_id, char *master_conninfo_out, bool quiet)
{ {
PQExpBufferData query; PQExpBufferData query;
@@ -952,7 +954,15 @@ get_master_connection(PGconn *conn,
log_verbose(LOG_INFO, log_verbose(LOG_INFO,
_("checking role of node '%i'"), _("checking role of node '%i'"),
node_id); node_id);
remote_conn = establish_db_connection(remote_conninfo, false);
if (quiet)
{
remote_conn = establish_db_connection_quiet(remote_conninfo);
}
else
{
remote_conn = establish_db_connection(remote_conninfo, false);
}
if (PQstatus(remote_conn) != CONNECTION_OK) if (PQstatus(remote_conn) != CONNECTION_OK)
continue; continue;
@@ -988,8 +998,22 @@ get_master_connection(PGconn *conn,
return NULL; return NULL;
} }
PGconn *
get_master_connection(PGconn *conn,
int *master_id, char *master_conninfo_out)
{
return _get_master_connection(conn, master_id, master_conninfo_out, false);
}
PGconn *
get_master_connection_quiet(PGconn *conn,
int *master_id, char *master_conninfo_out)
{
return _get_master_connection(conn, master_id, master_conninfo_out, true);
}
/* /*
* Return the id of the active master node, or NODE_NOT_FOUND if no * Return the id of the active master node, or NODE_NOT_FOUND if no
* record available. * record available.

View File

@@ -152,6 +152,7 @@ PGconn *establish_master_db_connection(PGconn *conn,
const bool exit_on_error); const bool exit_on_error);
PGconn *get_master_connection(PGconn *standby_conn, int *master_id, char *master_conninfo_out); PGconn *get_master_connection(PGconn *standby_conn, int *master_id, char *master_conninfo_out);
PGconn *get_master_connection_quiet(PGconn *standby_conn, int *master_id, char *master_conninfo_out);
bool is_superuser_connection(PGconn *conn, t_connection_user *userinfo); bool is_superuser_connection(PGconn *conn, t_connection_user *userinfo);

View File

@@ -1084,7 +1084,7 @@ do_standby_promote(void)
/* we also need to check if there isn't any master already */ /* we also need to check if there isn't any master already */
current_master_conn = get_master_connection(conn, &existing_master_id, NULL); current_master_conn = get_master_connection_quiet(conn, &existing_master_id, NULL);
if (PQstatus(current_master_conn) == CONNECTION_OK) if (PQstatus(current_master_conn) == CONNECTION_OK)
{ {