From 6df48bacc1aead4b5e8ee308081f95457d6f868f Mon Sep 17 00:00:00 2001
From: Amul <sul_amul@yahoo.co.in>
Date: Fri, 10 May 2013 01:39:16 +0900
Subject: [PATCH] psql connection wait

---
 src/bin/psql/common.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 76cba90..37f9284 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -334,7 +334,8 @@ static bool
 CheckConnection(void)
 {
 	bool		OK;
-
+	long		waitTime;
+	long		maxWaitTime = 10000000L;
 	OK = ConnectionUp();
 	if (!OK)
 	{
@@ -345,8 +346,14 @@ CheckConnection(void)
 		}
 
 		fputs(_("The connection to the server was lost. Attempting reset: "), stderr);
-		PQreset(pset.db);
-		OK = ConnectionUp();
+		
+		for (waitTime = 5000; waitTime <= maxWaitTime && !OK; waitTime += 1000)
+		{
+			pg_usleep(waitTime);	
+			PQreset(pset.db);
+			OK = ConnectionUp();
+		}
+
 		if (!OK)
 		{
 			fputs(_("Failed.\n"), stderr);
-- 
1.7.1

