diff --git a/HISTORY b/HISTORY index c34e9f05..a300cfe2 100644 --- a/HISTORY +++ b/HISTORY @@ -4,6 +4,7 @@ repmgr: improve switchover log messages and exit code when old primary could not be shut down cleanly (Ian) repmgr: add --dry-run mode to "repmgr standby follow"; GitHub #368 (Ian) + repmgr: fix upstream node display in "repmgr node status"; GitHub #363 (fanf2) 4.0.2 2018-01-18 repmgr: add missing -W option to getopt_long() invocation; GitHub #350 (Ian) diff --git a/dbutils.c b/dbutils.c index afa06ca9..435cae33 100644 --- a/dbutils.c +++ b/dbutils.c @@ -2123,7 +2123,11 @@ get_node_records_by_priority(PGconn *conn, NodeInfoList *node_list) return; } -void +/* + * return all node records together with their upstream's node name, + * if available. + */ +bool get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list) { PQExpBufferData query; @@ -2145,11 +2149,19 @@ get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list) termPQExpBuffer(&query); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + log_error(_("unable to retrieve node records")); + log_detail("%s", PQerrorMessage(conn)); + PQclear(res); + return false; + } + _populate_node_records(res, node_list); PQclear(res); - return; + return true; } @@ -2271,9 +2283,11 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info) if (PQresultStatus(res) != PGRES_COMMAND_OK) { - log_error(_("unable to %s node record:\n %s"), + log_error(_("unable to %s node record for node \"%s\" (ID: %i)"), action, - PQerrorMessage(conn)); + node_info->node_name, + node_info->node_id); + log_detail("%s", PQerrorMessage(conn)); PQclear(res); return false; } diff --git a/dbutils.h b/dbutils.h index b59b6de8..9e4cd4d0 100644 --- a/dbutils.h +++ b/dbutils.h @@ -410,7 +410,7 @@ void get_all_node_records(PGconn *conn, NodeInfoList *node_list); void get_downstream_node_records(PGconn *conn, int node_id, NodeInfoList *nodes); void get_active_sibling_node_records(PGconn *conn, int node_id, int upstream_node_id, NodeInfoList *node_list); void get_node_records_by_priority(PGconn *conn, NodeInfoList *node_list); -void get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list); +bool get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list); bool create_node_record(PGconn *conn, char *repmgr_action, t_node_info *node_info); bool update_node_record(PGconn *conn, char *repmgr_action, t_node_info *node_info); diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index 7d196292..8ecd0959 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -82,6 +82,7 @@ do_cluster_show(void) NodeInfoListCell *cell = NULL; int i = 0; ItemList warnings = {NULL, NULL}; + bool success = false; /* Connect to local database to obtain cluster connection data */ log_verbose(LOG_INFO, _("connecting to database")); @@ -91,11 +92,19 @@ do_cluster_show(void) else conn = establish_db_connection_by_params(&source_conninfo, true); - get_all_node_records_with_upstream(conn, &nodes); + success = get_all_node_records_with_upstream(conn, &nodes); + + if (success == false) + { + /* get_all_node_records_with_upstream() will print error message */ + PQfinish(conn); + exit(ERR_BAD_CONFIG); + } if (nodes.node_count == 0) { - log_error(_("unable to retrieve any node records")); + log_error(_("no node records were found")); + log_hint(_("ensure at least one node is registered")); PQfinish(conn); exit(ERR_BAD_CONFIG); }