Documentation should state what happens, when a commit fails

Started by PG Bug reporting form11 months ago7 messagesdocs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/sql-commit.html
Description:

Deferrable constraints, deadlocks and possibly other deferred or lazily
evaluated rules are checked upon commit.
What happens if they are not met and the commit statement fails? Does the
transaction then implicitly rollback? Or do I need an explicit rollback?

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: PG Bug reporting form (#1)
Re: Documentation should state what happens, when a commit fails

On Wed, 2025-05-28 at 08:08 +0000, PG Doc comments form wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/sql-commit.html
Description:

Deferrable constraints, deadlocks and possibly other deferred or lazily
evaluated rules are checked upon commit.
What happens if they are not met and the commit statement fails? Does the
transaction then implicitly rollback? Or do I need an explicit rollback?

I think it would be good to mention that a failed COMMIT automatically
performs a ROLLBACK. Do you want to suggest a patch?

Yours,
Laurenz Albe

#3David G. Johnston
david.g.johnston@gmail.com
In reply to: Laurenz Albe (#2)
Re: Documentation should state what happens, when a commit fails

On Wednesday, May 28, 2025, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

On Wed, 2025-05-28 at 08:08 +0000, PG Doc comments form wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/sql-commit.html
Description:

Deferrable constraints, deadlocks and possibly other deferred or lazily
evaluated rules are checked upon commit.
What happens if they are not met and the commit statement fails? Does the
transaction then implicitly rollback? Or do I need an explicit rollback?

I think it would be good to mention that a failed COMMIT automatically
performs a ROLLBACK. Do you want to suggest a patch?

Feel free to review mine for this topic and suggest additions.

https://commitfest.postgresql.org/patch/5546/

David J.

#4mark maker
mark@makr.zone
In reply to: David G. Johnston (#3)
RE: Documentation should state what happens, when a commit fails

Wow, great improvement, thanks!

The "tutorial-transactions" opens a new question that might be useful to
know: when a transaction enters the aborted state at an early point in
time (as has now become clear), does this mean it will also relinquish
any locks and predicate locks early, or will it still hold onto those
until explicitly rolled back by command?

_Mark

*From:* David G. Johnston <david.g.johnston@gmail.com>

*Sent:* Wednesday, May 28, 2025 at 4:04 PM UTC+2

*To:* Laurenz Albe <laurenz.albe@cybertec.at>

*Cc:* mark@makr.zone <mark@makr.zone>, pgsql-docs@lists.postgresql.org
<pgsql-docs@lists.postgresql.org>

*Subject:* RE: Documentation should state what happens, when a commit fails

Show quoted text

On Wednesday, May 28, 2025, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

On Wed, 2025-05-28 at 08:08 +0000, PG Doc comments form wrote:

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/sql-commit.html

<https://www.postgresql.org/docs/17/sql-commit.html&gt;

Description:

Deferrable constraints, deadlocks and possibly other deferred or

lazily

evaluated rules are checked upon commit.
What happens if they are not met and the commit statement fails?

Does the

transaction then implicitly rollback? Or do I need an explicit

rollback?

I think it would be good to mention that a failed COMMIT automatically
performs a ROLLBACK.  Do you want to suggest a patch?

Feel free to review mine for this topic and suggest additions.

https://commitfest.postgresql.org/patch/5546/

David J.

#5David G. Johnston
david.g.johnston@gmail.com
In reply to: mark maker (#4)
Re: Documentation should state what happens, when a commit fails

On Wed, May 28, 2025 at 7:47 AM mark maker <mark@makr.zone> wrote:

Wow, great improvement, thanks!

The "tutorial-transactions" opens a new question that might be useful to
know: when a transaction enters the aborted state at an early point in time
(as has now become clear), does this mean it will also relinquish any locks
and predicate locks early, or will it still hold onto those until
explicitly rolled back by command?

I suppose if the system knows there are no savepoints in progress it could
release the locks and whatnot...not sure if it knows that and acts upon
that knowledge if it does. Easy enough to test with two psql sessions if
you want to give it a go before I or someone else gets around to it.

David J.

#6Dave Cramer
pg@fastcrypt.com
In reply to: David G. Johnston (#5)
Re: Documentation should state what happens, when a commit fails

On Wed, 28 May 2025 at 10:59, David G. Johnston <david.g.johnston@gmail.com>
wrote:

On Wed, May 28, 2025 at 7:47 AM mark maker <mark@makr.zone> wrote:

Wow, great improvement, thanks!

The "tutorial-transactions" opens a new question that might be useful to
know: when a transaction enters the aborted state at an early point in time
(as has now become clear), does this mean it will also relinquish any locks
and predicate locks early, or will it still hold onto those until
explicitly rolled back by command?

I suppose if the system knows there are no savepoints in progress it could
release the locks and whatnot...not sure if it knows that and acts upon
that knowledge if it does. Easy enough to test with two psql sessions if
you want to give it a go before I or someone else gets around to it.

Somewhat annoying feature of this behaviour is that when COMMIT is issued
on an aborted transaction no error is reported.
Most drivers work around this problem by keeping track of the previous
error and reporting an error on the COMMIT.
Dave

#7Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Dave Cramer (#6)
Re: Documentation should state what happens, when a commit fails

On Wed, 2025-05-28 at 11:09 -0400, Dave Cramer wrote:

Somewhat annoying feature of this behaviour is that when COMMIT is issued on an aborted transaction no error is reported.
Most drivers work around this problem by keeping track of the previous error and reporting an error on the COMMIT.

We have been there before:
/messages/by-id/b9fb50dc-0f6e-15fb-6555-8ddb86f4aa71@postgresfriends.org
Nothing came of that discussion though.

Yours,
Laurenz Albe