如何查看Oracle資料庫的session阻塞

來源:互聯網
上載者:User

我們都知道ORACLE自己會自動處理死結的情況,不需要人為的幹預,但是ORACLE不能自己處理session阻塞的的情況,阻塞導致資源的浪費和消耗系統效能,這個時候我們就需要快速的找出導致阻塞的原因,並儘快排除它,好讓系統重新正常運行。下面我將做一個例子來解釋如何迅速的處理這種阻塞:

下面的例子是兩個session 同時更新HR使用者的同一條記錄。

HR使用者視窗1:

[oracle@even ~]$ sqlplus hr/hr

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Dec 18 14:57:27 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options

SQL> update hr.employees set last_name='b' where
employee_id=100;

1 row updated.

 

HR使用者視窗2:

[oracle@even ~]$ sqlplus hr/hr

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Dec 18 14:56:49 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options

SQL> update hr.employees set last_name='a' where
employee_id=100;

此時進入等待……hang住不動了

 

在開啟一個視窗,用SYS使用者登陸:

[oracle@even ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Dec 18 14:58:31 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options

---尋找阻塞,和被阻塞session id

SQL>select c.terminal||' ('''||a.sid||','||c.serial#||''') is blocking '||b.sid 
||','||d.serial# block_msg, a.block  from v$lock a,v$lock b,v$session c,v$session d 
  3  where a.id1=b.id1  and a.id2=b.id2  and a.block>0  and a.sid <>b.sid  and a.sid=c.sid  and b.sid=d.SID; 

BLOCK_MSG
--------------------------------------------------------------------------------
     BLOCK
----------
pts/2 ('151,18') is blocking 133,614
         1

SQL> select sid,serial#,username from v$session where username is not null; 

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
       133        614 HR
       134         71 SYS
       138        298 SYSMAN
       139          2 SYSMAN
       140          2 SYSMAN
       142         59 DBSNMP
       147        175 DBSNMP
       151         18 HR
       152       1639 SYS
       153         26 SYSMAN
       159         13 SYS

11 rows selected.

---kill the blocker '151,8'

SQL> alter system kill session'151,18';

System altered.

 

再次回到視窗1:

SQL> select * from employees;
select * from employees
*
ERROR at line 1:
ORA-00028: your session has been killed

 

 

再次回到HR使用者視窗2查看,語句已經執行了(提示1 row updated):

SQL> update hr.employees set last_name='a' where employee_id=100;

1 row updated.

 


 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.