首页 > 其他 > 详细

并发管理

时间:2017-08-15 20:36:19      阅读:310      评论:0      收藏:0      [点我收藏+]

读写冲突通过读一致性解决:

sys准备工作:

SQL> create user user01 identified by password;

SQL> grant dba to user01;

以下都用user01:

SQL> conn user01/password

Connected.

SQL> create table t1(x int);

SQL> insert into t1 values (1);

SQL> commit;

session1:

SQL> update t1 set x=11 where x=1;

SQL> select * from t1;

session 2:

SQL> select * from t1;

session 1:

SQL> commit;

session 2:

SQL> select * from t1;

测试serializable:

session1:

SQL> alter session set isolation_level=serializable;改为可串行化隔离级别

重复上面的步骤

 

写与写的冲突通过锁机制解决:

session 1:

SQL> update t1 set x=11 where x=1;

浏览器中查看锁信息

session 2:

SQL> update t1 set x=111 where x=1; 被阻塞

浏览器中查看锁信息

session 1:

SQL> rollback;

浏览器中查看锁信息

 

死锁:

session1:

SQL> select * from t1;

 

         X

----------

         1

         2

SQL> update t1 set x=11 where x=1;

session2:

SQL> update t1 set x=22 where x=2;

session1:

SQL> update t1 set x=222 where x=2; 阻塞

session2:

SQL> update t1 set x=111 where x=1; 死锁

ERROR at line 1:

ORA-00060: deadlock detected while waiting for resource

$ vi /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log

 

锁和外键

 

推荐外键做索引,避免全表扫描被锁定,提高并发

 

 

查询加锁 select … for update

并发管理

原文:http://www.cnblogs.com/shan2017/p/7367423.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!