mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
Suppress connection error display in repmgr cluster show
This prevents connection error messages being mixed in with `repmgr cluster show` output. Error message output can still be enabled with the --verbose flag. Fixes GitHub #215
This commit is contained in:
4
HISTORY
4
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
|
3.1.4 2016-07-12
|
||||||
repmgr: new configuration option for setting "restore_command"
|
repmgr: new configuration option for setting "restore_command"
|
||||||
in the recovery.conf file generated by repmgr (Martín)
|
in the recovery.conf file generated by repmgr (Martín)
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -1401,17 +1401,20 @@ which contains connection details for the local database.
|
|||||||
when analyzing connectivity from a particular node.
|
when analyzing connectivity from a particular node.
|
||||||
|
|
||||||
This command requires a valid `repmgr.conf` file to be provided; no
|
This command requires a valid `repmgr.conf` file to be provided; no
|
||||||
additional arguments are required.
|
additional arguments are needed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ repmgr -f /etc/repmgr.conf cluster show
|
$ repmgr -f /etc/repmgr.conf cluster show
|
||||||
|
|
||||||
Role | Name | Upstream | Connection String
|
Role | Name | Upstream | Connection String
|
||||||
----------+-------|----------|--------------------------------------------
|
----------+-------|----------|----------------------------------------
|
||||||
* master | node1 | | host=repmgr_node1 dbname=repmgr user=repmgr
|
* master | node1 | | host=db_node1 dbname=repmgr user=repmgr
|
||||||
standby | node2 | node1 | host=repmgr_node1 dbname=repmgr user=repmgr
|
standby | node2 | node1 | host=db_node2 dbname=repmgr user=repmgr
|
||||||
standby | node3 | node2 | host=repmgr_node1 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`
|
* `cluster cleanup`
|
||||||
|
|
||||||
|
|||||||
51
dbutils.c
51
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);
|
static int _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_info);
|
||||||
|
|
||||||
PGconn *
|
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 */
|
/* Make a connection to the database */
|
||||||
PGconn *conn = NULL;
|
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 */
|
/* Check to see that the backend connection was successfully made */
|
||||||
if ((PQstatus(conn) != CONNECTION_OK))
|
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"),
|
if (log_notice)
|
||||||
PQerrorMessage(conn));
|
{
|
||||||
}
|
log_notice(_("connection to database failed: %s\n"),
|
||||||
else
|
PQerrorMessage(conn));
|
||||||
{
|
}
|
||||||
log_err(_("connection to database failed: %s\n"),
|
else
|
||||||
PQerrorMessage(conn));
|
{
|
||||||
|
log_err(_("connection to database failed: %s\n"),
|
||||||
|
PQerrorMessage(conn));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exit_on_error)
|
if (exit_on_error)
|
||||||
@@ -72,16 +80,35 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Establish a database connection, optionally exit on error
|
||||||
|
*/
|
||||||
PGconn *
|
PGconn *
|
||||||
establish_db_connection(const char *conninfo, const bool exit_on_error)
|
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 *
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,11 +82,12 @@ extern char repmgr_schema[MAXLEN];
|
|||||||
|
|
||||||
PGconn *_establish_db_connection(const char *conninfo,
|
PGconn *_establish_db_connection(const char *conninfo,
|
||||||
const bool exit_on_error,
|
const bool exit_on_error,
|
||||||
const bool log_notice);
|
const bool log_notice,
|
||||||
|
const bool verbose_only);
|
||||||
PGconn *establish_db_connection(const char *conninfo,
|
PGconn *establish_db_connection(const char *conninfo,
|
||||||
const bool exit_on_error);
|
const bool exit_on_error);
|
||||||
PGconn *test_db_connection(const char *conninfo,
|
PGconn *establish_db_connection_quiet(const char *conninfo);
|
||||||
const bool exit_on_error);
|
PGconn *test_db_connection(const char *conninfo);
|
||||||
PGconn *establish_db_connection_by_params(const char *keywords[],
|
PGconn *establish_db_connection_by_params(const char *keywords[],
|
||||||
const char *values[],
|
const char *values[],
|
||||||
const bool exit_on_error);
|
const bool exit_on_error);
|
||||||
|
|||||||
4
log.h
4
log.h
@@ -130,5 +130,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
|||||||
|
|
||||||
extern int log_type;
|
extern int log_type;
|
||||||
extern int log_level;
|
extern int log_level;
|
||||||
|
extern int verbose_logging;
|
||||||
|
extern int terse_logging;
|
||||||
|
|
||||||
#endif
|
#endif /* _REPMGR_LOG_H_ */
|
||||||
|
|||||||
8
repmgr.c
8
repmgr.c
@@ -895,7 +895,7 @@ do_cluster_show(void)
|
|||||||
upstream_length,
|
upstream_length,
|
||||||
conninfo_length = 0;
|
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"));
|
log_info(_("connecting to database\n"));
|
||||||
conn = establish_db_connection(options.conninfo, true);
|
conn = establish_db_connection(options.conninfo, true);
|
||||||
|
|
||||||
@@ -970,7 +970,8 @@ do_cluster_show(void)
|
|||||||
|
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
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)
|
if (PQstatus(conn) != CONNECTION_OK)
|
||||||
strcpy(node_role, " FAILED");
|
strcpy(node_role, " FAILED");
|
||||||
else if (strcmp(PQgetvalue(res, i, 1), "witness") == 0)
|
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++)
|
for(i = 0; i < options.reconnect_attempts; i++)
|
||||||
{
|
{
|
||||||
/* Check whether primary is available */
|
/* Check whether primary is available */
|
||||||
|
remote_conn = test_db_connection(remote_conninfo);
|
||||||
remote_conn = test_db_connection(remote_conninfo, false); /* don't fail on error */
|
|
||||||
|
|
||||||
if (PQstatus(remote_conn) == CONNECTION_OK)
|
if (PQstatus(remote_conn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user