云服务器网:购买云服务器和VPS必上的网站!

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

用户A履行删除,但是没有提交。SQL> delete from test where object_id<10;已删除8行。
用户B履行删除或更新id update test set flag=N where object_id

用户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⑴1月⑴3
LIHUILIN 139 655 09⑴1月⑴3

或使用

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://www.yuntue.com/post/152256.html | 云服务器网,转载请注明出处!

关于作者: yuntue

云服务器(www.yuntue.com)是一家专门做阿里云服务器代金券、腾讯云服务器优惠券的网站,这里你可以找到阿里云服务器腾讯云服务器等国内主流云服务器优惠价格,以及海外云服务器、vps主机等优惠信息,我们会为你提供性价比最高的云服务器和域名、数据库、CDN、免费邮箱等企业常用互联网资源。

为您推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注