From 6b95a96f3ac503724ee8657063b526df15b4a073 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 7 Sep 2018 16:51:52 +0900 Subject: [PATCH] repmgr: improve "cluster show" output Only output full contents of connection error messages in --verbose mode, otherwise it can spew a lot of text onto the screen. --- doc/repmgr-cluster-show.sgml | 66 +++++++++++++++++++++++------------- repmgr-action-cluster.c | 30 ++++++++++++---- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/doc/repmgr-cluster-show.sgml b/doc/repmgr-cluster-show.sgml index 50fcad45..a096ff12 100644 --- a/doc/repmgr-cluster-show.sgml +++ b/doc/repmgr-cluster-show.sgml @@ -81,36 +81,56 @@ Options - - repmgr cluster show accepts an optional parameter --csv, which - outputs the replication cluster's status in a simple CSV format, suitable for - parsing by scripts: - + + + + + + + + repmgr cluster show accepts an optional parameter --csv, which + outputs the replication cluster's status in a simple CSV format, suitable for + parsing by scripts: + $ repmgr -f /etc/repmgr.conf cluster show --csv 1,-1,-1 2,0,0 3,0,1 - - - The columns have following meanings: - - - - node ID - - - - + + + The columns have following meanings: + + + + node ID + + + + availability (0 = available, -1 = unavailable) - - + + + + + recovery state (0 = not in recovery, 1 = in recovery, -1 = unknown) + + + + + + + + + - - recovery state (0 = not in recovery, 1 = in recovery, -1 = unknown) - + + Display the full text of any database connection error messages + - - + + + + diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index 5069e5c4..83083e6f 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -84,6 +84,7 @@ do_cluster_show(void) ItemList warnings = {NULL, NULL}; bool success = false; bool error_found = false; + bool connection_error_found = false; /* Connect to local database to obtain cluster connection data */ log_verbose(LOG_INFO, _("connecting to database")); @@ -141,14 +142,26 @@ do_cluster_show(void) } else { - char error[MAXLEN]; - - strncpy(error, PQerrorMessage(cell->node_info->conn), MAXLEN); cell->node_info->node_status = NODE_STATUS_DOWN; cell->node_info->recovery_type = RECTYPE_UNKNOWN; - item_list_append_format(&warnings, - "when attempting to connect to node \"%s\" (ID: %i), following error encountered :\n\"%s\"", - cell->node_info->node_name, cell->node_info->node_id, trim(error)); + + connection_error_found = true; + + if (runtime_options.verbose) + { + char error[MAXLEN]; + + strncpy(error, PQerrorMessage(cell->node_info->conn), MAXLEN); + item_list_append_format(&warnings, + "when attempting to connect to node \"%s\" (ID: %i), following error encountered :\n\"%s\"", + cell->node_info->node_name, cell->node_info->node_id, trim(error)); + } + else + { + item_list_append_format(&warnings, + "unable to connect to node \"%s\" (ID: %i)", + cell->node_info->node_name, cell->node_info->node_id); + } } initPQExpBuffer(&details); @@ -437,6 +450,11 @@ do_cluster_show(void) { printf(_(" - %s\n"), cell->string); } + + if (runtime_options.verbose == false && connection_error_found == true) + { + log_hint(_("execute with --verbose option to see connection error messages")); + } } /*