温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

RAC环境中的阻塞 查找锁

发布时间:2020-08-07 20:05:07 来源:ITPUB博客 阅读:129 作者:flywiththewind 栏目:关系型数据库

 RAC环境下的阻塞不同于单实例情形,因为我们需要考虑到位于不同实例的session。也就是说之前查询的v$session,v$lock相应的应变化为全局范围来查找。本文提供了2个查询脚本,并给出实例演示那些session为阻塞者,哪些为被阻塞者。有关阻塞的概念以及单实例环境下的阻塞请参考:Oracle 阻塞(blocking blocked)

 

1、演示环境

[sql] view plain copy
 print?
  1. scott@DEVDB> select * from v$version where rownum<2;  
  2.   
  3. BANNER  
  4. --------------------------------------------------------------------------------  
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production  
  6.   
  7. --在scott session中发布SQL语句,并未提交  
  8. scott@DEVDB> begin  
  9.   2  update emp set sal=sal+100 where empno=7788;  
  10.   3  update dept set dname='DBA' where deptno=10;  
  11.   4  end;  
  12.   5  /  
  13.   
  14. PL/SQL procedure successfully completed.  
  15.   
  16. --在leshami session中更新emp对象  
  17. leshami@DEVDB> update scott.emp set sal=sal-200 where empno=7788;  
  18.   
  19. --在usr1 session中更新emp对象  
  20. usr1@DEVDB> update scott.dept set dname='DEV' where deptno=10;  

2、寻找阻塞

[sql] view plain copy
 print?
  1. scott@DEVDB> @block_session_rac  
  2.   
  3. USER_STATUS     SID_SERIAL      CONN_INSTANCE     SID PROGRAM                        OSUSER  MACHINE         LOCK_TYPE       LOCK_MODE        CTIME OBJECT_NAME  
  4. --------------- --------------- ---------------- ---- ------------------------------ ------- --------------- --------------- ----------- ---------- -------------------------  
  5. Blocking ->     '20,1545'       devdb1             20 sqlplus@Linux-01 (TNS V1-V3)   oracle  Linux-01        Transaction     Exclusive          666 DEPT  
  6. Blocking ->     '20,1545'       devdb1             20 sqlplus@Linux-01 (TNS V1-V3)   oracle  Linux-01        Transaction     Exclusive          666 EMP  
  7. Waiting         '49,1007'       devdb1             49 sqlplus@Linux-01 (TNS V1-V3)   oracle  Linux-01        Transaction     None               618 EMP  
  8. Waiting         '933,11691'     devdb2            933 sqlplus@Linux-02 (TNS V1-V3)   oracle  Linux-02        Transaction     None               558 DEPT  
  9.   
  10. --通过上述脚本我们可以看到session '20,1545' 锁住了对象DEPT以及EMP,而此时session '49,1007'与'933,11691'处于等待状态。  
  11.   
  12. --下面是另外的一种方式来获取阻塞的情形  
  13. scott@DEVDB> @block_session_rac2  
  14.   
  15. BLOCKING_STATUS  
  16. ----------------------------------------------------------------------------------------------------------------------------  
  17. SCOTT@Linux-01 ( INST=1 SID=20 Serail#=1545 ) IS BLOCKING USR1@Linux-02 ( INST=2 SID=933 Serial#=11691 )  
  18. SCOTT@Linux-01 ( INST=1 SID=20 Serail#=1545 ) IS BLOCKING LESHAMI@Linux-01 ( INST=1 SID=49 Serial#=1007 )  
  19.   
  20. --Author : Leshami  
  21. --Blog   : http://blog.csdn.net/leshami  

3、演示中用到的脚本

[sql] view plain copy
 print?
  1. [oracle@Linux-01 ~]$ more block_session_rac.sql   
  2. set linesize 180  
  3. col user_status format a15  
  4. col sid_serial format  a15  
  5. col program format a30 wrapped  
  6. col machine format a15 wrapped  
  7. col osuser format a15 wrapped  
  8. col conn_instance format a15  
  9. col object_name format a25 wrapped  
  10.  SELECT DECODE (l.block, 0, 'Waiting''Blocking ->') user_status,  
  11.          CHR (39) || s.sid || ',' || s.serial# || CHR (39) sid_serial,  
  12.          (SELECT instance_name  
  13.             FROM gv$instance  
  14.            WHERE inst_id = l.inst_id)  
  15.             conn_instance,  
  16.          s.sid,  
  17.          s.program,  
  18.          s.osuser,  
  19.          s.machine,  
  20.          DECODE (l.TYPE,  
  21.                  'RT''Redo Log Buffer',  
  22.                  'TD''Dictionary',  
  23.                  'TM''DML',  
  24.                  'TS''Temp Segments',  
  25.                  'TX''Transaction',  
  26.                  'UL''User',  
  27.                  'RW''Row Wait',  
  28.                  l.TYPE)  
  29.             lock_type--,id1  
  30.                      --,id2  
  31.          ,  
  32.          DECODE (l.lmode,  
  33.                  0, 'None',  
  34.                  1, 'Null',  
  35.                  2, 'Row Share',  
  36.                  3, 'Row Excl.',  
  37.                  4, 'Share',  
  38.                  5, 'S/Row Excl.',  
  39.                  6, 'Exclusive',  
  40.                  LTRIM (TO_CHAR (lmode, '990')))  
  41.             lock_mode,  
  42.          ctime--,DECODE(l.BLOCK, 0, 'Not Blocking', 1, 'Blocking', 2, 'Global') lock_status  
  43.          ,  
  44.          object_name  
  45.     FROM gv$lock l  
  46.          JOIN gv$session s ON (l.inst_id = s.inst_id AND l.sid = s.sid)  
  47.          JOIN gv$locked_object o  
  48.             ON (o.inst_id = s.inst_id AND s.sid = o.session_id)  
  49.          JOIN dba_objects d ON (d.object_id = o.object_id)  
  50.    WHERE (l.id1, l.id2, l.TYPE) IN (SELECT id1, id2, TYPE  
  51.                                       FROM gv$lock  
  52.                                      WHERE request > 0)  
  53. ORDER BY id1, id2, ctime DESC;  
  54.   
  55. [oracle@Linux-01 ~]$ more block_session_rac2.sql   
  56. SELECT DISTINCT  
  57.           s1.username  
  58.        || '@'  
  59.        || s1.machine  
  60.        || ' ( INST='  
  61.        || s1.inst_id  
  62.        || ' SID='  
  63.        || s1.sid  
  64.        || ' Serail#='  
  65.        || s1.serial#  
  66.        || ' ) IS BLOCKING '  
  67.        || s2.username  
  68.        || '@'  
  69.        || s2.machine  
  70.        || ' ( INST='  
  71.        || s2.inst_id  
  72.        || ' SID='  
  73.        || s2.sid  
  74.        || ' Serial#='  
  75.        || s2.serial#  
  76.        || ' ) '  
  77.           AS blocking_status  
  78.   FROM gv$lock l1,  
  79.        gv$session s1,  
  80.        gv$lock l2,  
  81.        gv$session s2  
  82.  WHERE     s1.sid = l1.sid  
  83.        AND s2.sid = l2.sid  
  84.        AND s1.inst_id = l1.inst_id  
  85.        AND s2.inst_id = l2.inst_id  
  86.        AND l1.block > 0  
  87.        AND l2.request > 0  
  88.        AND l1.id1 = l2.id1  
  89.        AND l1.id2 = l2.id2;  
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI