From 6cdf73b4cb2f42ca36c312213a332ad41d39ed94 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 21 Jun 2017 13:21:44 +0900 Subject: [PATCH] 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. --- dbutils.c | 30 +++++++++++++++++++++++++++--- dbutils.h | 1 + repmgr-action-standby.c | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dbutils.c b/dbutils.c index a2f31af1..16cb0309 100644 --- a/dbutils.c +++ b/dbutils.c @@ -19,6 +19,8 @@ static PGconn *_establish_db_connection(const char *conninfo, const bool log_notice, 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 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); @@ -892,8 +894,8 @@ get_recovery_type(PGconn *conn) */ PGconn * -get_master_connection(PGconn *conn, - int *master_id, char *master_conninfo_out) +_get_master_connection(PGconn *conn, + int *master_id, char *master_conninfo_out, bool quiet) { PQExpBufferData query; @@ -952,7 +954,15 @@ get_master_connection(PGconn *conn, log_verbose(LOG_INFO, _("checking role of node '%i'"), 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) continue; @@ -988,8 +998,22 @@ get_master_connection(PGconn *conn, 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 * record available. diff --git a/dbutils.h b/dbutils.h index 8f2e2056..56d9a74b 100644 --- a/dbutils.h +++ b/dbutils.h @@ -152,6 +152,7 @@ PGconn *establish_master_db_connection(PGconn *conn, const bool exit_on_error); 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); diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 7375b1af..37992986 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1084,7 +1084,7 @@ do_standby_promote(void) /* 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) {