From 9115bd04700b5ba95c96eed55074e4ce5a61d5dc Mon Sep 17 00:00:00 2001 From: Amul Date: Fri, 10 May 2013 04:38:00 +0900 Subject: [PATCH] psql connection reset wait When one of backend connected to server is failed, then server restarted in recovery mode and come to normal state to accept further connection. The client those running transaction before crash will send the connection reset request immediately irrespective of server started successfully or not. If not, will terminate throwing error connection reset failed. That's why, we want to client should wait, for server comes in normal state in define time out. --- src/bin/psql/common.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 3dea92c..bf91906 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -278,6 +278,10 @@ static bool CheckConnection(void) { bool OK; + long waitTime; + long maxWaitTime = 10000000L;/* max wait time till + * client will wait to reset + */ OK = ConnectionUp(); if (!OK) @@ -291,6 +295,15 @@ CheckConnection(void) psql_error("The connection to the server was lost. Attempting reset: "); PQreset(pset.db); OK = ConnectionUp(); + + /* make client wait till the server is up properly if its not */ + for (waitTime = 1000; waitTime <= maxWaitTime && !OK; waitTime += 1000) + { + pg_usleep(1000L); + PQreset(pset.db); + OK = ConnectionUp(); + } + if (!OK) { psql_error("Failed.\n"); -- 1.7.1