~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/man7/SET_TRANSACTION.7

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'\" t
 
2
.\"     Title: SET TRANSACTION
 
3
.\"    Author: The PostgreSQL Global Development Group
 
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
 
5
.\"      Date: 2011-04-27
 
6
.\"    Manual: PostgreSQL 9.1beta1 Documentation
 
7
.\"    Source: PostgreSQL 9.1beta1
 
8
.\"  Language: English
 
9
.\"
 
10
.TH "SET TRANSACTION" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
 
11
.\" -----------------------------------------------------------------
 
12
.\" * set default formatting
 
13
.\" -----------------------------------------------------------------
 
14
.\" disable hyphenation
 
15
.nh
 
16
.\" disable justification (adjust text to left margin only)
 
17
.ad l
 
18
.\" -----------------------------------------------------------------
 
19
.\" * MAIN CONTENT STARTS HERE *
 
20
.\" -----------------------------------------------------------------
 
21
.SH "NAME"
 
22
SET_TRANSACTION \- set the characteristics of the current transaction
 
23
.\" SET TRANSACTION
 
24
.\" transaction isolation level: setting
 
25
.\" read-only transaction: setting
 
26
.\" deferrable transaction: setting
 
27
.SH "SYNOPSIS"
 
28
.sp
 
29
.nf
 
30
SET TRANSACTION \fItransaction_mode\fR [, \&.\&.\&.]
 
31
SET SESSION CHARACTERISTICS AS TRANSACTION \fItransaction_mode\fR [, \&.\&.\&.]
 
32
 
 
33
where \fItransaction_mode\fR is one of:
 
34
 
 
35
    ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED }
 
36
    READ WRITE | READ ONLY
 
37
    [ NOT ] DEFERRABLE
 
38
.fi
 
39
.SH "DESCRIPTION"
 
40
.PP
 
41
The
 
42
SET TRANSACTION
 
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
 
46
SET TRANSACTION
 
47
for an individual transaction\&.
 
48
.PP
 
49
The available transaction characteristics are the transaction isolation level, the transaction access mode (read/write or read\-only), and the deferrable mode\&.
 
50
.PP
 
51
The isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently:
 
52
.PP
 
53
READ COMMITTED
 
54
.RS 4
 
55
A statement can only see rows committed before it began\&. This is the default\&.
 
56
.RE
 
57
.PP
 
58
REPEATABLE READ
 
59
.RS 4
 
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\&.
 
61
.RE
 
62
.PP
 
63
SERIALIZABLE
 
64
.RS 4
 
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\&.
 
67
.RE
 
68
The SQL standard defines one additional level,
 
69
READ UNCOMMITTED\&. In
 
70
PostgreSQLREAD UNCOMMITTED
 
71
is treated as
 
72
READ COMMITTED\&.
 
73
.PP
 
74
The transaction isolation level cannot be changed after the first query or data\-modification statement (SELECT,
 
75
INSERT,
 
76
DELETE,
 
77
UPDATE,
 
78
FETCH, or
 
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\&.
 
82
.PP
 
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:
 
84
INSERT,
 
85
UPDATE,
 
86
DELETE, and
 
87
COPY FROM
 
88
if the table they would write to is not a temporary table; all
 
89
CREATE,
 
90
ALTER, and
 
91
DROP
 
92
commands;
 
93
COMMENT,
 
94
GRANT,
 
95
REVOKE,
 
96
TRUNCATE; and
 
97
EXPLAIN ANALYZE
 
98
and
 
99
EXECUTE
 
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\&.
 
101
.PP
 
102
The
 
103
DEFERRABLE
 
104
transaction property has no effect unless the transaction is also
 
105
SERIALIZABLE
 
106
and
 
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
 
108
SERIALIZABLE
 
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\&.
 
110
.SH "NOTES"
 
111
.PP
 
112
If
 
113
SET TRANSACTION
 
114
is executed without a prior
 
115
START TRANSACTION
 
116
or
 
117
BEGIN, it will appear to have no effect, since the transaction will immediately end\&.
 
118
.PP
 
119
It is possible to dispense with
 
120
SET TRANSACTION
 
121
by instead specifying the desired
 
122
\fItransaction_modes\fR
 
123
in
 
124
BEGIN
 
125
or
 
126
START TRANSACTION\&.
 
127
.PP
 
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\&.
 
138
.SH "COMPATIBILITY"
 
139
.PP
 
140
Both commands are defined in the
 
141
SQL
 
142
standard\&.
 
143
SERIALIZABLE
 
144
is the default transaction isolation level in the standard\&. In
 
145
PostgreSQL
 
146
the default is ordinarily
 
147
READ COMMITTED, but you can change it as mentioned above\&.
 
148
.PP
 
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
 
150
PostgreSQL
 
151
server\&.
 
152
.PP
 
153
The
 
154
DEFERRABLE\fItransaction_mode\fR
 
155
is a
 
156
PostgreSQL
 
157
language extension\&.
 
158
.PP
 
159
The SQL standard requires commas between successive
 
160
\fItransaction_modes\fR, but for historical reasons
 
161
PostgreSQL
 
162
allows the commas to be omitted\&.