diff --git a/HISTORY b/HISTORY index 78917222..2c7873a6 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +3.3.1 2017-01- + repmgrd: revent invalid apply lag value being written to the + monitoring table (Ian) + 3.3 2016-12-27 repmgr: always log to STDERR even if log facility defined (Ian) repmgr: add --log-to-file to log repmgr output to the defined diff --git a/repmgrd.c b/repmgrd.c index 7342f3e5..eb4bbdfc 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1187,10 +1187,22 @@ standby_monitor(void) PQclear(res); 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); 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); + + if (lsn_last_xlog_receive_location >= lsn_last_xlog_replay_location) + { + apply_lag = (long long unsigned int)lsn_last_xlog_receive_location - lsn_last_xlog_replay_location; + } + else + { + /* This should never happen, but in case it does set apply lag to zero */ + log_warning("Standby receive (%s) location appears less than standby replay location (%s)\n", + last_xlog_receive_location, + last_xlog_replay_location); + apply_lag = 0; + } - apply_lag = (long long unsigned int)lsn_last_xlog_receive_location - lsn_last_xlog_replay_location; /* Calculate replication lag */ if (lsn_master_current_xlog_location >= lsn_last_xlog_receive_location) @@ -1199,7 +1211,7 @@ standby_monitor(void) } else { - /* This should never happen, but in case it does set lag to zero */ + /* This should never happen, but in case it does set replication lag to zero */ log_warning("Master xlog (%s) location appears less than standby receive location (%s)\n", last_wal_primary_location, last_xlog_receive_location);