SET TRANSACTION 中文man页面

系统
SET TRANSACTION 命令为当前事务设置特性。 它对后面的事务没有影响。 SET SESSION CHARACTERISTICS 为一个会话中的每个事务设置缺省的隔离级别。 SET TRANSACTION 可以为一个独立的事务覆盖上面的设置。

NAME

SET TRANSACTION - 设置当前事务的特性

SYNOPSIS

SET TRANSACTION
    [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
SET SESSION CHARACTERISTICS AS TRANSACTION
    [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]

DESCRIPTION 描述

SET TRANSACTION 命令为当前事务设置特性。 它对后面的事务没有影响。 SET SESSION CHARACTERISTICS 为一个会话中的每个事务设置缺省的隔离级别。 SET TRANSACTION 可以为一个独立的事务覆盖上面的设置。


 可用的事务特性是事务隔离级别和事务访问模式(读/写或者只读)。


 事务的隔离级别决定一个事务在同时存在其它并行运行的事务时它能够看到什么数据。

READ COMMITTED

 一条语句只能看到在它开始之前的数据。这是缺省。
SERIALIZABLE

 当前的事务只能看到在这次事务第一条查询或者修改数据的语句执行之前的数据。
Tip: 提示: 说白了,serializable(可串行化)意味着两个事务将把数据库保持在同一个状态, 就好象这两个事务是严格地按照先后顺序执行地那样。


 事务隔离级别在事务中第一个数据修改语句 (SELECT, INSERT, DELETE, UPDATE, FETCH, COPY) 执行之后就不能再次设置。 参阅 Chapter 12 ``Concurrency Control'' 获取有关事务隔离级别和并发性控制的更多信息。


 事务访问模式决定事务是读/写还是只读。读/写是缺省。如果一个 事务是只读,而且写入的表不是临时表,那么下面的 SQL 命令是不允许的:INSERT, UPDATE,DELETE,和 COPY TO; 而所有的 CREATE,ALTER,和 DROP 命令; COMMENT,GRANT,REVOKE, TRUNCATE;和 EXPLAIN ANALYZE 和EXECUTE 都不允许。这是一个高层次的只读概念,它并不阻止对磁盘的写入。  

NOTES 注意


 会话的缺省事务隔离级别也可以用命令

SET default_transaction_isolation = 'value'


 以及在配置文件里设置。 参考 Section 16.4 ``Run-time Configuration'' 获取更多信息。  

COMPATIBILITY 兼容性


 两个命令都在 SQL 标准里定义了。SQL 里的缺省事务隔离级别是 SERIALIZABLE; 在 PostgreSQL 里,缺省隔离级别是 READ COMMITED,但是你可以用上面的描述修改它。 PostgreSQL 并没有提供隔离级别 READ UNCOMMITTED 和 REPEATABLE READ。 因为多版本并发控制,SERIALIZABLE 级别并非真正的可串行化。参阅 Chapter 12 ``Concurrency Control'' 获取细节。


 在 SQL 标准里还有另外一种事务特性可以用这些命令设置:诊断范围的大小。这个概念只用于嵌入的 SQL。

#p#

NAME

SET TRANSACTION - set the characteristics of the current transaction

SYNOPSIS

SET TRANSACTION
    [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
SET SESSION CHARACTERISTICS AS TRANSACTION
    [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]

DESCRIPTION

The SET TRANSACTION command sets the transaction characteristics of the current transaction. It has no effect on any subsequent transactions. SET SESSION CHARACTERISTICS sets the default transaction characteristics for each transaction of a session. SET TRANSACTION can override it for an individual transaction.

The available transaction characteristics are the transaction isolation level and the transaction access mode (read/write or read-only).

The isolation level of a transaction determines what data the transaction can see when other transactions are running concurrently.

READ COMMITTED
A statement can only see rows committed before it began. This is the default.
SERIALIZABLE
The current transaction can only see rows committed before first query or data-modification statement was executed in this transaction.
Tip: Intuitively, serializable means that two concurrent transactions will leave the database in the same state as if the two has been executed strictly after one another in either order.

The transaction isolation level cannot be set after the first query or data-modification statement (SELECT, INSERT, DELETE, UPDATE, FETCH, COPY) of a transaction has been executed. See the chapter called ``Concurrency Control'' in the documentation for more information about transaction isolation and concurrency control.

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: INSERT, UPDATE, DELETE, and COPY TO if the table they would write to is not a temporary table; all CREATE, ALTER, and DROP commands; COMMENT, GRANT, REVOKE, TRUNCATE; and EXPLAIN ANALYZE and EXECUTE if the command they would execute is among those listed. This is a high-level notion of read-only that does not prevent writes to disk.  

NOTES

The session default transaction isolation level can also be set with the command

SET default_transaction_isolation = 'value'

and in the configuration file. Consult the section called ``Run-time Configuration'' in the documentation for more information.  

COMPATIBILITY

Both commands are defined in the SQL standard. SERIALIZABLE is the default transaction isolation level in the standard; in PostgreSQL the default is ordinarily READ COMMITTED, but you can change it as described above. PostgreSQL does not provide the isolation levels READ UNCOMMITTED and REPEATABLE READ. Because of multiversion concurrency control, the SERIALIZABLE level is not truly serializable. See the chapter called ``Concurrency Control'' in the documentation for details.

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 only for use in embedded SQL.

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 18:19:13

START TRANS中文man

2011-08-24 17:50:19

SET中文man

2011-08-24 17:53:08

SET CONSTRA中文man

2011-08-24 17:58:08

SET SESSION中文man

2011-08-15 10:21:09

man中文man

2011-08-24 16:48:36

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-12 14:58:05

killall中文man

2011-07-15 16:58:36

ac中文man

2011-08-15 11:10:48

more中文man

2011-08-25 17:03:51

pclose中文man

2011-08-15 14:10:37

tar中文man

2011-08-16 10:42:30

rmmod中文man

2011-08-11 17:46:02

chmod中文man

2011-08-18 13:57:38

acct中文man

2011-08-23 17:49:36

zdump中文man

2011-08-15 15:10:49

wall中文man

2011-08-12 13:26:56

groff中文man

2011-08-25 11:39:13

tzfile中文man
点赞
收藏

51CTO技术栈公众号