Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 613D8632E76 for ; Sat, 12 Dec 2009 20:49:53 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 61213-04 for ; Sun, 13 Dec 2009 00:49:45 +0000 (UTC) X-Greylist: delayed 00:07:05.008987 by SQLgrey-1.7.6 Received: from mail-qy0-f186.google.com (mail-qy0-f186.google.com [209.85.221.186]) by mail.postgresql.org (Postfix) with ESMTP id D9EB2632BBE for ; Sat, 12 Dec 2009 20:49:45 -0400 (AST) Received: by qyk16 with SMTP id 16so939828qyk.15 for ; Sat, 12 Dec 2009 16:49:44 -0800 (PST) Received: by 10.224.110.197 with SMTP id o5mr1920216qap.93.1260664958779; Sat, 12 Dec 2009 16:42:38 -0800 (PST) Received: from ?10.1.100.50? (dhcp-0071361389-e0-85.client.fas.harvard.edu [140.247.199.105]) by mx.google.com with ESMTPS id 4sm7083079qwe.55.2009.12.12.16.42.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 12 Dec 2009 16:42:37 -0800 (PST) Subject: Re: keeping Connection alive Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset=us-ascii From: "F. Jovan Jester" In-Reply-To: <943271.32.1260661401559.JavaMail.root@store1.zcs.ext.wpsrv.net> Date: Sat, 12 Dec 2009 19:42:36 -0500 Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <98B3D2B2-9F95-43CA-AA0A-02CD8ACE771B@groupspeak.com> References: <943271.32.1260661401559.JavaMail.root@store1.zcs.ext.wpsrv.net> To: Andreas Brandl X-Mailer: Apple Mail (2.1077) 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/33 X-Sequence-Number: 20114 On Dec 12, 2009, at 6:43 PM, Andreas Brandl wrote: > 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. Is this a standard Java application or is it running in a Java EE or = servlet container? > -- snip -- > org.postgresql.util.PSQLException: An I/O error occured while sending = to the backend. > -- snip -- >=20 > What is best practice to prevent the connection from breaking, i.e. = keeping the Conection alive? >=20 > 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. If you're not using an application server, and/or don't need pooling, = perhaps it would be better to use the regular jdbc api something like = this: Class.forName("org.postgresql.Driver"); Connection conn =3D DriverManager.getConnection(jdbcConnUrl, username, = password); // then conn.createStatement , etc. Then you can call conn.close() and create a new connection when = necessary. > 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. >=20 > 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). I've only had issues with pooled connections when I've misconfigured a = setting in the app server (it should manage the connections and = automatically close and reconnect every so often) or when I've had an = application bug that was not releasing connections because of unintended = long running transactions. Hope that helps. -Jovan Jester > I'm using PostgreSQL 8.3.8 and postgresql-8.4-701.jdbc4.jar for JDBC.=20= >=20 > Thanks alot! >=20 > Best regards, > Andreas >=20