Re: Error on failed COMMIT

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Dave Cramer <davecramer(at)postgres(dot)rocks>, Robert Haas <robertmhaas(at)gmail(dot)com>, Shay Rojansky <roji(at)roji(dot)org>, "Haumacher, Bernhard" <haui(at)haumacher(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Error on failed COMMIT
Date: 2020-02-24 22:06:23
Message-ID: CAB=Je-Ger+TZHLHhphQx3H8K0+Xi1jagT06oMuhD1=v7zn4fmw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Merlin>My biggest sense of alarm with the proposed change is that it could
Merlin>leave applications in a state where the transaction is hanging there

How come?
The spec says commit ends the transaction.
Can you please clarify where the proposed change leaves a hanging
transaction?

Just in case, the proposed change is as follows:

postgres=# begin;
BEGIN
postgres=# aslkdfasdf;
ERROR: syntax error at or near "aslkdfasdf"
LINE 1: aslkdfasdf;
^
postgres=# commit;
ROLLBACK <-- this should be replaced with "ERROR: can't commit the
transaction because ..."
postgres=# commit;
WARNING: there is no transaction in progress <-- this should be as it is
currently. Even if commit throws an error, the transaction should be
terminated.
COMMIT

No-one on the thread suggests the transaction must hang forever.
Of course, commit must terminate the transaction one way or another.
The proposed change is to surface the exception if user tries to commit or
prepare a transaction that can't be committed.
Note: the reason does not matter much. If deferred constraint fails on
commit, then commit itself throws an error.
Making commit throw an error in case "current transaction is aborted" makes
perfect sense.

Note: the same thing is with PREPARE TRANSACTION 'txname`.
Apparently it silently responses with ROLLBACK which is strange as well.

Vladimir

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Vik Fearing 2020-02-24 22:37:45 Re: Error on failed COMMIT
Previous Message Tom Lane 2020-02-24 21:44:27 Re: pgsql: Add kqueue(2) support to the WaitEventSet API.