Oracle BlockingBlocked 인스턴스 상세 정보

7294 단어
1. 개요: 차단은 DBA가 자주 만나는 상황이다. 특히 불량한 응용 프로그램 설계로 인한 차단은 데이터베이스 성능이 심각하게 떨어지고 데이터베이스가 붕괴될 때까지 초래할 것이다.DBA의 입장에서 볼 때 현재 시스템에 어떤 막힘이 있는지, 도대체 누가 막힌 사람인지, 누가 막힌 사람인지 어떻게 포지셔닝해야 하는지를 알아야 한다.본고는 이에 대해 묘사하고 관련 시범을 보였다.
2. 프레젠테이션 막힘:

--   , ,   scott@CNMMBO     scott session,     ,session  。
scott@CNMMBO> update emp set sal=sal*1.1 where empno=7788;
1 row updated.
scott@CNMMBO> @my_env
 
SPID        SID  SERIAL# USERNAME    PROGRAM
------------ ---------- ---------- --------------- ------------------------------------------------
11205       1073    4642 robin      oracle@SZDB (TNS V1-V3)
 
--    session      ,   session      ,     session     
leshami@CNMMBO> update scott.emp set sal=sal+100 where empno=7788;
 
goex_admin@CNMMBO> update scott.emp set sal=sal-50 where empno=7788;
 
--      session       
scott@CNMMBO> @blocker 
 
BLOCK_MSG                        BLOCK
-------------------------------------------------- ----------
pts/5 ('1073,4642') is blocking 1067,10438         1
pts/5 ('1073,4642') is blocking 1065,4464          1
--       session 1073,4642       2 
-- session 1073,4642    ,  2 session     
 
--Author : Leshami
--Blog  : http://blog.csdn.net/leshami
 
--         session id,SQL          
scott@CNMMBO> @blocking_session_detail.sql
 
'SID='||A.SID||'WAITCLASS='||A.WAIT_CLASS||'TIME='||A.SECONDS_IN_WAIT||CHR(10)||'QUERY='||B.SQL_TEXT
------------------------------------------------------------------------
sid=1067 Wait Class=Application Time=5995
 Query=update scott.emp set sal=sal+100 where empno=7788
 
sid=1065 Wait Class=Application Time=225
 Query=update scott.emp set sal=sal-50 where empno=7788
 
--               
scott@CNMMBO> @request_lock_type
 
USERNAME               SID TY LMODE    REQUEST      ID1    ID2
------------------------------ ---------- -- ----------- ----------- ---------- ----------
SCOTT                1073 TX Exclusive  None      524319   27412
LESHAMI               1067 TX None    Exclusive    524319   27412
GOEX_ADMIN              1065 TX None    Exclusive    524319   27412
--    LESHAMI,GOEX_ADMIN 2       524319/27412  Exclusive ,      SCOTT  Exclusive 
 
--             
scott@CNMMBO> @request_lock_detail
 
    SID USERNAME       OSUSER     TERMINAL         OBJECT_NAME     TY Lock Mode  Req_Mode
---------- -------------------- --------------- ------------------------- -------------------- -- ----------- --------------------
   1065 GOEX_ADMIN      robin      pts/1           EMP         TM Row Excl
   1065 GOEX_ADMIN      robin      pts/1           Trans-524319     TX --Waiting-- Exclusive
   1067 LESHAMI       robin      pts/0           EMP         TM Row Excl
   1067 LESHAMI       robin      pts/0           Trans-524319     TX --Waiting-- Exclusive
   1073 SCOTT        robin      pts/5           EMP         TM Row Excl
   1073 SCOTT        robin      pts/5           Trans-524319     TX Exclusive 


3. 관련 SQL 스크립트의 전체 코드는 다음과 같습니다.

robin@SZDB:~/dba_scripts/custom/sql> more my_env.sql 
SELECT spid, s.sid, s.serial#, p.username, p.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr
   AND s.sid = (SELECT sid
          FROM v$mystat
          WHERE rownum = 1);

robin@SZDB:~/dba_scripts/custom/sql> more blocker.sql 
col block_msg format a50; 
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 
 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; 

robin@SZDB:~/dba_scripts/custom/sql> more blocking_session_detail.sql
--To find the query for blocking session

--Access Privileges: SELECT on v$session, v$sqlarea

SELECT   'sid='
     || a.SID
     || ' Wait Class='
     || a.wait_class
     || ' Time='
     || a.seconds_in_wait
     || CHR (10)
     || ' Query='
     || b.sql_text
  FROM v$session a, v$sqlarea b
  WHERE a.blocking_session IS NOT NULL AND a.sql_address = b.address
ORDER BY a.blocking_session
/
robin@SZDB:~/dba_scripts/custom/sql> more request_lock_type.sql
--This script generates a report of users waiting for locks.
--Access Privileges: SELECT on v$session, v$lock

SELECT sn.username, m.sid, m.type,
    DECODE(m.lmode, 0, 'None',
            1, 'Null',
            2, 'Row Share',
            3, 'Row Excl.',
            4, 'Share',
            5, 'S/Row Excl.',
            6, 'Exclusive',
        lmode, ltrim(to_char(lmode,'990'))) lmode,
    DECODE(m.request,0, 'None',
             1, 'Null',
             2, 'Row Share',
             3, 'Row Excl.',
             4, 'Share',
             5, 'S/Row Excl.',
             6, 'Exclusive',
             request, ltrim(to_char(m.request,
        '990'))) request, m.id1, m.id2
FROM v$session sn, v$lock m
WHERE (sn.sid = m.sid AND m.request != 0)
    OR (sn.sid = m.sid
        AND m.request = 0 AND lmode != 4
        AND (id1, id2) IN (SELECT s.id1, s.id2
   FROM v$lock s
            WHERE request != 0
       AND s.id1 = m.id1
                AND s.id2 = m.id2)
        )
ORDER BY id1, id2, m.request; 
robin@SZDB:~/dba_scripts/custom/sql> more request_lock_detail.sql
set linesize 190
col osuser format a15
col username format a20 wrap
col object_name format a20 wrap
col terminal format a25 wrap
col Req_Mode format a20
select B.SID, C.USERNAME, C.OSUSER, C.TERMINAL,
    DECODE(B.ID2, 0, A.OBJECT_NAME,
      'Trans-'||to_char(B.ID1)) OBJECT_NAME,
   B.TYPE,
    DECODE(B.LMODE,0,'--Waiting--',
           1,'Null',
           2,'Row Share',
           3,'Row Excl',
          4,'Share',
           5,'Sha Row Exc',
      6,'Exclusive',
            'Other') "Lock Mode",
    DECODE(B.REQUEST,0,' ',
           1,'Null',
           2,'Row Share',
           3,'Row Excl',
           4,'Share',
           5,'Sha Row Exc',
           6,'Exclusive',
           'Other') "Req_Mode"
 from DBA_OBJECTS A, V$LOCK B, V$SESSION C
where A.OBJECT_ID(+) = B.ID1
 and B.SID = C.SID
 and C.USERNAME is not null
order by B.SID, B.ID2;

좋은 웹페이지 즐겨찾기