BEGIN initiates a user transaction in chained mode,
i.e., all user statements after BEGIN command will
be executed in a single transaction until an explicit
- ,
- ,
- or execution abort. Statements in chained mode are executed much faster,
+ or
+ .
+ Statements are executed more quickly in chained mode,
because transaction start/commit requires significant CPU and disk
activity. Execution of multiple statements inside a transaction
- is also required for consistency when changing several
- related tables.
+ is also useful to ensure consistency when changing several
+ related tables: other clients will be unable to see the intermediate
+ states wherein not all the related updates have been done.
The default transaction isolation level in
- is READ COMMITTED, where queries inside the transaction see only changes
- committed before query execution. So, you have to use
+ is READ COMMITTED, wherein each query inside the transaction sees changes
+ committed before that query begins execution. So, you have to use
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
- just after BEGIN if you need more rigorous transaction isolation.
+ just after BEGIN if you need more rigorous transaction
+ isolation. (Alternatively, you can change the default transaction
+ isolation level; see the PostgreSQL Administrator's
+ Guide for details.)
In SERIALIZABLE mode queries will see only changes committed before
the entire
transaction began (actually, before execution of the first DML statement
- in a serializable transaction).
+ in the transaction).
- If the transaction is committed,
PostgreSQL
- will ensure either that all updates are done or else that none of
- them are done. Transactions have the standard
ACID
- (atomic, consistent, isolatable, and durable) property.
+ Transactions have the standard
ACID
+ (atomic, consistent, isolatable, and durable) properties.
Notes
- Refer to
- for further information
- about locking tables inside a transaction.
+
+ endterm="sql-start-transaction-title"> has the same functionality
+ as BEGIN>.
to terminate a transaction.
+
+ Refer to
+ for further information
+ about locking tables inside a transaction.
+
+
+ If you turn autocommit> mode off, then BEGIN>
+ is not required: any SQL command automatically starts a transaction.
+
-
+
+
2002-07-26
This command begins a new transaction. If the isolation level is
specified, the new transaction has that isolation level. In all other
respects, the behavior of this command is identical to the
- <command>BEGIN> command.
+ <xref linkend="sql-begin" endterm="sql-begin-title"> command.
The isolation level of a transaction can also be set with the
linkend="sql-set-transaction" endterm="sql-set-transaction-title">
- command. If no isolation level is specified, the level defaults to
- .
+ command. If no isolation level is specified, the default isolation
+ level is used.
SQL99
- is the default level in
+ is the default isolation level in
+
SQL99, but it is not the usual default in
+
PostgreSQL: the factory default setting
+ is READ COMMITTED.
does not provide the isolation levels
- and . Because of multiversion
- concurrency control, the level is
+ and . Because of lack of predicate
+ locking, the level is
not truly serializable. See the User's Guide
for details.