Imported upstream version 1.5
[manpages-zh.git] / raw / man7 / set_transaction.7
blob28417efcc827d35323561b4a3ac7f3670a5549d7
1 .\\" auto-generated by docbook2man-spec $Revision: 1.1 $
2 .TH "SET TRANSACTION" "7" "2003-11-02" "SQL - Language Statements" "SQL Commands"
3 .SH NAME
4 SET TRANSACTION \- set the characteristics of the current transaction
6 .SH SYNOPSIS
7 .sp
8 .nf
9 SET TRANSACTION
10     [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
11 SET SESSION CHARACTERISTICS AS TRANSACTION
12     [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
13 .sp
14 .fi
15 .SH "DESCRIPTION"
16 .PP
17 The \fBSET TRANSACTION\fR command sets the transaction
18 characteristics of the current transaction. It has no effect on any
19 subsequent transactions. \fBSET SESSION
20 CHARACTERISTICS\fR sets the default transaction
21 characteristics for each transaction of a session. \fBSET
22 TRANSACTION\fR can override it for an individual
23 transaction.
24 .PP
25 The available transaction characteristics are the transaction
26 isolation level and the transaction access mode (read/write or
27 read-only).
28 .PP
29 The isolation level of a transaction determines what data the
30 transaction can see when other transactions are running concurrently.
31 .TP
32 \fBREAD COMMITTED\fR
33 A statement can only see rows committed before it began. This
34 is the default.
35 .TP
36 \fBSERIALIZABLE\fR
37 The current transaction can only see rows committed before
38 first query or data-modification statement was executed in this transaction.
39 .sp
40 .RS
41 .B "Tip:"
42 Intuitively, serializable means that two concurrent
43 transactions will leave the database in the same state as if
44 the two has been executed strictly after one another in either
45 order.
46 .RE
47 .sp
48 .PP
49 The transaction isolation level cannot be set after the first query
50 or data-modification statement (\fBSELECT\fR,
51 \fBINSERT\fR, \fBDELETE\fR,
52 \fBUPDATE\fR, \fBFETCH\fR,
53 \fBCOPY\fR) of a transaction has been executed. See
54 the chapter called ``Concurrency Control'' in the documentation for more information about transaction
55 isolation and concurrency control.
56 .PP
57 The transaction access mode determines whether the transaction is
58 read/write or read-only. Read/write is the default. When a
59 transaction is read-only, the following SQL commands are
60 disallowed: INSERT, UPDATE,
61 DELETE, and COPY TO if the
62 table they would write to is not a temporary table; all
63 CREATE, ALTER, and
64 DROP commands; COMMENT,
65 GRANT, REVOKE,
66 TRUNCATE; and EXPLAIN ANALYZE
67 and EXECUTE if the command they would execute is
68 among those listed. This is a high-level notion of read-only that
69 does not prevent writes to disk.
70 .SH "NOTES"
71 .PP
72 The session default transaction isolation level can also be set
73 with the command
74 .sp
75 .nf
76 SET default_transaction_isolation = '\fIvalue\fR'
77 .sp
78 .fi
79 and in the configuration file. Consult the section called ``Run-time Configuration'' in the documentation for more
80 information.
81 .SH "COMPATIBILITY"
82 .PP
83 Both commands are defined in the SQL standard.
84 SERIALIZABLE is the default transaction
85 isolation level in the standard; in PostgreSQL the default is
86 ordinarily READ COMMITTED, but you can change it as
87 described above. PostgreSQL does not
88 provide the isolation levels READ UNCOMMITTED
89 and REPEATABLE READ. Because of multiversion
90 concurrency control, the SERIALIZABLE level is
91 not truly serializable. See the chapter called ``Concurrency Control'' in the documentation for details.
92 .PP
93 In the SQL standard, there is one other transaction characteristic
94 that can be set with these commands: the size of the diagnostics
95 area. This concept is only for use in embedded SQL.