注册
DM8锁学习
技术分享/ 文章详情 /

DM8锁学习

火禾 2023/05/12 2015 0 0

DM锁学习
锁模拟:
session1 与 session2同时对表t2的col1=200的列进行更新,但不提交
session1:
SQL> create table t1(col1 int);
SQL> create table t2(col1 int);
SQL> insert into t1 values(100);
SQL> insert into t2 values(200);
SQL> commit;image.pngsession2:
SQL> update t2 set col1=2000 where col1=200;
image.pngsession1:
SQL> update t1 set col1=1000 where col1=100;
SQL> update t2 set col1=3000 where col1=200;(等待无法执行)
image.pngsession3:
1、查询执行时间超过2秒的会话
SQL> select * from (select sess_id,sql_text,datediff(ss,last_recv_time,sysdate)Y_EXETIME,SF_GET_SESSION_SQL(SESS_ID)fullsql,clnt_ip from v$sessions where state='ACTIVE') where Y_EXETIME>=2;

image.png
2、查询当前是否存在锁
SQL> select o.name,l.* from v$lock l,sysobjects o where l.table_id=o.id and blocked=1;

image.png
3、查询锁等待情况
SQL> select * from v$trxwait;

image.png
4、可以查询到217656请求的锁目前被217662占用
分别查询对应trx_id的SQL_TEXT
select trx_id,sql_text from v$sessions where trx_id=217656;
select trx_id,sql_text from v$sessions where trx_id=217662;
image.png
5、分别查询217656与217662对应的SQL内容
之后调用存储过程杀掉目前占用锁的会话即可
select SQL_ID,SESS_ID,TRX_ID from v$sql_history where trx_id=217662;
sp_close_session(95677440);
image.png
session1:执行成功
image.png

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服