mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
Check primary connection
Verify that existing primary connection is valid, and if not attempt to find and connect to the current primary node.
This commit is contained in:
45
repmgrd.c
45
repmgrd.c
@@ -1434,6 +1434,8 @@ set_local_node_failed(void)
|
|||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
int active_primary_node_id = -1;
|
||||||
|
char primary_conninfo[MAXLEN];
|
||||||
|
|
||||||
if (!check_connection(primary_conn, "master"))
|
if (!check_connection(primary_conn, "master"))
|
||||||
{
|
{
|
||||||
@@ -1447,7 +1449,48 @@ set_local_node_failed(void)
|
|||||||
* intervening period
|
* intervening period
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// ZZZ TODO
|
sqlquery_snprintf(sqlquery,
|
||||||
|
"SELECT id, conninfo "
|
||||||
|
" FROM %s.repl_nodes "
|
||||||
|
" WHERE type = 'primary' "
|
||||||
|
" AND active IS TRUE ",
|
||||||
|
get_repmgr_schema_quoted(primary_conn));
|
||||||
|
|
||||||
|
res = PQexec(primary_conn, sqlquery);
|
||||||
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
log_err(_("Unable to obtain active primary record: %s\n"),
|
||||||
|
PQerrorMessage(primary_conn));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!PQntuples(res))
|
||||||
|
{
|
||||||
|
log_err(_("No active primary record found\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
active_primary_node_id = atoi(PQgetvalue(res, 0, 0));
|
||||||
|
strncpy(primary_conninfo, PQgetvalue(res, 0, 1), MAXLEN);
|
||||||
|
PQclear(res);
|
||||||
|
|
||||||
|
if(active_primary_node_id != primary_options.node)
|
||||||
|
{
|
||||||
|
log_notice(_("Current active primary is %i; attempting to connect\n"),
|
||||||
|
active_primary_node_id);
|
||||||
|
PQfinish(primary_conn);
|
||||||
|
primary_conn = establish_db_connection(primary_conninfo, false);
|
||||||
|
|
||||||
|
if(PQstatus(primary_conn) != CONNECTION_OK)
|
||||||
|
{
|
||||||
|
log_err(_("Unable to connect to active primary\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_notice(_("Connection to new primary was successful\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to set own record as inactive
|
* Attempt to set own record as inactive
|
||||||
|
|||||||
Reference in New Issue
Block a user