X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B3F505286C for ; Wed, 6 Jul 2005 04:39:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23147-01 for ; Wed, 6 Jul 2005 07:39:27 +0000 (GMT) Received: from smtp-vbr3.xs4all.nl (smtp-vbr3.xs4all.nl [194.109.24.23]) by svr1.postgresql.org (Postfix) with ESMTP id 60D7A5284F for ; Wed, 6 Jul 2005 04:39:21 -0300 (ADT) Received: from webmail.xs4all.nl (webmail12.xs4all.nl [194.109.22.172]) by smtp-vbr3.xs4all.nl (8.13.3/8.13.3) with ESMTP id j667dCdV066458; Wed, 6 Jul 2005 09:39:12 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: from 202.47.227.25 by webmail.xs4all.nl with HTTP; Wed, 6 Jul 2005 09:39:12 +0200 (CEST) Message-ID: <24362.202.47.227.25.1120635552.squirrel@202.47.227.25> In-Reply-To: <13032.1120574589@sss.pgh.pa.us> References: <21028.202.47.227.25.1120571298.squirrel@202.47.227.25> <13032.1120574589@sss.pgh.pa.us> Date: Wed, 6 Jul 2005 09:39:12 +0200 (CEST) Subject: Re: libpq and connection failures From: jtv@xs4all.nl To: "Tom Lane" Cc: jtv@xs4all.nl, pgsql-interfaces@postgresql.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.228 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200507/6 X-Sequence-Number: 5642 Tom Lane wrote: > I think it's probably better to have the default assumption be > "connection possibly recoverable" than have it be "summarily kill > connection at first hint of trouble". The latter seems less robust > not more so. Not after the connection failure has made its way into a PGresult, surely? Doesn't seem consistent with the design choice of aborting transactions on error, for starters. Are you saying that a session is still in usable shape when you have no way of establishing whether the last command succeeded? If you're in an explicit transaction when this happens, it's in an unknown state[*] so you have to abort anyway. All the client hears is "there's been an error of some sort, but the connection may or may not be fine, thank you." You don't necessarily know what level of transaction nesting you're in though, so you may have to fire off aborts until you're pretty sure you're out of all of them. Frankly I'd rather call PQreset() just to save myself the trouble. (*) Yes, there are cases where the transaction is left in a reliable state. Such as on a read-only query, which the application could retry (I'll assume it cares about the results or it wouldn't have queried) at the cost of greater code complexity. To me is one of the cases where simplicity and clarity matter a damn sight more than optimizing out the reconnect on the offchance that the application knows how to handle the situation despite not receiving even the basic knowledge that the error was something to do with the connection, not the query. Tom, when I said way back when that I wanted to do recovery and retry after a connection was lost, weren't you the one who said "this scares the hell out of me" because you couldn't be sure whether the last command committed? I thought the mantra when it came to networking went "don't second-guess the OS." If you get negative bytes out of a socket, there are a few known errno values that mean it's a transient thing. Fine, if you identify more of those then chuck them in there. There are several cases of that in there already. But otherwise, why not assume that the system gave you an error code because it decided it saw a failure? Jeroen