Oracle中查看引起Session阻塞的2个脚本分享

Oracle中查看引起Session阻塞的2个脚本分享,第1张

Oracle中查看引起Session阻塞的2个脚本分享

用户A执行删除,但是没有提交。

复制代码 代码如下:
SQL> delete from test where object_id<10;

已删除8行。

用户B执行删除或者更新id<10的记录,则被阻塞。

复制代码 代码如下:
SQL> update test set flag='N' where object_id<10;

遇到这种阻塞,首先需要确定问题。可以使用以下脚本。

复制代码 代码如下:
select t2.username,t2.sid,t2.serial#,t2.logon_time
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time;

结果如下:

复制代码 代码如下:
USERNAME                              SID    SERIAL# LOGON_TIME
------------------------------ ---------- ---------- --------------
LIHUILIN                               14         87 09-11月-13
LIHUILIN                              139        655 09-11月-13

或者使用

复制代码 代码如下:
select
(select username from v$session where sid=a.sid) blocker,
a.sid,' is blocking ',
(select username from v$session where sid=b.sid) blockee,
b.sid
from v$lock a,v$lock b
where a.block=1 and b.request>0 and a.id1=b.id1 and a.id2=b.id2;

结果如下:

复制代码 代码如下:
BLOCKER                               SID 'ISBLOCKING'  BLOCKEE                               SID
------------------------------ ---------- ------------- ------------------------------ ----------
LIHUILIN                               14  is blocking  LIHUILIN                              139

Kill引起阻塞的Session

复制代码 代码如下:
select 'alter system kill session '''||sid||','||serial#||''';' cmd from v$session where username='LIHUILIN' and sid=14;

结果如下:

复制代码 代码如下:
CMD
-----------------------------------------
alter system kill session '14,87';

最后执行alter system命令,阻塞解除。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/893370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-14
下一篇 2022-05-14

发表评论

登录后才能评论

评论列表(0条)

保存