Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 2D3D7633328 for ; Sat, 22 May 2010 06:58:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 81013-07 for ; Sat, 22 May 2010 09:57:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id A764C6328DF for ; Sat, 22 May 2010 06:57:58 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id DE4279F68; Sat, 22 May 2010 17:57:55 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 92EFDAF802; Sat, 22 May 2010 17:57:09 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IH2puiSGlx3V; Sat, 22 May 2010 17:57:04 +0800 (WST) Received: from [10.1.1.7] (124-148-217-247.dyn.iinet.net.au [124.148.217.247]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 2AA45AF800; Sat, 22 May 2010 17:57:04 +0800 (WST) Message-ID: <4BF7AA8C.8080008@postnewspapers.com.au> Date: Sat, 22 May 2010 17:57:32 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: Rod CC: pgsql-jdbc Subject: Re: After server restart I get - An I/O error occured while sending to the backend. References: <4BF27D11.8020001@postnewspapers.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/63 X-Sequence-Number: 20547 On 22/05/2010 3:31 PM, Rod wrote: > I find it hard to believe! We live in 21st century, year 2010. > Electric cars and black president. And there's still no connection > pool library that keeps track if connection is valid or not? Sure, there are plenty of connection pools that *try*. It's fundamentally impossible to do it properly, though, as the connection can die at *any* time. Including between when the connection pool tests it and when it hands it to the application for use. This is a race condition that you just can't solve. For that matter, the connection can die while the app is using it - someone trips over an Ethernet cable (or a server's power cable), a laptop goes out of wifi range, whatever. So - a connection pool testing for connection validity is only a convenience. The app must still be prepared to handle the connection breaking at any time. Given that, why bother testing it with the connection pool? It only offers a false sense of security, and wastes resources polling unused connections. I suppose it'd be possible to produce a Connection object wrapper that recorded all operations sent through it and if the underlying connection dropped replayed those operations to hide the connection loss from the application. However, the new connection couldn't obtain the same snapshot of the database state as the old one so the replay couldn't guarantee it'd have the same effects as the original run of those same statements. It'd be extremely unsafe at best. Now, maybe if the database kept the snapshot and connection state for lost connections around in case the client re-connected to pick up where it left off, then it'd be possible*. Hell, the database could even save that state and restore it after a database server reload. The complexity involved would be really ugly, though, and it'd only be of use to poorly behaved apps that can't gracefully handle connection failure. Even then it wouldn't save you from unexpected situations like server power loss, postgresql backend/server unexpected termination, etc, so the app/pool STILL needs to be able to gracefully cope with having all its work yanked out from under it. This is one of the reasons client/server transactional SQL programming can be more complicated than everything-on-one-machine shared file database programming. On the other hand, that could go wrong too, just not as easily so people pretended it couldn't and hoped it never would. -- Craig Ringer