mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +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
|
||||
repmgr: new configuration option for setting "restore_command"
|
||||
in the recovery.conf file generated by repmgr (Martín)
|
||||
|
||||
13
README.md
13
README.md
@@ -1382,17 +1382,20 @@ which contains connection details for the local database.
|
||||
when analyzing connectivity from a particular node.
|
||||
|
||||
This command requires a valid `repmgr.conf` file to be provided; no
|
||||
additional arguments are required.
|
||||
additional arguments are needed.
|
||||
|
||||
Example:
|
||||
|
||||
$ repmgr -f /etc/repmgr.conf cluster show
|
||||
|
||||
Role | Name | Upstream | Connection String
|
||||
----------+-------|----------|--------------------------------------------
|
||||
* master | node1 | | host=repmgr_node1 dbname=repmgr user=repmgr
|
||||
standby | node2 | node1 | host=repmgr_node1 dbname=repmgr user=repmgr
|
||||
standby | node3 | node2 | host=repmgr_node1 dbname=repmgr user=repmgr
|
||||
----------+-------|----------|----------------------------------------
|
||||
* master | node1 | | host=db_node1 dbname=repmgr user=repmgr
|
||||
standby | node2 | node1 | host=db_node2 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`
|
||||
|
||||
|
||||
51
dbutils.c
51
dbutils.c
@@ -34,7 +34,7 @@ char repmgr_schema_quoted[MAXLEN] = "";
|
||||
static int _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_info);
|
||||
|
||||
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 */
|
||||
PGconn *conn = NULL;
|
||||
@@ -50,15 +50,23 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b
|
||||
/* Check to see that the backend connection was successfully made */
|
||||
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"),
|
||||
PQerrorMessage(conn));
|
||||
}
|
||||
else
|
||||
{
|
||||
log_err(_("connection to database failed: %s\n"),
|
||||
PQerrorMessage(conn));
|
||||
if (log_notice)
|
||||
{
|
||||
log_notice(_("connection to database failed: %s\n"),
|
||||
PQerrorMessage(conn));
|
||||
}
|
||||
else
|
||||
{
|
||||
log_err(_("connection to database failed: %s\n"),
|
||||
PQerrorMessage(conn));
|
||||
}
|
||||
}
|
||||
|
||||
if (exit_on_error)
|
||||
@@ -71,16 +79,35 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Establish a database connection, optionally exit on error
|
||||
*/
|
||||
PGconn *
|
||||
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 *
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -81,11 +81,12 @@ typedef struct s_replication_slot
|
||||
|
||||
PGconn *_establish_db_connection(const char *conninfo,
|
||||
const bool exit_on_error,
|
||||
const bool log_notice);
|
||||
const bool log_notice,
|
||||
const bool verbose_only);
|
||||
PGconn *establish_db_connection(const char *conninfo,
|
||||
const bool exit_on_error);
|
||||
PGconn *test_db_connection(const char *conninfo,
|
||||
const bool exit_on_error);
|
||||
PGconn *establish_db_connection_quiet(const char *conninfo);
|
||||
PGconn *test_db_connection(const char *conninfo);
|
||||
PGconn *establish_db_connection_by_params(const char *keywords[],
|
||||
const char *values[],
|
||||
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_level;
|
||||
extern int verbose_logging;
|
||||
extern int terse_logging;
|
||||
|
||||
#endif
|
||||
#endif /* _REPMGR_LOG_H_ */
|
||||
|
||||
8
repmgr.c
8
repmgr.c
@@ -871,7 +871,7 @@ do_cluster_show(void)
|
||||
upstream_length,
|
||||
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"));
|
||||
conn = establish_db_connection(options.conninfo, true);
|
||||
|
||||
@@ -946,7 +946,8 @@ do_cluster_show(void)
|
||||
|
||||
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)
|
||||
strcpy(node_role, " FAILED");
|
||||
else if (strcmp(PQgetvalue(res, i, 1), "witness") == 0)
|
||||
@@ -3463,8 +3464,7 @@ do_standby_switchover(void)
|
||||
for(i = 0; i < options.reconnect_attempts; i++)
|
||||
{
|
||||
/* Check whether primary is available */
|
||||
|
||||
remote_conn = test_db_connection(remote_conninfo, false); /* don't fail on error */
|
||||
remote_conn = test_db_connection(remote_conninfo);
|
||||
|
||||
if (PQstatus(remote_conn) == CONNECTION_OK)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user