mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-05-28 17:53:19 +03:00
Introductory docs section on transaction control improved
Added big fat warning about idle in transaction and reference to set_session().
This commit is contained in:
parent
d2b28abced
commit
d76d136b4f
|
@ -396,7 +396,7 @@ The ``connection`` class
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
By default, any query execution, including a simple :sql:`SELECT`
|
By default, any query execution, including a simple :sql:`SELECT`
|
||||||
will start a transaction: for long-running program, if no further
|
will start a transaction: for long-running programs, if no further
|
||||||
action is taken, the session will remain "idle in transaction", a
|
action is taken, the session will remain "idle in transaction", a
|
||||||
condition non desiderable for several reasons (locks are held by
|
condition non desiderable for several reasons (locks are held by
|
||||||
the session, tables bloat...). For long lived scripts, either
|
the session, tables bloat...). For long lived scripts, either
|
||||||
|
|
|
@ -489,7 +489,7 @@ rounded to the nearest minute, with an error of up to 30 seconds.
|
||||||
versions use `psycopg2.extras.register_tstz_w_secs()`.
|
versions use `psycopg2.extras.register_tstz_w_secs()`.
|
||||||
|
|
||||||
|
|
||||||
.. index:: Transaction, Begin, Commit, Rollback, Autocommit
|
.. index:: Transaction, Begin, Commit, Rollback, Autocommit, Read only
|
||||||
|
|
||||||
.. _transactions-control:
|
.. _transactions-control:
|
||||||
|
|
||||||
|
@ -503,7 +503,7 @@ The following database commands will be executed in the context of the same
|
||||||
transaction -- not only the commands issued by the first cursor, but the ones
|
transaction -- not only the commands issued by the first cursor, but the ones
|
||||||
issued by all the cursors created by the same connection. Should any command
|
issued by all the cursors created by the same connection. Should any command
|
||||||
fail, the transaction will be aborted and no further command will be executed
|
fail, the transaction will be aborted and no further command will be executed
|
||||||
until a call to the `connection.rollback()` method.
|
until a call to the `~connection.rollback()` method.
|
||||||
|
|
||||||
The connection is responsible to terminate its transaction, calling either the
|
The connection is responsible to terminate its transaction, calling either the
|
||||||
`~connection.commit()` or `~connection.rollback()` method. Committed
|
`~connection.commit()` or `~connection.rollback()` method. Committed
|
||||||
|
@ -516,13 +516,23 @@ 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
|
commands executed will be immediately committed and no rollback is possible. A
|
||||||
few commands (e.g. :sql:`CREATE DATABASE`, :sql:`VACUUM`...) require to be run
|
few commands (e.g. :sql:`CREATE DATABASE`, :sql:`VACUUM`...) require to be run
|
||||||
outside any transaction: in order to be able to run these commands from
|
outside any transaction: in order to be able to run these commands from
|
||||||
Psycopg, the session must be in autocommit mode. Read the documentation for
|
Psycopg, the session must be in autocommit mode: you can use the
|
||||||
`connection.set_isolation_level()` to know how to change the commit mode.
|
`~connection.autocommit` property (`~connection.set_isolation_level()` in
|
||||||
|
older versions).
|
||||||
|
|
||||||
.. note::
|
.. warning::
|
||||||
|
|
||||||
From version 2.4.2 you can use the `~connection.autocommit` property to
|
By default even a simple :sql:`SELECT` will start a transaction: in
|
||||||
switch a connection in autocommit mode.
|
long-running programs, if no further action is taken, the session will
|
||||||
|
remain "idle in transaction", a condition non desiderable for several
|
||||||
|
reasons (locks are held by the session, tables bloat...). For long lived
|
||||||
|
scripts, either ensure to terminate a transaction as soon as possible or
|
||||||
|
use an autocommit connection.
|
||||||
|
|
||||||
|
A few other transaction properties can be set session-wide by the
|
||||||
|
`!connection`: for instance it is possible to have read-only transactions or
|
||||||
|
change the isolation level. See the `~connection.set_session()` method for all
|
||||||
|
the details.
|
||||||
|
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
Loading…
Reference in New Issue
Block a user