From 195b2549371ce4a2e8f1f9c94f06e921c1cda387 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 5 Sep 2020 19:15:01 +0100 Subject: [PATCH] Improve wording around transactions behaviour closing connections The transaction is not rolled back by the connection, rather discarded by the server. Close #1135. --- doc/src/usage.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/src/usage.rst b/doc/src/usage.rst index 7d0e7004..5239518c 100644 --- a/doc/src/usage.rst +++ b/doc/src/usage.rst @@ -750,10 +750,14 @@ until a call to the `~connection.rollback()` method. The connection is responsible for terminating its transaction, calling either the `~connection.commit()` or `~connection.rollback()` method. Committed -changes are immediately made persistent into the database. Closing the -connection using the `~connection.close()` method or destroying the -connection object (using `!del` or letting it fall out of scope) -will result in an implicit rollback. +changes are immediately made persistent into the database. If he connection +is closed (using the `~connection.close()` method) or destroyed (using `!del` +or letting it falling out of scope) while a transaction is in progress, the +server will discard the transaction. However doing so is not adviceable: +middleware such as PgBouncer_ may see the connection closed uncleanly and +dispose of it. + +.. _PgBouncer: http://www.pgbouncer.org/ It is possible to set the connection in *autocommit* mode: this way all the commands executed will be immediately committed and no rollback is possible. A