如何查看Oracle数据库的session阻塞

php中文网
发布: 2016-06-07 17:24:50
原创
1509人浏览过

我们都知道Oracle自己会自动处理死锁的情况,不需要人为的干预,但是Oracle不能自己处理session阻塞的的情况,阻塞导致资源的浪费

我们都知道oracle自己会自动处理死锁的情况,不需要人为的干预,,但是oracle不能自己处理session阻塞的的情况,阻塞导致资源的浪费和消耗系统性能,这个时候我们就需要快速的找出导致阻塞的原因,并尽快排除它,好让系统重新正常运行。下面我将做一个例子来解释如何迅速的处理这种阻塞:

下面的例子是两个session 同时更新HR用户的同一条记录。

HR用户窗口1:

[oracle@linuxidc ~]$ 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@linuxidc ~]$ 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用户登陆:

库宝AI
库宝AI

库宝AI是一款功能多样的智能伙伴助手,涵盖AI写作辅助、智能设计、图像生成、智能对话等多个方面。

库宝AI 109
查看详情 库宝AI

[oracle@linuxidc ~]$ 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.

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号