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) --- Latches

[中文]

Author:  fuyuncat

Source:  www.HelloDBA.com

Date:  2010-06-15 06:54:07

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! 

Latches

    Latch is a mechanism to serialize access to shared data structures. Not like lock, it's more transparent for user. It's hard for us to expect what exactly latches that an operation will request. Now, tracing the kernel function that get a latch, _kslgetl, it's possible for us to monitor the latch requestes.

    set the _kslgetl as trace point.

SQL代码
  1. _kslgetl (0*2,0*2,0*2,0*2,0*2,0*2)  

    Get a session to be traced in OraTracer.

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. 6996  

    Then, run a SQL that never be executed since the instance startup.

SQL代码
  1. HELLODBA.COM>select /*6*/* from demo.tt;   
  2.   
  3.          X   
  4. ----------   
  5.          8   
  6.        101   
  7.        101   
  8.         11   
  9.          1   
  10.          1   
  11.          2   
  12.          3   
  13.   
  14. rows selected.  

    We got a lots of trace records from the log window.

SQL代码
  1. [2010-06-10 15:51:04.749]User call: _kslgetl (TID: 6996)    
  2.     [Args(6)]:    
  3.         0x1c90fd48(=>0)   
  4.         1   
  5.         0   
  6.         0x9f9(=>NULL)   
  7.         0x1b08a580(=>0x370000(=>0))   
  8.         0   
  9. [2010-06-10 15:51:04.764]User call: _kslgetl (TID: 6996)    
  10.     [Args(6)]:    
  11.         0x1c90fd48(=>0)   
  12.         1   
  13.         0   
  14.         0x9f9(=>NULL)   
  15.         0x1b08a580(=>0x370000(=>0))   
  16.         0   
  17. [2010-06-10 15:51:04.764]User call: _kslgetl (TID: 6996)    
  18.     [Args(6)]:    
  19.         0x4e4cb50(=>0)   
  20.         1   
  21.         0   
  22.         0x980(=>NULL)   
  23.         0x911d1ec(=>0x911d26c(=>0x911d2a8))   
  24.         0x4674cc(=>0x8b0cc483(=>NULL))   
  25. ...  

    By counting the _kslgetl, we found the SQL execution requested latch for 360 times (This number is not exactly same for each execution).
 

    The 1st argument of the function is the address of the latch child, or the address of the latch without any child. Choose 5 of them to check the v$latch_children/v$latch, we will get to know what's kind of latches they are.

SQL代码
  1. HELLODBA.COM>select name from v$latch_children where addr='1C90FD48';   
  2.   
  3. NAME  
  4. --------------------------------------------------   
  5. library cache   
  6.   
  7. HELLODBA.COM>select name from v$latch_children where addr='1C90FFB8';   
  8.   
  9. NAME  
  10. --------------------------------------------------   
  11. library cache lock   
  12.   
  13. HELLODBA.COM>select name from v$latch_children where addr='1C90FE80';   
  14.   
  15. NAME  
  16. --------------------------------------------------   
  17. library cache pin   
  18.   
  19. HELLODBA.COM>select name from v$latch_children where addr='04E4CB50';   
  20.   
  21. NAME  
  22. --------------------------------------------------   
  23. shared pool   
  24.   
  25. HELLODBA.COM>select name from v$latch_children where addr='1E8C7D68';   
  26.   
  27. NAME  
  28. --------------------------------------------------   
  29. enqueue hash chains   
  30.   
  31. HELLODBA.COM>select name from v$latch where addr='03C3D858';   
  32.   
  33. NAME  
  34. --------------------------------------------------   
  35. enqueues  

    Tips: The kernal function that release a latch is named _kslfre.

    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