Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 645839FB797 for ; Tue, 1 May 2007 10:28:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 56217-05 for ; Tue, 1 May 2007 10:27:57 -0300 (ADT) X-Greylist: delayed 00:07:17.20185 by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.242]) by postgresql.org (Postfix) with ESMTP id DFFD79FB50C for ; Tue, 1 May 2007 10:27:56 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c24so1682014ana for ; Tue, 01 May 2007 06:27:55 -0700 (PDT) Received: by 10.100.95.19 with SMTP id s19mr1820050anb.1178025638199; Tue, 01 May 2007 06:20:38 -0700 (PDT) Received: from srinilaptop ( [71.175.17.63]) by mx.google.com with ESMTP id c4sm9434317anc.2007.05.01.06.20.36; Tue, 01 May 2007 06:20:37 -0700 (PDT) Reply-To: From: "Srinivas Kotapally" To: Subject: Intermittent Postgres Connection refused Errors (JDBC) Date: Tue, 1 May 2007 09:20:34 -0400 Organization: Coriendo LLC Message-ID: <016601c78bf3$80819c00$800101df@srinilaptop> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0167_01C78BD1.F96FFC00" X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Thread-Index: AceL838Gi1hKytTuT3Ox73h8REEp1w== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/6 X-Sequence-Number: 25326 This is a multi-part message in MIME format. ------=_NextPart_000_0167_01C78BD1.F96FFC00 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi I am managing an application that uses the Postgres backend. Of late we have started getting connection refused errors every now and then. We have not been able to identify the cause of this. Any hints or known bugs that I should be aware of? Thanks for any help extended! Regards Srinivas Here is the environment I work in: Application is a Java app residing on a web server and is running on Tomcat. Versions: jdk: 1.5.0_02 Tomcat 5.5.23 Web server: httpd-2.0.52-28.ent.centos4 Kernel: Linux version 2.6.9-42.0.10.ELsmp (mockbuild@builder5.centos.org) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)) #1 SMP Tue Feb 27 09:40:21 EST 2007 Postgres: 8.1.8 (64 bit version) - postgresql-libs-8.1.8-1PGDG postgresql-8.1.8-1PGDG postgresql-server-8.1.8-1PGDG postgresql-contrib-8.1.8-1PGDG We use the JDBC2 driver that comes with Postgres. The specific error we get is: CDBConnectionPool.newConnection() : SQLException= org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Our CDBConnectionPool class as below (this is a class that we have implemented to establish BD connections): import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; class CDBConnectionPool { public synchronized Connection getConnection(String stIPAddress,String stPort,String stDataBaseName, String stUser,String stPassword,String stDBType) { Connection con = null; try { con = newConnection(stIPAddress,stPort,stDataBaseName,stDBType,stUser,stPassword); } catch(Exception e) { Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.getConnection:Except ion="+e); } return con; } private Connection newConnection(String stIPAddress,String stPort,String stDataBaseName,String stDBType,String stUser,String stPassword) { Connection con = null; try { String stURL = ""; String stClassName = ""; if (stDBType.equals("ORACLE")) { stURL = "jdbc:oracle:thin:@"+ stIPAddress + ":" + stPort + ":" + stDataBaseName ; stClassName = "oracle.jdbc.driver.OracleDriver"; } else if(stDBType.equals("POSTGRES")) { stURL = "jdbc:postgresql://"+stIPAddress+":"+stPort+"/"+stDataBaseName; stClassName = "org.postgresql.Driver"; } else if(stDBType.equals("MS-SQL2000")) { stURL = "jdbc:microsoft:sqlserver://"+stIPAddress+":"+stPort+";DatabaseName="+stDataBase Name; stClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; } else if(stDBType.equals("SYBASE")) { stURL = "jdbc:sybase:Tds:"+stIPAddress+":"+stPort+"/"+stDataBaseName; stClassName = "com.sybase.jdbc2.jdbc.SybDriver"; } else if(stDBType.equals("DB2")) { stURL = "jdbc:db2://"+stIPAddress+":"+stPort+"/"+stDataBaseName; stClassName = "COM.ibm.db2.jdbc.net.DB2Driver"; } Class.forName(stClassName); con = DriverManager.getConnection(stURL,stUser,stPassword); } catch(SQLException sqle) { if(sqle.toString().indexOf("too many clients")>=0) { Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.newConnection() : Maxmimum connections Reached. Waiting for connections to freeup."); con = newConnection(stIPAddress,stPort,stDataBaseName,stDBType,stUser,stPassword); } else { Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.newConnection() : SQLException= " + sqle); } } catch(ClassNotFoundException e) { Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.newConnection() : ClassNotFoundException = " + e.getCause()); } catch(Exception e) { Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.newConnection() : Exception= " + e); } return con; } public void freeConnection(Connection con,String stDataBaseName) { try { con.close(); }catch(Exception e){Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.freeConnection : Exception= " + e);} } } ------=_NextPart_000_0167_01C78BD1.F96FFC00 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
Hi
 
I am = managing an=20 application that uses the Postgres backend.  Of late we have = started=20 getting connection refused errors every now and then.  We have not = been=20 able to identify the cause of this.  Any hints or known bugs that I = should=20 be aware of?  Thanks for any help extended!
 
Regards

Srinivas
 
Here = is the=20 environment I work in:
Application is a Java app residing on a web = server and=20 is running on Tomcat. 
Versions:
jdk:=20 1.5.0_02
Tomcat = 5.5.23
Web = server:=20 httpd-2.0.52-28.ent.centos4
Kernel: Linux=20 version 2.6.9-42.0.10.ELsmp (mockbuild@builder5.centos.o= rg)=20 (gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)) #1 SMP Tue Feb 27 = 09:40:21 EST=20 2007
Postgres: 8.1.8 (64 bit version) -
postgresql-libs-8.1.8-1PGDG
postgresql-8.1.8-1PGDG
postgre= sql-server-8.1.8-1PGDG
postgresql-contrib-8.1.8-1PGDG
 
We use = the JDBC2=20 driver that comes with Postgres.
 
The = specific error=20 we get is:
 
CDBConnectionPool.newConnection() : SQLException=3D=20 org.postgresql.util.PSQLException: Connection refused. Check that the = hostname=20 and port are correct and that the postmaster is accepting TCP/IP=20 connections.
 
Our=20 CDBConnectionPool class as below (this is a class that we have = implemented to=20 establish BD connections):
 
import = java.sql.Connection;
import java.sql.DriverManager;
import=20 java.sql.SQLException;
import java.util.Enumeration;
import=20 java.util.Hashtable;
import java.util.Vector;
 
class=20 CDBConnectionPool
{
 public synchronized Connection=20 getConnection(String stIPAddress,String stPort,String stDataBaseName, = String=20 stUser,String stPassword,String = stDBType)
 {
  Connection=20 con =3D = null;
  try
  {
   con =3D=20 newConnection(stIPAddress,stPort,stDataBaseName,stDBType,stUser,stPasswor= d);
  }
  catch(Exception=20 e)
  {
   Logger.toLog("CONNECTION",stData= BaseName,"CDBConnectionPool.getConnection:Exception=3D"+e);
 &nbs= p;}
  return=20 con;
 }
 
 private=20 Connection newConnection(String stIPAddress,String stPort,String=20 stDataBaseName,String stDBType,String stUser,String=20 stPassword)
 {
  Connection con =3D=20 null;
  try
  {
   String = stURL =3D=20 "";
   String stClassName =3D "";
 
   if=20 (stDBType.equals("ORACLE"))
   {
   &= nbsp;stURL=20 =3D "jdbc:oracle:thin:@"+ stIPAddress + ":" + stPort + ":" + = stDataBaseName=20 ;
    stClassName =3D=20 "oracle.jdbc.driver.OracleDriver";
   }
  =  else=20 if(stDBType.equals("POSTGRES"))
   {
  &nb= sp; stURL=20 =3D=20 "jdbc:postgresql://"+stIPAddress+":"+stPort+"/"+stDataBaseName;
 =    stClassName=20 =3D=20  "org.postgresql.Driver";
   }
  &nbs= p;else=20 if(stDBType.equals("MS-SQL2000"))
   {
  &= nbsp; stURL=20 =3D=20 "jdbc:microsoft:sqlserver://"+stIPAddress+":"+stPort+";DatabaseName=3D"+s= tDataBaseName;
    stClassName=20 =3D=20 "com.microsoft.jdbc.sqlserver.SQLServerDriver";
   }   else=20 if(stDBType.equals("SYBASE"))
   {
   = ; stURL=20 =3D=20 "jdbc:sybase:Tds:"+stIPAddress+":"+stPort+"/"+stDataBaseName;
 &n= bsp;  stClassName=20 =3D=20 "com.sybase.jdbc2.jdbc.SybDriver";
   }
  =  else=20 if(stDBType.equals("DB2"))
   {
   &n= bsp;=20 stURL =3D=20 "jdbc:db2://"+stIPAddress+":"+stPort+"/"+stDataBaseName;
  &= nbsp; =20 stClassName =3D=20 "COM.ibm.db2.jdbc.net.DB2Driver";
   }
 
   Class.forName(stClassName);
 
   con =3D=20 DriverManager.getConnection(stURL,stUser,stPassword);
  &nbs= p;  =20  }
       catch(SQLException=20 sqle)
     =20  {
   if(sqle.toString().indexOf("too many=20 clients")>=3D0)
   {
    Logg= er.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.newConnection()=20 : Maxmimum connections Reached. Waiting for connections to=20 freeup.");
    con =3D=20 newConnection(stIPAddress,stPort,stDataBaseName,stDBType,stUser,stPasswor= d);
   }
   else
   = ;{
    Logger.toLog("CONNECTION",stDataBaseName,"C= DBConnectionPool.newConnection()=20 : SQLException=3D " +=20 sqle);
   }
  }
  catch(Class= NotFoundException=20 e)
  {
   Logger.toLog("CONNECTION",stData= BaseName,"CDBConnectionPool.newConnection()=20 : ClassNotFoundException =3D " +=20 e.getCause());
  }
     =20  catch(Exception e)
     =20  {
   Logger.toLog("CONNECTION",stDataBaseName,"CD= BConnectionPool.newConnection()=20 : Exception=3D " + e);
  }
  return=20 con;
 }
 
 public void=20 freeConnection(Connection con,String=20 stDataBaseName)
 {
  try
  {
 &= nbsp; con.close();
 
  }catch(Exception=20 e){Logger.toLog("CONNECTION",stDataBaseName,"CDBConnectionPool.freeConnec= tion :=20 Exception=3D " + e);}
 }
}
------=_NextPart_000_0167_01C78BD1.F96FFC00--