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.
This commit is contained in:
Ian Barwick
2018-09-07 16:51:52 +09:00
committed by Ian Barwick
parent bd146ae9ac
commit 6b95a96f3a
2 changed files with 67 additions and 29 deletions

View File

@@ -81,6 +81,12 @@
<refsect1> <refsect1>
<title>Options</title> <title>Options</title>
<variablelist>
<varlistentry>
<term><option>--csv</option></term>
<listitem>
<para> <para>
<command>repmgr cluster show</command> accepts an optional parameter <literal>--csv</literal>, which <command>repmgr cluster show</command> accepts an optional parameter <literal>--csv</literal>, which
outputs the replication cluster's status in a simple CSV format, suitable for outputs the replication cluster's status in a simple CSV format, suitable for
@@ -111,6 +117,20 @@
</listitem> </listitem>
</itemizedlist> </itemizedlist>
</para> </para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--verbose</option></term>
<listitem>
<para>
Display the full text of any database connection error messages
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1> </refsect1>

View File

@@ -84,6 +84,7 @@ do_cluster_show(void)
ItemList warnings = {NULL, NULL}; ItemList warnings = {NULL, NULL};
bool success = false; bool success = false;
bool error_found = false; bool error_found = false;
bool connection_error_found = false;
/* Connect to local database to obtain cluster connection data */ /* Connect to local database to obtain cluster connection data */
log_verbose(LOG_INFO, _("connecting to database")); log_verbose(LOG_INFO, _("connecting to database"));
@@ -140,16 +141,28 @@ do_cluster_show(void)
cell->node_info->recovery_type = get_recovery_type(cell->node_info->conn); cell->node_info->recovery_type = get_recovery_type(cell->node_info->conn);
} }
else else
{
cell->node_info->node_status = NODE_STATUS_DOWN;
cell->node_info->recovery_type = RECTYPE_UNKNOWN;
connection_error_found = true;
if (runtime_options.verbose)
{ {
char error[MAXLEN]; char error[MAXLEN];
strncpy(error, PQerrorMessage(cell->node_info->conn), 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, item_list_append_format(&warnings,
"when attempting to connect to node \"%s\" (ID: %i), following error encountered :\n\"%s\"", "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)); 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); initPQExpBuffer(&details);
@@ -437,6 +450,11 @@ do_cluster_show(void)
{ {
printf(_(" - %s\n"), cell->string); 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"));
}
} }
/* /*