From afa942fef6a8f4335860eb26ff377d018ef0d845 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 23 Apr 2018 23:51:03 +0900 Subject: [PATCH] repmgrd: prevent standby connection handle from going stale If monitoring history not in use, there's no activity on the standby's connection handle, so if e.g. the standby is restarted, PQstatus() never returns CONNECTION_BAD and repmgrd never notices the connection is stale. Therefore execute a throw-away statement at "monitor_interval_secs". --- dbutils.c | 15 +++++++++++++++ dbutils.h | 1 + repmgrd-physical.c | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/dbutils.c b/dbutils.c index c8f27edf..f8c91657 100644 --- a/dbutils.c +++ b/dbutils.c @@ -3847,6 +3847,21 @@ is_server_available_params(t_conninfo_param_list *param_list) } + +/* + * Simple throw-away query to stop a connection handle going stale + */ +void +connection_ping(PGconn *conn) +{ + PGresult *res = PQexec(conn, "SELECT TRUE"); + + PQclear(res); + return; +} + + + /* ==================== */ /* monitoring functions */ /* ==================== */ diff --git a/dbutils.h b/dbutils.h index 93fbf019..8d78ca71 100644 --- a/dbutils.h +++ b/dbutils.h @@ -466,6 +466,7 @@ int wait_connection_availability(PGconn *conn, long long timeout); /* node availability functions */ bool is_server_available(const char *conninfo); bool is_server_available_params(t_conninfo_param_list *param_list); +void connection_ping(PGconn *conn); /* monitoring functions */ void diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 3c79c9f6..2f0ff58c 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -1070,7 +1070,13 @@ loop: if (PQstatus(primary_conn) == CONNECTION_OK && config_file_options.monitoring_history == true) + { update_monitoring_history(); + } + else + { + connection_ping(local_conn); + } if (got_SIGHUP) {