From 1ade1acb22d7aed0fa8584e5841afbe919f915ae Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 15 Jun 2016 15:41:10 +0900 Subject: [PATCH] Report standby location as last apply location when in archive recovery Otherwise the monitoring table's 'last_wal_standby_location' will stay at the location of the last streaming WAL received. This complements the bugfix applied in e814c1120e6cdc2e3a0a53effa355ac2189b51c0. --- repmgrd.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/repmgrd.c b/repmgrd.c index 9e012155..50168587 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -695,7 +695,7 @@ standby_monitor(void) { PGresult *res; char monitor_standby_timestamp[MAXLEN]; - char last_wal_master_location[MAXLEN]; + char last_wal_primary_location[MAXLEN]; char last_xlog_receive_location[MAXLEN]; char last_xlog_replay_location[MAXLEN]; char last_xact_replay_timestamp[MAXLEN]; @@ -1048,17 +1048,23 @@ standby_monitor(void) return; } - strncpy(last_wal_master_location, PQgetvalue(res, 0, 0), MAXLEN); + strncpy(last_wal_primary_location, PQgetvalue(res, 0, 0), MAXLEN); PQclear(res); /* 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_primary_location, NULL); lsn_last_xlog_replay_location = lsn_to_xlogrecptr(last_xlog_replay_location, NULL); if (last_xlog_receive_location_gte_replayed == false) { + /* + * We're not receiving streaming WAL - in this case the receive location + * equals the last replayed location + */ + lsn_last_xlog_receive_location = lsn_last_xlog_replay_location; + strncpy(last_xlog_receive_location, last_xlog_replay_location, MAXLEN); } else { @@ -1091,7 +1097,7 @@ standby_monitor(void) local_options.node, monitor_standby_timestamp, last_xact_replay_timestamp, - last_wal_master_location, + last_wal_primary_location, last_xlog_receive_location, (long long unsigned int)(lsn_master_current_xlog_location - lsn_last_xlog_receive_location), (long long unsigned int)(lsn_last_xlog_receive_location - lsn_last_xlog_replay_location));