HelloDBA [中文]
Search Internet Search HelloDBA
  Oracle Technology Site. email: fuyuncat@gmail.com  MSN: fuyuncat@hotmail.com Add to circle  acoug  acoug 

Look Oracle from inside (tracing internal calls) --- Lock (Enqueue)

[中文]

Author:  fuyuncat

Source:  www.HelloDBA.com

Date:  2010-06-11 07:41:48

Share to  Twitter Facebook GMail Blogger Orkut Google Bookmarks Sina Weibo QQ Renren Tieba Kaixin Douban Taobao

    WARNING: Never play OraTracer in any crytical system! 

Lock (Enqueue)

    The kernal function to get an enqueue is _ksqgtl, and the kernal function to release an enqueue is _ksqrcl. By tracing these 2 functions, we will monitor the lock request and release.

    Let's set the trace point first.

SQL代码
  1. _ksqrcl (0,0)   
  2. _ksqgtl (0,0,0,0,0,0,0,0)  

    Use OraTracer to trace below session.

SQL代码
  1. HELLODBA.COM>select distinct spid from v$mystat m, v$session s, v$process p where m.sid=s.sid and s.paddr=p.addr;   
  2.   
  3. SPID   
  4. ------------   
  5. 9800  

    Then execute an UPDATE sql in the session.

SQL代码
  1. HELLODBA.COM>update demo.tt set x=111 where x=1;   
  2.   
  3. rows updated.  

    We got the trace records from the log window.

SQL代码
  1. [2010-06-10 10:32:58.681]User call: _ksqgtl (TID: 9800)    
  2.     [Args(8)]:    
  3.         0x1dec4890   
  4.         3   
  5.         0   
  6.         0x147ae14   
  7.         0x31   
  8.         0x310ef   
  9.         0   
  10.         0x401   
  11. [2010-06-10 10:32:58.681]User call: _ksqgtl (TID: 9800)    
  12.     [Args(8)]:    
  13.         0x1dfd4150   
  14.         6   
  15.         0   
  16.         0   
  17.         0x3b   
  18.         0x60007   
  19.         0x1C52F   
  20.         0x401  

    The 1st argument is the lock address;
    The 2nd argument is lock mode in which the session holds the lock;
    The 3rd argument is lock mode in which the process requests the lock;
    The 5th argument is lock type;
    The 6th argument is ID1;
    The 7th argument is ID2.

    For the 1st one, we will understand that it's a TM lock by querying v$lock.

SQL代码
  1. HELLODBA.COM>select name, resname, id1, id2 from X$KSQEQTYP where indx=to_number('31''XXXXXXXX');   
  2.   
  3. NAME        RESNAME ID1                   ID2   
  4. ----------- ------- --------------------- ----------------------   
  5. DML         TM      object #              table/partition   
  6.   
  7. HELLODBA.COM>select * from V$LOCK where kaddr='1DEC4890';   
  8.   
  9. ADDR     KADDR           SID TY        ID1        ID2      LMODE    REQUEST      CTIME      BLOCK   
  10. -------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------   
  11. 1DEC4878 1DEC4890        309 TM     200943          0          3          0          6          0  

    Similarly, we got that the 2nd one is a TX lock.

SQL代码
  1. HELLODBA.COM>select name, resname, id1, id2 from X$KSQEQTYP where indx=to_number('3B''XXXXXXXX');   
  2.   
  3. NAME        RESNAME ID1                   ID2   
  4. ----------- ------- --------------------- ----------------------   
  5. Transaction TX      usn<<16 | slot        sequence  
  6.   
  7. HELLODBA.COM>select * from V$LOCK where kaddr='1DFD4150';   
  8.   
  9. ADDR     KADDR           SID TY        ID1        ID2      LMODE    REQUEST      CTIME      BLOCK   
  10. -------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------   
  11. 1DFD4034 1DFD4150        309 TX     393223     116015          6          0        207          0  

    Then, let's rollback the transaction.

SQL代码
  1. HELLODBA.COM>rollback;   
  2.   
  3. Rollback complete.  

    We got the lock releasing trace records.

SQL代码
  1. [2010-06-10 10:33:01.090]User call: _ksqrcl (TID: 9800)    
  2.     [Args(2)]:    
  3.         0x1dfd4150   
  4.         1   
  5. [2010-06-10 10:33:01.105]User call: _ksqrcl (TID: 9800)    
  6.     [Args(2)]:    
  7.         0x1dec4890   
  8.         2  

    Obviously, the 1st argument is the address of the lock to be released.

    You can download the OraTracer at here:
    http://www.HelloDBA.com/Download/OraTracer.zip

    --- Fuyuncat ---

Top

Copyright ©2005, HelloDBA.Com All reseverd.

Declaration
by fuyuncat