From 60bceae905bbe5bd64ffce84732b90021fb58600 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 1 Jul 2016 07:50:27 +0900 Subject: [PATCH] Use PQping only to check for server shutdown Functionally there's no difference between that and attempting to make an actual connection, so use one method only, which also simplifies the code. --- repmgr.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/repmgr.c b/repmgr.c index e58bcf12..51c1cac6 100644 --- a/repmgr.c +++ b/repmgr.c @@ -3195,27 +3195,22 @@ do_standby_switchover(void) { /* Check whether primary is available */ - remote_conn = test_db_connection(remote_conninfo, false); /* don't fail on error */ + PGPing ping_res = PQping(remote_conninfo); - /* - * If we're unable to connect, keep PQping-ing the server until it - * finally goes away - */ - if (PQstatus(remote_conn) != CONNECTION_OK) + /* database server could not be contacted */ + if (ping_res == PQPING_NO_RESPONSE) { - PGPing ping_res = PQping(remote_conninfo); + /* + * XXX here we should directly access the server and check that the + * pidfile has gone away so we can be sure the server is actually + * shut down and the PQPING_NO_RESPONSE is not due to other issues + * such as coincidental network failure. + */ + shutdown_success = true; - /* database server could not be contacted */ - if (ping_res == PQPING_NO_RESPONSE) - { - /* XXX we should double-check access to the physical server here */ - shutdown_success = true; - - log_notice(_("current master has been stopped\n")); - break; - } + log_notice(_("current master has been stopped\n")); + break; } - PQfinish(remote_conn); /* XXX make configurable? */ sleep(options.reconnect_interval);