mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
"cluster show": improve handling of database errors
In particular, if running "repmgr cluster show" against a database without the repmgr metadata, showing the error (rather than just "no records found" etc.) will provide some clues about the problem.
This commit is contained in:
1
HISTORY
1
HISTORY
@@ -4,6 +4,7 @@
|
|||||||
repmgr: improve switchover log messages and exit code when old primary could
|
repmgr: improve switchover log messages and exit code when old primary could
|
||||||
not be shut down cleanly (Ian)
|
not be shut down cleanly (Ian)
|
||||||
repmgr: add --dry-run mode to "repmgr standby follow"; GitHub #368 (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
|
4.0.2 2018-01-18
|
||||||
repmgr: add missing -W option to getopt_long() invocation; GitHub #350 (Ian)
|
repmgr: add missing -W option to getopt_long() invocation; GitHub #350 (Ian)
|
||||||
|
|||||||
22
dbutils.c
22
dbutils.c
@@ -2123,7 +2123,11 @@ get_node_records_by_priority(PGconn *conn, NodeInfoList *node_list)
|
|||||||
return;
|
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)
|
get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list)
|
||||||
{
|
{
|
||||||
PQExpBufferData query;
|
PQExpBufferData query;
|
||||||
@@ -2145,11 +2149,19 @@ get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list)
|
|||||||
|
|
||||||
termPQExpBuffer(&query);
|
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);
|
_populate_node_records(res, node_list);
|
||||||
|
|
||||||
PQclear(res);
|
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)
|
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,
|
action,
|
||||||
PQerrorMessage(conn));
|
node_info->node_name,
|
||||||
|
node_info->node_id);
|
||||||
|
log_detail("%s", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_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_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_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 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);
|
bool update_node_record(PGconn *conn, char *repmgr_action, t_node_info *node_info);
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ do_cluster_show(void)
|
|||||||
NodeInfoListCell *cell = NULL;
|
NodeInfoListCell *cell = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
ItemList warnings = {NULL, NULL};
|
ItemList warnings = {NULL, NULL};
|
||||||
|
bool success = 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"));
|
||||||
@@ -91,11 +92,19 @@ do_cluster_show(void)
|
|||||||
else
|
else
|
||||||
conn = establish_db_connection_by_params(&source_conninfo, true);
|
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)
|
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);
|
PQfinish(conn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user