Intermittent Postgres Connection refused Errors (JDBC)

Lists: pgsql-admin
From: "'Srinivas Kotapally'" <ksrinivas(at)bisil(dot)com>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Intermittent Postgres Connection refused Errors (JDBC)
Date: 2007-05-01 21:26:47
Message-ID: 01a101c78c37$6da02450$800101df@srinilaptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

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(at)builder5(dot)centos(dot)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);}
}
}


From: "Aaron Bono" <postgresql(at)aranya(dot)com>
To: ksrinivas(at)coriendo(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Intermittent Postgres Connection refused Errors (JDBC)
Date: 2007-05-01 21:58:49
Message-ID: bf05e51c0705011458h1020a4feqccf9968324c83aec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On 5/1/07, Srinivas Kotapally <ksrinivas(at)bisil(dot)com> wrote:
>
> 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(at)builder5(dot)centos(dot)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.
>

Are you exceeding the maximum allowed connections in PostgreSQL? I would
start by checking the PostgreSQL logs. If nothing shows up, it may be a
network or application configuration issue.

-Aaron

--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================


From: "Srinivas Kotapally" <ksrinivas(at)coriendo(dot)com>
To: "'Aaron Bono'" <postgresql(at)aranya(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Intermittent Postgres Connection refused Errors (JDBC)
Date: 2007-05-01 22:10:06
Message-ID: 01aa01c78c3d$7a71cac0$800101df@srinilaptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Thanks for the response. No, I am not exceeding the max limit. I tried a test
which would exceed the max connections (which is 100 - set in postgresql.conf).
The error at that point is
org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

_____

From: aaron(dot)bono(at)gmail(dot)com [mailto:aaron(dot)bono(at)gmail(dot)com] On Behalf Of Aaron Bono
Sent: Tuesday, May 01, 2007 5:59 PM
To: ksrinivas(at)coriendo(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: [ADMIN] Intermittent Postgres Connection refused Errors (JDBC)

On 5/1/07, Srinivas Kotapally <ksrinivas(at)bisil(dot)com> wrote:

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(at)builder5(dot)centos(dot)org
<mailto:mockbuild(at)builder5(dot)centos(dot)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.

Are you exceeding the maximum allowed connections in PostgreSQL? I would start
by checking the PostgreSQL logs. If nothing shows up, it may be a network or
application configuration issue.

-Aaron

--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================


From: "Aaron Bono" <postgresql(at)aranya(dot)com>
To: ksrinivas(at)coriendo(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Intermittent Postgres Connection refused Errors (JDBC)
Date: 2007-05-01 22:34:37
Message-ID: bf05e51c0705011534r156a2412s64ec5df55f1bef58@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On 5/1/07, Srinivas Kotapally <ksrinivas(at)coriendo(dot)com> wrote:
>
> Thanks for the response. No, I am not exceeding the max limit. I tried
> a test which would exceed the max connections (which is 100 - set in
> postgresql.conf). The error at that point is
> org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
>

Are any errors showing up in the PostgreSQL logs?

Also, are do you have any of your already established connections in your
pool being that are begin disconnected? If so, you may be having
intermittent network problems.

The error you are getting implies that you are having connectivity problems
between servers. I am tomcat and PostgreSQL are running on separate
machines. Have you tried replicating this problem by running tomcat and
PostgreSQL on the same machine and connecting to localhost?

------------------------------
> *From:* aaron(dot)bono(at)gmail(dot)com [mailto:aaron(dot)bono(at)gmail(dot)com] *On Behalf Of *Aaron
> Bono
> *Sent:* Tuesday, May 01, 2007 5:59 PM
> *To:* ksrinivas(at)coriendo(dot)com
> *Cc:* pgsql-admin(at)postgresql(dot)org
> *Subject:* Re: [ADMIN] Intermittent Postgres Connection refused Errors
> (JDBC)
>
> On 5/1/07, Srinivas Kotapally <ksrinivas(at)bisil(dot)com> wrote:
> >
> > 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(at)builder5(dot)centos(dot)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.
> >
>
> Are you exceeding the maximum allowed connections in PostgreSQL? I would
> start by checking the PostgreSQL logs. If nothing shows up, it may be a
> network or application configuration issue.
>
> -Aaron
>

--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================