PG中的事务隔离级别

SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;
set default_transaction_isolation='repeatable read';
set transaction isolation level repeatable read;
show transaction_isolation;
 
 
设置默认的隔离级别,缺省的为read committed.
postgres=# set default_transaction_isolation='repeatable read';
postgres=# show transaction_isolation;
transaction_isolation
-----------------------
repeatable read
 
 
read committed,提交读,oltp
postgres=# show transaction_isolation;
transaction_isolation
-----------------------
read committed
 
repeatable read,可重复读,做报表
即一个事务中,所有的select读取的结果是一样,即都读同一个时间点上的数据。
相当于 select * from as tabName as scn=12345;
 
要注意的有同一行,补两个事务更新,被阻塞者是repeatable read事务,那么阻塞者提交后,被阻塞者将收到如下错误:
ERROR: could not serialize access due to concurrent update
如果阻塞者回退执行了回退,则持有repeatable read事务的被阻塞者也不会报错。
 
postgres=# begin;
postgres=# set transaction isolation level repeatable read;
postgres=# show transaction_isolation;
transaction_isolation
-----------------------
repeatable read
postgres=# commit;
postgres=# show transaction_isolation;
transaction_isolation
-----------------------
read committed
 
串行读 SERIALIZABLE read
严格来说,PostgreSQL在9.1之前的版本中只是实现了其中两种,即读已提交和串行读。
在PostgreSQL v9.1的版本中提供了三种实现方式,即在原有的基础上增加了可重复读。但串行读与可重复读测试目前没有差别。
不过使用MVCC机制实现的数据库隔离级别和传统锁机制实现的数据库的隔离级别有细微的差异。
 
 
 
 
 
 
 
 
 


猜你喜欢

转载自www.cnblogs.com/laverne/p/12625695.html
今日推荐