RAC環境中的阻塞 查詢鎖
RAC環境下的阻塞不同於單例項情形,因為我們需要考慮到位於不同例項的session。也就是說之前查詢的v$session,v$lock相應的應變化為全域性範圍來查詢。本文提供了2個查詢指令碼,並給出例項演示那些session為阻塞者,哪些為被阻塞者。有關阻塞的概念以及單例項環境下的阻塞請參考:Oracle 阻塞(blocking blocked)
1、演示環境
- scott@DEVDB> select * from v$version where rownum<2;
- BANNER
- --------------------------------------------------------------------------------
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- --在scott session中釋出SQL語句,並未提交
- scott@DEVDB> begin
- 2 update emp set sal=sal+100 where empno=7788;
- 3 update dept set dname='DBA' where deptno=10;
- 4 end;
- 5 /
- PL/SQL procedure successfully completed.
- --在leshami session中更新emp物件
- leshami@DEVDB> update scott.emp set sal=sal-200 where empno=7788;
- --在usr1 session中更新emp物件
- usr1@DEVDB> update scott.dept set dname='DEV' where deptno=10;
2、尋找阻塞
- scott@DEVDB> @block_session_rac
- USER_STATUS SID_SERIAL CONN_INSTANCE SID PROGRAM OSUSER MACHINE LOCK_TYPE LOCK_MODE CTIME OBJECT_NAME
- --------------- --------------- ---------------- ---- ------------------------------ ------- --------------- --------------- ----------- ---------- -------------------------
- Blocking -> '20,1545' devdb1 20 sqlplus@Linux-01 (TNS V1-V3) oracle Linux-01 Transaction Exclusive 666 DEPT
- Blocking -> '20,1545' devdb1 20 sqlplus@Linux-01 (TNS V1-V3) oracle Linux-01 Transaction Exclusive 666 EMP
- Waiting '49,1007' devdb1 49 sqlplus@Linux-01 (TNS V1-V3) oracle Linux-01 Transaction None 618 EMP
- Waiting '933,11691' devdb2 933 sqlplus@Linux-02 (TNS V1-V3) oracle Linux-02 Transaction None 558 DEPT
- --透過上述指令碼我們可以看到session '20,1545' 鎖住了物件DEPT以及EMP,而此時session '49,1007'與'933,11691'處於等待狀態。
- --下面是另外的一種方式來獲取阻塞的情形
- scott@DEVDB> @block_session_rac2
- BLOCKING_STATUS
- ----------------------------------------------------------------------------------------------------------------------------
- SCOTT@Linux-01 ( INST=1 SID=20 Serail#=1545 ) IS BLOCKING USR1@Linux-02 ( INST=2 SID=933 Serial#=11691 )
- SCOTT@Linux-01 ( INST=1 SID=20 Serail#=1545 ) IS BLOCKING LESHAMI@Linux-01 ( INST=1 SID=49 Serial#=1007 )
- --Author : Leshami
- --Blog : http://blog.csdn.net/leshami
3、演示中用到的指令碼
- [oracle@Linux-01 ~]$ more block_session_rac.sql
- set linesize 180
- col user_status format a15
- col sid_serial format a15
- col program format a30 wrapped
- col machine format a15 wrapped
- col osuser format a15 wrapped
- col conn_instance format a15
- col object_name format a25 wrapped
- SELECT DECODE (l.block, 0, 'Waiting', 'Blocking ->') user_status,
- CHR (39) || s.sid || ',' || s.serial# || CHR (39) sid_serial,
- (SELECT instance_name
- FROM gv$instance
- WHERE inst_id = l.inst_id)
- conn_instance,
- s.sid,
- s.program,
- s.osuser,
- s.machine,
- DECODE (l.TYPE,
- 'RT', 'Redo Log Buffer',
- 'TD', 'Dictionary',
- 'TM', 'DML',
- 'TS', 'Temp Segments',
- 'TX', 'Transaction',
- 'UL', 'User',
- 'RW', 'Row Wait',
- l.TYPE)
- lock_type--,id1
- --,id2
- ,
- DECODE (l.lmode,
- 0, 'None',
- 1, 'Null',
- 2, 'Row Share',
- 3, 'Row Excl.',
- 4, 'Share',
- 5, 'S/Row Excl.',
- 6, 'Exclusive',
- LTRIM (TO_CHAR (lmode, '990')))
- lock_mode,
- ctime--,DECODE(l.BLOCK, 0, 'Not Blocking', 1, 'Blocking', 2, 'Global') lock_status
- ,
- object_name
- FROM gv$lock l
- JOIN gv$session s ON (l.inst_id = s.inst_id AND l.sid = s.sid)
- JOIN gv$locked_object o
- ON (o.inst_id = s.inst_id AND s.sid = o.session_id)
- JOIN dba_objects d ON (d.object_id = o.object_id)
- WHERE (l.id1, l.id2, l.TYPE) IN (SELECT id1, id2, TYPE
- FROM gv$lock
- WHERE request > 0)
- ORDER BY id1, id2, ctime DESC;
- [oracle@Linux-01 ~]$ more block_session_rac2.sql
- SELECT DISTINCT
- s1.username
- || '@'
- || s1.machine
- || ' ( INST='
- || s1.inst_id
- || ' SID='
- || s1.sid
- || ' Serail#='
- || s1.serial#
- || ' ) IS BLOCKING '
- || s2.username
- || '@'
- || s2.machine
- || ' ( INST='
- || s2.inst_id
- || ' SID='
- || s2.sid
- || ' Serial#='
- || s2.serial#
- || ' ) '
- AS blocking_status
- FROM gv$lock l1,
- gv$session s1,
- gv$lock l2,
- gv$session s2
- WHERE s1.sid = l1.sid
- AND s2.sid = l2.sid
- AND s1.inst_id = l1.inst_id
- AND s2.inst_id = l2.inst_id
- AND l1.block > 0
- AND l2.request > 0
- AND l1.id1 = l2.id1
- AND l1.id2 = l2.id2;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26224914/viewspace-2145060/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle阻塞(鎖等待)查詢Oracle
- 關於RAC環境下鎖查詢的測試案例1-1
- 關於RAC環境下鎖查詢的測試案例1-2
- RAC環境對並行查詢的支援並行
- 查詢RAC環境中例項間資源分配情況
- Oracle10g中阻塞鎖查詢更簡單Oracle
- 一條查詢Oracle中的阻塞鎖(以及阻塞在哪個資料上)的SQLOracleSQL
- Oracle中查詢阻塞與被阻塞SID的方法Oracle
- RAC環境中的TNSNAMES檔案
- oracle session阻塞查詢OracleSession
- RAC環境中的快照控制檔案
- RAC環境中的密碼檔案密碼
- RAC環境中的儲存部分管理——RAC管理
- 查詢阻塞與被阻塞SQL語句SQL
- RAC環境中的應用程式部署——RAC部署和效能
- 11.2RAC環境中的CRSD程式
- RAC環境中的初始化檔案
- Oracle阻塞會話查詢Oracle會話
- MySQL查詢阻塞語句MySql
- 環境變數與檔案查詢變數
- 查詢鎖的原因
- RAC中的並行查詢 DOP(Degree of Parallelism)並行Parallel
- package鎖的查詢與解鎖Package
- SQL Server阻塞查詢語句SQLServer
- oracle 查詢鎖 && 解鎖Oracle
- Oracle查詢鎖、解鎖Oracle
- RAC環境中的資料庫部署技術——RAC部署和效能資料庫
- 介紹RAC環境中的應用程式部署——RAC部署和效能
- oracle 中查詢被鎖的物件,並殺死死鎖程式的方法Oracle物件
- innodb查詢鎖
- TX鎖查詢
- RAC環境的恢復策略
- RAC環境下dataguard的搭建
- RAC+Dataguard環境中JDBC Failover配置JDBCAI
- 使用 strace 查詢 Emacs 啟動阻塞的原因Mac
- Waiting for table阻塞查詢的問題AI
- SQLServer DML操作阻塞SELECT查詢SQLServer
- row lock contention 阻塞程式查詢