Re: Error on failed COMMIT - Mailing list pgsql-hackers

From Haumacher, Bernhard
Subject Re: Error on failed COMMIT
Date
Msg-id 6b841c3e-df57-fccb-0edf-6c73679f8b19@haumacher.de
Whole thread Raw
In response to Re: Error on failed COMMIT  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Error on failed COMMIT  (Dave Cramer <davecramer@postgres.rocks>)
List pgsql-hackers
Am 14.02.2020 um 20:36 schrieb Robert Haas:
> On Fri, Feb 14, 2020 at 2:08 PM Dave Cramer <davecramer@postgres.rocks> wrote:
>> Well now you are asking the driver to re-interpret the results in a different way than the server which is not what
wetend to do.
 
>>
>> The server throws an error we throw an error. We really aren't in the business of re-interpreting the servers
responses.
> I don't really see a reason why the driver has to throw an exception
> if and only if there is an ERROR on the PostgreSQL side. But even if
> you want to make that rule for some reason, it doesn't preclude
> correct behavior here. All you really need is to have con.commit()
> return some indication of what the command tag was, just as, say, psql
> would do.

I think, this would be an appropriate solution. PostgreSQL reports the 
"unsuccessful" commit through the "ROLLBACK" status code and the driver 
translates this into a Java SQLException, because this is the only way 
to communicate the "non-successfullness" from the void commit() method. 
Since the commit() was not successful, from the API point of view this 
is an error and it is fine to report this using an exception.

Am 14.02.2020 um 21:07 schrieb Tom Lane:
> Dave Cramer <davecramer@postgres.rocks> writes:
>> We have the same blast radius.
>> I have offered to make the behaviour requested dependent on a configuration
>> parameter but apparently this is not sufficient.
> Nope, that is absolutely not happening.  We learned very painfully, back
> around 7.3 when we tried to put in autocommit on/off, that if server
> behaviors like this are configurable then most client code has to be
> prepared to work with every possible setting.  The argument that "you can
> just set it to work the way you expect" is a dangerous falsehood.  I see
> no reason to think that a change like this wouldn't suffer the same sort
> of embarrassing and expensive failure that autocommit did.

Doing this in a (non-default) driver setting is not ideal, because I 
expect do be notified *by default* from a database (driver) if a commit 
was not successful (and since the API is void, the only notification 
path is an exception). We already have a non-default option named 
"autosafe", which fixes the problem somehow.

If we really need both behaviors ("silently ignore failed commits" and 
"notify about failed commits") I would prefer adding a 
backwards-compatible option 
"silently-ignore-failed-commit-due-to-auto-rollback" (since it is a 
really aburd setting from my point of view, since consistency is at risk 
if this happens - the worst thing to expect from a database).

Regards,  Bernhard




pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: base backup client as auxiliary backend process
Next
From: "Daniel Verite"
Date:
Subject: Re: Unicode normalization SQL functions