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 e814c1120e.
This commit is contained in:
Ian Barwick
2016-06-15 15:41:10 +09:00
parent 66fd003ab4
commit 1ade1acb22

View File

@@ -695,7 +695,7 @@ standby_monitor(void)
{ {
PGresult *res; PGresult *res;
char monitor_standby_timestamp[MAXLEN]; 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_receive_location[MAXLEN];
char last_xlog_replay_location[MAXLEN]; char last_xlog_replay_location[MAXLEN];
char last_xact_replay_timestamp[MAXLEN]; char last_xact_replay_timestamp[MAXLEN];
@@ -1048,17 +1048,23 @@ standby_monitor(void)
return; return;
} }
strncpy(last_wal_master_location, PQgetvalue(res, 0, 0), MAXLEN); strncpy(last_wal_primary_location, PQgetvalue(res, 0, 0), MAXLEN);
PQclear(res); PQclear(res);
/* 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_primary_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) 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; lsn_last_xlog_receive_location = lsn_last_xlog_replay_location;
strncpy(last_xlog_receive_location, last_xlog_replay_location, MAXLEN);
} }
else else
{ {
@@ -1091,7 +1097,7 @@ standby_monitor(void)
local_options.node, local_options.node,
monitor_standby_timestamp, monitor_standby_timestamp,
last_xact_replay_timestamp, last_xact_replay_timestamp,
last_wal_master_location, last_wal_primary_location,
last_xlog_receive_location, last_xlog_receive_location,
(long long unsigned int)(lsn_master_current_xlog_location - lsn_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)); (long long unsigned int)(lsn_last_xlog_receive_location - lsn_last_xlog_replay_location));