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.
This commit is contained in:
Ian Barwick
2016-07-01 07:50:27 +09:00
parent 746c9793ed
commit 60bceae905

View File

@@ -3195,27 +3195,22 @@ do_standby_switchover(void)
{ {
/* Check whether primary is available */ /* Check whether primary is available */
remote_conn = test_db_connection(remote_conninfo, false); /* don't fail on error */ PGPing ping_res = PQping(remote_conninfo);
/* /* database server could not be contacted */
* If we're unable to connect, keep PQping-ing the server until it if (ping_res == PQPING_NO_RESPONSE)
* finally goes away
*/
if (PQstatus(remote_conn) != CONNECTION_OK)
{ {
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 */ log_notice(_("current master has been stopped\n"));
if (ping_res == PQPING_NO_RESPONSE) break;
{
/* XXX we should double-check access to the physical server here */
shutdown_success = true;
log_notice(_("current master has been stopped\n"));
break;
}
} }
PQfinish(remote_conn);
/* XXX make configurable? */ /* XXX make configurable? */
sleep(options.reconnect_interval); sleep(options.reconnect_interval);