mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
repmgrd: handle situations where streaming replication is inactive
This commit is contained in:
31
repmgrd.c
31
repmgrd.c
@@ -718,6 +718,7 @@ standby_monitor(void)
|
|||||||
int active_master_id;
|
int active_master_id;
|
||||||
const char *upstream_node_type = NULL;
|
const char *upstream_node_type = NULL;
|
||||||
|
|
||||||
|
bool receiving_streamed_wal = true;
|
||||||
/*
|
/*
|
||||||
* Verify that the local node is still available - if not there's
|
* Verify that the local node is still available - if not there's
|
||||||
* no point in doing much else anyway
|
* no point in doing much else anyway
|
||||||
@@ -1002,10 +1003,24 @@ standby_monitor(void)
|
|||||||
strncpy(last_xlog_receive_location, PQgetvalue(res, 0, 1), MAXLEN);
|
strncpy(last_xlog_receive_location, PQgetvalue(res, 0, 1), MAXLEN);
|
||||||
strncpy(last_xlog_replay_location, PQgetvalue(res, 0, 2), MAXLEN);
|
strncpy(last_xlog_replay_location, PQgetvalue(res, 0, 2), MAXLEN);
|
||||||
strncpy(last_xact_replay_timestamp, PQgetvalue(res, 0, 3), MAXLEN);
|
strncpy(last_xact_replay_timestamp, PQgetvalue(res, 0, 3), MAXLEN);
|
||||||
|
|
||||||
last_xlog_receive_location_gte_replayed = (strcmp(PQgetvalue(res, 0, 4), "t") == 0)
|
last_xlog_receive_location_gte_replayed = (strcmp(PQgetvalue(res, 0, 4), "t") == 0)
|
||||||
? true
|
? true
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If pg_last_xlog_receive_location is NULL, this means we're in archive
|
||||||
|
* recovery and will need to calculate lag based on pg_last_xlog_replay_location
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Replayed WAL is greater than received streamed WAL
|
||||||
|
*/
|
||||||
|
if (PQgetisnull(res, 0, 1))
|
||||||
|
{
|
||||||
|
receiving_streamed_wal = false;
|
||||||
|
}
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1017,11 +1032,10 @@ standby_monitor(void)
|
|||||||
* PostgreSQL log. In the absence of a better strategy, skip attempting
|
* PostgreSQL log. In the absence of a better strategy, skip attempting
|
||||||
* to insert a monitoring record.
|
* to insert a monitoring record.
|
||||||
*/
|
*/
|
||||||
if (last_xlog_receive_location_gte_replayed == false)
|
if (receiving_streamed_wal == true && last_xlog_receive_location_gte_replayed == false)
|
||||||
{
|
{
|
||||||
log_verbose(LOG_WARNING,
|
log_verbose(LOG_WARNING,
|
||||||
"Invalid replication_lag value calculated - is this standby connected to its upstream?\n");
|
"Replayed WAL newer than received WAL - is this standby connected to its upstream?\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get master xlog info */
|
/* Get master xlog info */
|
||||||
@@ -1040,9 +1054,18 @@ standby_monitor(void)
|
|||||||
|
|
||||||
/* Calculate the lag */
|
/* Calculate the lag */
|
||||||
lsn_master_current_xlog_location = lsn_to_xlogrecptr(last_wal_master_location, NULL);
|
lsn_master_current_xlog_location = lsn_to_xlogrecptr(last_wal_master_location, NULL);
|
||||||
lsn_last_xlog_receive_location = lsn_to_xlogrecptr(last_xlog_receive_location, NULL);
|
|
||||||
lsn_last_xlog_replay_location = lsn_to_xlogrecptr(last_xlog_replay_location, NULL);
|
lsn_last_xlog_replay_location = lsn_to_xlogrecptr(last_xlog_replay_location, NULL);
|
||||||
|
|
||||||
|
if (last_xlog_receive_location_gte_replayed == false)
|
||||||
|
{
|
||||||
|
lsn_last_xlog_receive_location = lsn_last_xlog_replay_location;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lsn_last_xlog_receive_location = lsn_to_xlogrecptr(last_xlog_receive_location, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build the SQL to execute on master
|
* Build the SQL to execute on master
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user