mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 08:56:29 +00:00
Wrap use of PQconnectdbParams, add proper error
checking and logging when the connection fails.
This commit is contained in:
20
dbutils.c
20
dbutils.c
@@ -43,6 +43,26 @@ establishDBConnection(const char *conninfo, const bool exit_on_error)
|
||||
return conn;
|
||||
}
|
||||
|
||||
PGconn *
|
||||
establishDBConnectionByParams(const char *keywords[], const char *values[],const bool exit_on_error)
|
||||
{
|
||||
/* Make a connection to the database */
|
||||
PGconn *conn = PQconnectdbParams(keywords, values, true);
|
||||
|
||||
/* Check to see that the backend connection was successfully made */
|
||||
if ((PQstatus(conn) != CONNECTION_OK))
|
||||
{
|
||||
log_err(_("Connection to database failed: %s\n"),
|
||||
PQerrorMessage(conn));
|
||||
if (exit_on_error)
|
||||
{
|
||||
PQfinish(conn);
|
||||
exit(ERR_DB_CON);
|
||||
}
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
bool
|
||||
is_standby(PGconn *conn)
|
||||
|
||||
Reference in New Issue
Block a user