Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 89652632B4B for ; Sat, 12 Dec 2009 19:51:15 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 86955-07 for ; Sat, 12 Dec 2009 23:50:58 +0000 (UTC) X-Greylist: delayed 00:07:40.091817 by SQLgrey-1.7.6 Received: from mta1.zcs.ext.wpsrv.net (mta1.zcs.ext.wpsrv.net [78.47.55.244]) by mail.postgresql.org (Postfix) with ESMTP id D414C6323B2 for ; Sat, 12 Dec 2009 19:51:04 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id 2E62318124 for ; Sun, 13 Dec 2009 00:43:22 +0100 (CET) X-Virus-Scanned: amavisd-new at mta1.zcs.ext.wpsrv.net Received: from mta1.zcs.ext.wpsrv.net ([127.0.0.1]) by localhost (mta1.zcs.ext.wpsrv.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cmOCh4Yn7VVT for ; Sun, 13 Dec 2009 00:43:21 +0100 (CET) Received: from store1.zcs.ext.wpsrv.net (store1.zcs.ext.wpsrv.net [78.47.55.243]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id A87431803F for ; Sun, 13 Dec 2009 00:43:21 +0100 (CET) Date: Sun, 13 Dec 2009 00:43:21 +0100 (CET) From: Andreas Brandl To: pgsql-jdbc@postgresql.org Message-ID: <943271.32.1260661401559.JavaMail.root@store1.zcs.ext.wpsrv.net> In-Reply-To: <18453464.30.1260661240055.JavaMail.root@store1.zcs.ext.wpsrv.net> Subject: keeping Connection alive MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mailer: Zimbra 6.0.2_GA_1912.DEBIAN4.0 (ZimbraWebClient - FF3.0 (Linux)/6.0.2_GA_1912.DEBIAN4.0) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/32 X-Sequence-Number: 20113 Hi, I'm using a PostgreSQL as backend for a Java application, which may idle for quite a while (i.e. hours) and now and then issue a query on the backend. The problem is the following exception I get when connection is apparently broken: -- snip -- org.postgresql.util.PSQLException: An I/O error occured while sending to the backend. -- snip -- What is best practice to prevent the connection from breaking, i.e. keeping the Conection alive? I'm using an instance of PGPoolingDataSource and would expect to retrieve a _valid_ Connection when calling DataSource.getConnection() (which I don't get). I even did call PGPoolingDataSource.setTcpKeepAlive(true) - same result. My first approach was to use a scheduled task and regularly check the Connection for validity ("ping") - unfortunately Connection.isValid(int timeout) has not been implemented yet. My current workaround is a scheduled task issueing a "SELECT 1" on a regularly basis. Which I feel is not the best solution, though. I read of using a connection pool like dbcp, which I'd like to avoid: I don't need connection pooling at all, just need to have a valid Connection even after hours of no-operation (a reconnect is ok, so no performance issue here). So, what's the best practice using the postgresql jdbc driver? I'm using PostgreSQL 8.3.8 and postgresql-8.4-701.jdbc4.jar for JDBC. Thanks alot! Best regards, Andreas