Oracle中查看引起Session阻塞的2個指令碼分享_oracle

來源:互聯網
上載者:User

使用者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命令,阻塞解除。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.