2
.\" Title: SET TRANSACTION
3
.\" Author: The PostgreSQL Global Development Group
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
6
.\" Manual: PostgreSQL 9.1beta1 Documentation
7
.\" Source: PostgreSQL 9.1beta1
10
.TH "SET TRANSACTION" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
11
.\" -----------------------------------------------------------------
12
.\" * set default formatting
13
.\" -----------------------------------------------------------------
14
.\" disable hyphenation
16
.\" disable justification (adjust text to left margin only)
18
.\" -----------------------------------------------------------------
19
.\" * MAIN CONTENT STARTS HERE *
20
.\" -----------------------------------------------------------------
22
SET_TRANSACTION \- set the characteristics of the current transaction
24
.\" transaction isolation level: setting
25
.\" read-only transaction: setting
26
.\" deferrable transaction: setting
30
SET TRANSACTION \fItransaction_mode\fR [, \&.\&.\&.]
31
SET SESSION CHARACTERISTICS AS TRANSACTION \fItransaction_mode\fR [, \&.\&.\&.]
33
where \fItransaction_mode\fR is one of:
35
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
36
READ WRITE | READ ONLY
43
command sets the characteristics of the current transaction\&. It has no effect on any subsequent transactions\&.
44
SET SESSION CHARACTERISTICS
45
sets the default transaction characteristics for subsequent transactions of a session\&. These defaults can be overridden by
47
for an individual transaction\&.
49
The available transaction characteristics are the transaction isolation level, the transaction access mode (read/write or read\-only), and the deferrable mode\&.
51
The isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently:
55
A statement can only see rows committed before it began\&. This is the default\&.
60
All statements of the current transaction can only see rows committed before the first query or data\-modification statement was executed in this transaction\&.
65
All statements of the current transaction can only see rows committed before the first query or data\-modification statement was executed in this transaction\&. If a pattern of reads and writes among concurrent serializable transactions would create a situation which could not have occurred for any serial (one\-at\-a\-time) execution of those transactions, one of them will be rolled back with a
66
serialization_failureSQLSTATE\&.
68
The SQL standard defines one additional level,
69
READ UNCOMMITTED\&. In
70
PostgreSQLREAD UNCOMMITTED
74
The transaction isolation level cannot be changed after the first query or data\-modification statement (SELECT,
79
COPY) of a transaction has been executed\&. See
80
Chapter 13, Concurrency Control, in the documentation
81
for more information about transaction isolation and concurrency control\&.
83
The transaction access mode determines whether the transaction is read/write or read\-only\&. Read/write is the default\&. When a transaction is read\-only, the following SQL commands are disallowed:
88
if the table they would write to is not a temporary table; all
100
if the command they would execute is among those listed\&. This is a high\-level notion of read\-only that does not prevent all writes to disk\&.
104
transaction property has no effect unless the transaction is also
107
READ ONLY\&. When all of these properties are set on a transaction, the transaction may block when first acquiring its snapshot, after which it is able to run without the normal overhead of a
109
transaction and without any risk of contributing to or being cancelled by a serialization failure\&. This mode is well suited for long\-running reports or backups\&.
114
is executed without a prior
117
BEGIN, it will appear to have no effect, since the transaction will immediately end\&.
119
It is possible to dispense with
121
by instead specifying the desired
122
\fItransaction_modes\fR
128
The session default transaction modes can also be set by setting the configuration parameters
129
default_transaction_isolation,
130
default_transaction_read_only, and
131
default_transaction_deferrable\&. (In fact
132
SET SESSION CHARACTERISTICS
133
is just a verbose equivalent for setting these variables with
134
SET\&.) This means the defaults can be set in the configuration file, via
135
ALTER DATABASE, etc\&. Consult
136
Chapter 18, Server Configuration, in the documentation
137
for more information\&.
140
Both commands are defined in the
144
is the default transaction isolation level in the standard\&. In
146
the default is ordinarily
147
READ COMMITTED, but you can change it as mentioned above\&.
149
In the SQL standard, there is one other transaction characteristic that can be set with these commands: the size of the diagnostics area\&. This concept is specific to embedded SQL, and therefore is not implemented in the
154
DEFERRABLE\fItransaction_mode\fR
157
language extension\&.
159
The SQL standard requires commas between successive
160
\fItransaction_modes\fR, but for historical reasons
162
allows the commas to be omitted\&.