mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Add function test_db_connection()
The difference between this and establish_db_connection() is that it outputs any connection failure as a [NOTICE] rather than an [ERROR]; it's intended for use in e.g. polling a server to wait for it to come up/go down, while preventing [ERROR] log lines which may cause confusion.
This commit is contained in:
28
dbutils.c
28
dbutils.c
@@ -29,8 +29,9 @@
|
|||||||
char repmgr_schema[MAXLEN] = "";
|
char repmgr_schema[MAXLEN] = "";
|
||||||
char repmgr_schema_quoted[MAXLEN] = "";
|
char repmgr_schema_quoted[MAXLEN] = "";
|
||||||
|
|
||||||
|
|
||||||
PGconn *
|
PGconn *
|
||||||
establish_db_connection(const char *conninfo, const bool exit_on_error)
|
_establish_db_connection(const char *conninfo, const bool exit_on_error, const bool log_notice)
|
||||||
{
|
{
|
||||||
/* Make a connection to the database */
|
/* Make a connection to the database */
|
||||||
PGconn *conn = NULL;
|
PGconn *conn = NULL;
|
||||||
@@ -46,8 +47,16 @@ establish_db_connection(const char *conninfo, const bool exit_on_error)
|
|||||||
/* 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))
|
||||||
{
|
{
|
||||||
log_err(_("connection to database failed: %s\n"),
|
if (log_notice)
|
||||||
PQerrorMessage(conn));
|
{
|
||||||
|
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)
|
if (exit_on_error)
|
||||||
{
|
{
|
||||||
@@ -59,6 +68,19 @@ establish_db_connection(const char *conninfo, const bool exit_on_error)
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGconn *
|
||||||
|
establish_db_connection(const char *conninfo, const bool exit_on_error)
|
||||||
|
{
|
||||||
|
return _establish_db_connection(conninfo, exit_on_error, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
PGconn *
|
||||||
|
test_db_connection(const char *conninfo, const bool exit_on_error)
|
||||||
|
{
|
||||||
|
return _establish_db_connection(conninfo, exit_on_error, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PGconn *
|
PGconn *
|
||||||
establish_db_connection_by_params(const char *keywords[], const char *values[],
|
establish_db_connection_by_params(const char *keywords[], const char *values[],
|
||||||
const bool exit_on_error)
|
const bool exit_on_error)
|
||||||
|
|||||||
@@ -78,8 +78,13 @@ typedef struct s_replication_slot
|
|||||||
InvalidXLogRecPtr \
|
InvalidXLogRecPtr \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGconn *_establish_db_connection(const char *conninfo,
|
||||||
|
const bool exit_on_error,
|
||||||
|
const bool log_notice);
|
||||||
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,
|
||||||
|
const bool exit_on_error);
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user