关于序列化隔离级别需请教
测试如下(按时间顺序)
连线1 set transaction isolation level serializable;连线2 update table set ... where ROWNUM=1;
commit;连线1 update table set ... where ROWNUM=1
--> ORA-08177: 无法连续访问此事务处理为何以上错误,既然不允许这样做,
那么serializable隔离等级一般会用在什么场合下?
只读的事务吗?
测试如下(按时间顺序)
连线1 set transaction isolation level serializable;连线2 update table set ... where ROWNUM=1;
commit;连线1 update table set ... where ROWNUM=1
--> ORA-08177: 无法连续访问此事务处理为何以上错误,既然不允许这样做,
那么serializable隔离等级一般会用在什么场合下?
只读的事务吗?
通俗讲:在serializable事务执行期间,如果对该事务中的数据进行修改操作,那么serializable事务不会读取到这些变更,因此会发现无法序列化访问的错误
像是给数据库做了快照,把数据库状态定格在事务开始的时间点上.
不明白,一般使用serializable隔离级别在什么场合?举个例子.
/*
tom告诉我们,出现ORA-01877:can't serialize access for this transaction的原因:
1.oracle试图完全在行级得到serializable隔离性,
但是即使你想修改的行尚未被别人修改过,也可能得到这个错误
2.包含这一行的块上有其他行正被修改
3.没有任何阻塞,如果其他会话修改了我们想要修改的数据时。
*/
/*
serializable并不意味着用户执行的所有事务都表现得好像是以一种串行方式一个接一个地执行,
serializable不代表事务有某种串行顺序并且得到相同的结果。
(Serializable does not mean that all transactions executed by the users are the same
as if they were executed one right after another in a serial fashion.
It does not imply that there is some serial ordering of the transactions
that would result in the same outcome.
This last point is a frequently misunderstood concept.)
下面是一个验证实例:
---------------------
Time Session 1 Executes Session 2 Executes
0:00 Alter session set isolation_level=serializable;
0:01 Alter session set isolation_level=serializable;
0:02 Insert into a select count(*) from B;
0:03 Insert into b select count(*) from A;
0:04 Commit;
0:05 Commit;
0:06 select * from a;
X
------
0
0:07 select * from b;
X
--------
0
*/
/*
tom还告诉我们,如果使用serializable隔离级别,只要保证以下几点就能有效:
1.一般没有其他人修改相同的数据(同一个数据块上)
2.需要事务级读一致
3.事务都很短(有助于保证第一点)
如果你在使用serializable事务,就不要指望它与其他事务一同更新同样的信息,
若非要更新数据,就应该使用select ... for update实现在读取数据后马上锁定相关资源。
*/