From c02a12a1130f4d7e06959219c8f14f2fa981a975 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 18 Apr 2017 13:33:28 +0900 Subject: [PATCH] repmgrd: actually call repmgr_update_last_updated() Function was created but never actually used, resulting in incorrect values for "communication_time_lag" in the "repl_status" view. This appears to have been an oversight in the original commit ( c3b58658ad856392edb4036adc3d023fbcaa52b0 ). Addresses GitHub #290 --- repmgrd.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/repmgrd.c b/repmgrd.c index 9e9da664..ef46185b 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -718,7 +718,7 @@ witness_monitor(void) return; } - strcpy(monitor_witness_timestamp, PQgetvalue(res, 0, 0)); + strncpy(monitor_witness_timestamp, PQgetvalue(res, 0, 0), MAXLEN); PQclear(res); /* @@ -1151,9 +1151,9 @@ standby_monitor(void) return; } - strncpy(monitor_standby_timestamp, PQgetvalue(res, 0, 0), MAXLEN); + strncpy(monitor_standby_timestamp, PQgetvalue(res, 0, 0), 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); receiving_streamed_wal = (strcmp(PQgetvalue(res, 0, 4), "t") == 0) @@ -1256,8 +1256,23 @@ standby_monitor(void) log_verbose(LOG_DEBUG, "standby_monitor:() %s\n", sqlquery); if (PQsendQuery(master_conn, sqlquery) == 0) - log_warning(_("query could not be sent to master. %s\n"), + { + log_warning(_("query could not be sent to master: %s\n"), PQerrorMessage(master_conn)); + } + else + { + sqlquery_snprintf(sqlquery, + "SELECT %s.repmgr_update_last_updated();", + get_repmgr_schema_quoted(my_local_conn)); + res = PQexec(my_local_conn, sqlquery); + + /* not critical if the above query fails*/ + if (PQresultStatus(res) != PGRES_TUPLES_OK) + log_warning(_("unable to set last_updated: %s\n"), PQerrorMessage(my_local_conn)); + + PQclear(res); + } }