并发管理

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

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

posted @ 2017-08-15 19:52  夜月色下  阅读(81)  评论(0编辑  收藏  举报