diff --git a/HISTORY b/HISTORY index 49e623b4..72508957 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +3.2 2016- + repmgr: suppress connection error display in `repmgr cluster show` + unless `--verbose` supplied (Ian) + 3.1.4 2016-07-12 repmgr: new configuration option for setting "restore_command" in the recovery.conf file generated by repmgr (Martín) diff --git a/README.md b/README.md index 02759637..841bfc87 100644 --- a/README.md +++ b/README.md @@ -1401,17 +1401,20 @@ which contains connection details for the local database. when analyzing connectivity from a particular node. This command requires a valid `repmgr.conf` file to be provided; no - additional arguments are required. + additional arguments are needed. Example: $ repmgr -f /etc/repmgr.conf cluster show Role | Name | Upstream | Connection String - ----------+-------|----------|-------------------------------------------- - * master | node1 | | host=repmgr_node1 dbname=repmgr user=repmgr - standby | node2 | node1 | host=repmgr_node1 dbname=repmgr user=repmgr - standby | node3 | node2 | host=repmgr_node1 dbname=repmgr user=repmgr + ----------+-------|----------|---------------------------------------- + * master | node1 | | host=db_node1 dbname=repmgr user=repmgr + standby | node2 | node1 | host=db_node2 dbname=repmgr user=repmgr + standby | node3 | node2 | host=db_node3 dbname=repmgr user=repmgr + + To show database connection errors when polling nodes, run the command in + `--verbose` mode. * `cluster cleanup` diff --git a/dbutils.c b/dbutils.c index c0034fbf..66ab4067 100644 --- a/dbutils.c +++ b/dbutils.c @@ -35,7 +35,7 @@ char repmgr_schema_quoted[MAXLEN] = ""; static int _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_info); PGconn * -_establish_db_connection(const char *conninfo, const bool exit_on_error, const bool log_notice) +_establish_db_connection(const char *conninfo, const bool exit_on_error, const bool log_notice, const bool verbose_only) { /* Make a connection to the database */ PGconn *conn = NULL; @@ -51,15 +51,23 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b /* Check to see that the backend connection was successfully made */ if ((PQstatus(conn) != CONNECTION_OK)) { - if (log_notice) + bool emit_log = true; + + if (verbose_only == true && verbose_logging == false) + emit_log = false; + + if (emit_log) { - log_notice(_("connection to database failed: %s\n"), - PQerrorMessage(conn)); - } - else - { - log_err(_("connection to database failed: %s\n"), - PQerrorMessage(conn)); + if (log_notice) + { + log_notice(_("connection to database failed: %s\n"), + PQerrorMessage(conn)); + } + else + { + log_err(_("connection to database failed: %s\n"), + PQerrorMessage(conn)); + } } if (exit_on_error) @@ -72,16 +80,35 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b return conn; } + +/* + * Establish a database connection, optionally exit on error + */ PGconn * establish_db_connection(const char *conninfo, const bool exit_on_error) { - return _establish_db_connection(conninfo, exit_on_error, false); + return _establish_db_connection(conninfo, exit_on_error, false, false); } +/* + * Attempt to establish a database connection, never exit on error, only + * output error messages if --verbose option used + */ PGconn * -test_db_connection(const char *conninfo, const bool exit_on_error) +establish_db_connection_quiet(const char *conninfo) { - return _establish_db_connection(conninfo, exit_on_error, true); + return _establish_db_connection(conninfo, false, false, true); +} + +/* + * Attempt to establish a database connection, never exit on error, + * output connection error messages as NOTICE (useful when connection + * failure is expected) + */ +PGconn * +test_db_connection(const char *conninfo) +{ + return _establish_db_connection(conninfo, false, true, false); } diff --git a/dbutils.h b/dbutils.h index 89b40454..ce9135bc 100644 --- a/dbutils.h +++ b/dbutils.h @@ -82,11 +82,12 @@ extern char repmgr_schema[MAXLEN]; PGconn *_establish_db_connection(const char *conninfo, const bool exit_on_error, - const bool log_notice); + const bool log_notice, + const bool verbose_only); PGconn *establish_db_connection(const char *conninfo, const bool exit_on_error); -PGconn *test_db_connection(const char *conninfo, - const bool exit_on_error); +PGconn *establish_db_connection_quiet(const char *conninfo); +PGconn *test_db_connection(const char *conninfo); PGconn *establish_db_connection_by_params(const char *keywords[], const char *values[], const bool exit_on_error); diff --git a/log.h b/log.h index e717be98..58f7b459 100644 --- a/log.h +++ b/log.h @@ -130,5 +130,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); extern int log_type; extern int log_level; +extern int verbose_logging; +extern int terse_logging; -#endif +#endif /* _REPMGR_LOG_H_ */ diff --git a/repmgr.c b/repmgr.c index 10f79715..cc19758f 100644 --- a/repmgr.c +++ b/repmgr.c @@ -895,7 +895,7 @@ do_cluster_show(void) upstream_length, conninfo_length = 0; - /* We need to connect to check configuration */ + /* Connect to local database to obtain cluster connection data */ log_info(_("connecting to database\n")); conn = establish_db_connection(options.conninfo, true); @@ -970,7 +970,8 @@ do_cluster_show(void) for (i = 0; i < PQntuples(res); i++) { - conn = establish_db_connection(PQgetvalue(res, i, 0), false); + conn = establish_db_connection_quiet(PQgetvalue(res, i, 0)); + if (PQstatus(conn) != CONNECTION_OK) strcpy(node_role, " FAILED"); else if (strcmp(PQgetvalue(res, i, 1), "witness") == 0) @@ -3499,8 +3500,7 @@ do_standby_switchover(void) for(i = 0; i < options.reconnect_attempts; i++) { /* Check whether primary is available */ - - remote_conn = test_db_connection(remote_conninfo, false); /* don't fail on error */ + remote_conn = test_db_connection(remote_conninfo); if (PQstatus(remote_conn) == CONNECTION_OK) {