Successfully reported this slideshow.
SGA    Internals    Julian Dyke    Independent Consultant    Web Version1   © 2005 Julian Dyke       juliandyke.com
Agenda        Introduction        SGA           Granules           Fixed SGA           Buffer Cache           Shared...
Introduction        Examples based on           32 bit architecture           Red Hat 2.1 AS           Oracle 9.2.0.4 ...
Word Length        Word length can be          32 bit - 4 byte pointers          64 bit - 8 byte pointers        Also ...
Double Linked Lists - Insertion           Frequently used in SGA structures           Each element includes pointers to ...
Double Linked Lists - Deletion           Double linked lists are more efficient for              insertion             ...
Memory Areas                                        08048000          An Oracle process includes                  Executa...
Shared Memory        Shared memory can be dumped to trace file using         $ sqlplus /nolog         SQL> CONNECT SYS/<p...
ORADEBUG IPC - Example             Area #0 `Fixed Size containing Subareas 0-0              Total size 000000000006e5cc Mi...
V$SGA         Describes sizes of main components in SGA         Used by SHOW SGA command in SQL*Plus                   S...
Shared Global Area         Contains            Fixed SGA            Buffer Pool            Shared Pool                ...
Granules         Introduced in Oracle 9.0.1         SGA divided into granules         In Oracle 9.2 granule size depend...
Granules         Pool parameters rounded up to nearest granule         Each pool occupies one or more granules         ...
Granules         SGA_MAX_SIZE = 128M         4M   Fixed SGA 4M         DB_CACHE_SIZE = 48M              Free 16M         J...
Granule Operations         The following pools can be dynamically resized           Pool           Parameter             ...
Granule Views         The following views support dynamic memory management         Introduced in Oracle 9.2           ...
X$KSMGE      Introduced in Oracle 9.2      Describes individual granules     Granule ID        ADDR              RAW(4) ...
Granule Dumps         Granules can be dumped using                 ALTER SESSION SET EVENTS                 ‘immediate tr...
Fixed SGA                              Area containing all fixed variables                              Contains pointer...
X$KSMFSV         Externalises name, type, address and size of all variables in          fixed SGA                        ...
Global Area Dumps         Global areas can be dumped using                 ALTER SESSION SET EVENTS                 ‘imme...
X$KSMMEM         Externalises contents of all locations in the SGA                                                       ...
Buffer Cache                       51400000           DB_CACHE_SIZE = 48M                       51800000           DB_BLOC...
Buffer Headers         Each buffer has a buffer header         In 9.2.0.4 buffer headers are 188 bytes         Buffer h...
X$BH         Externalises buffer headers              ADDR           RAW(4)                                        Hash L...
Shared Pool                       56400000   Shared Pool includes                                     Permanent Area     ...
V$SGASTAT         Describes sizes of individual components in SGA                 SELECT pool, name, value FROM v$sgastat...
Permanent Areas         Allocated at instance startup   56400000         Contain structures such as            processe...
Sessions         Array of sessions stored in shared pool permanent area         Allocated at instance startup         N...
Sessions  ksusga_struct ksusg        Array of            X$KSUSE    X$KSUSESTA     X$KSUSECST        Pointers           V$...
Segmented Arrays         Used to store arrays of objects            Array too large to fit in granule            Array ...
Segmented Arrays            Segmented              Call              Arrays                                              S...
X$KSMDD         Externalises segmented array headers   Name of array             ADDR             RAW(4)             INDX...
Heaps         A heap consists of one or more extents         Each heap extent occupies a single granule         Each ex...
Extent      Chunks                                Extent                                                     Header      ...
X$KSMSP         Externalises chunks in the shared pool   Description of chunk type                                       ...
Heap Dumps         Heaps can be dumped using              ALTER SESSION SET EVENTS              ‘immediate trace name hea...
Free List         Heap free lists contain 255 buckets         Each bucket contains double linked list to free chunks    ...
Free List          Example Heap Header                          16       24 byte chunks                          20 Bucke...
Subheaps         Heaps can contain subheaps         Objects can have up to 10 subheaps            SQL statements includ...
Subheap Dumps         In Oracle 9.0.1 and below to dump a subheap, first obtain the          address of the subheap and c...
Subheap Dumps         Example - dump the SGA using          ALTER SESSION SET EVENTS ‘immediate trace name heapdump level...
Subheap Dumps                 HEAP DUMP heap name="library cache" desc=0x576193c4     Extent 0     extent sz=0x224 alt=327...
X$KSMHP         Externalises chunks in a subheap           ADDR           RAW(4)           INDX           NUMBER         ...
X$KSMHP                 SQL> SELECT COUNT(*) FROM x$ksmhp;                 COUNT(*)                 --------              ...
Library Cache         Database objects            Tables            Views            Packages            Functions   ...
Library Cache         For example                             CREATE TABLE t1                             (              ...
Library Cache                  512 x 1 word                                       pointers                                ...
Library Cache Object - Parent             KGLHD                   KGLNA                  Parent                           ...
Library Cache Object - Child                           Child                  Statistics                           Object ...
Library Cache - Statement                           Subquery                            Header         Explain            ...
Sort (Aggregate)               Output             SORT (AGGREGATE)              Columns                                   ...
Table Access (By Index Rowid)     Output                                                                    Predicate    C...
Index (Range Scan)          Output                                                           Predicate         Columns    ...
Shared Pool Reserved Area         Area of memory reserved for large contiguous requests for          memory         Redu...
X$KSMSPR         Externalises address, size and class of all chunks in the          shared pool                          ...
Shared Pool Reserved Area                                                        56400000       SELECT ksmchcom,ksmchptr,k...
Log Buffer                    58400000       Guard Page                                         LOG_BUFFER = 524288       ...
Thank you for your interest       For more information and to provide feedback       please contact me       My e-mail add...
Upcoming SlideShare
Loading in …5
×

Sga internals

957 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Sga internals

  1. 1. SGA Internals Julian Dyke Independent Consultant Web Version1 © 2005 Julian Dyke juliandyke.com
  2. 2. Agenda  Introduction  SGA  Granules  Fixed SGA  Buffer Cache  Shared Pool  Permanent Areas  Heaps  Subheaps  Library Cache  Reserved Area  Log Buffer  Conclusion2 © 2005 Julian Dyke juliandyke.com
  3. 3. Introduction  Examples based on  32 bit architecture  Red Hat 2.1 AS  Oracle 9.2.0.4  Single (non-RAC) instance  Examples affected by  Oracle version  Operating system  Single instance / RAC  Architecture (32/64)  Parameters3 © 2005 Julian Dyke juliandyke.com
  4. 4. Word Length  Word length can be  32 bit - 4 byte pointers  64 bit - 8 byte pointers  Also affects  size of some integer variables e.g. int  word alignment  When moving from 32 bit to 64 bit Oracle recommends doubling  SHARED_POOL_SIZE  SHARED_POOL_RESERVED_SIZE  LARGE_POOL_SIZE4 © 2005 Julian Dyke juliandyke.com
  5. 5. Double Linked Lists - Insertion  Frequently used in SGA structures  Each element includes pointers to next and previous elements  Requires 8 bytes (32 bit systems) or 16 bytes (64 bit systems) 5000F430 55443080 55845C54 52175AC0 Head 5000F430 Tail 5000F4305 © 2005 Julian Dyke STOP juliandyke.com
  6. 6. Double Linked Lists - Deletion  Double linked lists are more efficient for  insertion  deletion 5000F430 55443080 55845C54 52175AC0 Head 55443080 55845C54 52175AC0 5000F430 Tail 52175AC0 5000F430 55443080 55845C546 © 2005 Julian Dyke STOP juliandyke.com
  7. 7. Memory Areas 08048000  An Oracle process includes Executable the following memory areas 0AAA28C0 PGA Session Heap  Executable  PGA/Session Heap Shared 40000000 Libraries  Shared Libraries  SGA 50000000  Stack SGA 584A4000 Stack7 © 2005 Julian Dyke STOP juliandyke.com
  8. 8. Shared Memory  Shared memory can be dumped to trace file using $ sqlplus /nolog SQL> CONNECT SYS/<password> AS SYSDBA Connected SQL> ORADEBUG SETMYPID ORADEBUG SETMYPID Statement processed ORADEBUG IPC SQL> ORADEBUG IPC Information written to trace file SQL> ORADEBUG TRACEFILE_NAME /var/opt/oracle/admin/LX092001/udump/lx092001_ora_9824.trc8 © 2005 Julian Dyke juliandyke.com
  9. 9. ORADEBUG IPC - Example Area #0 `Fixed Size containing Subareas 0-0 Total size 000000000006e5cc Minimum Subarea size 00000000 Area Subarea Shmid Stable Addr Actual Addr 0 0 163840 0x00000050000000 0x00000050000000 Fixed Area Subarea size Segment size 000000000006f000 0000000008800000 Area #1 `Variable Size containing Subareas 1-1 Total size 0000000008000000 Minimum Subarea size 00400000 Area Subarea Shmid Stable Addr Actual Addr Variable Area 1 1 163840 0x0000005006f000 0x0000005006f000 Subarea size Segment size 0000000008391000 0000000008800000 Area #2 `Redo Buffers containing Subareas 2-2 Total size 00000000000a3000 Minimum Subarea size 00000000 Area Subarea Shmid Stable Addr Actual Addr 2 2 163840 0x00000058400000 0x00000058400000 Redo Buffers Subarea size Segment size 00000000000a3000 0000000008800000 Area #3 `skgm overhead containing Subareas 3-3 Total size 0000000000001000 Minimum Subarea size 00000000 Area Subarea Shmid Stable Addr Actual Addr 3 3 163840 0x000000584a3000 0x000000584a3000 OS Specific Subarea size Segment size 0000000000001000 00000000088000009 © 2005 Julian Dyke STOP juliandyke.com
  10. 10. V$SGA  Describes sizes of main components in SGA  Used by SHOW SGA command in SQL*Plus SELECT name, value FROM v$sga; Name Value Fixed Size 452044 Variable Size 83886080 Database Buffers 50331648 Redo Buffers 667648  Based from X$KSMSD  X$KSMSD derived from ksmstv_ (ksmst) in Fixed SGA10 © 2005 Julian Dyke juliandyke.com
  11. 11. Shared Global Area  Contains  Fixed SGA  Buffer Pool  Shared Pool Oracle 7.0 and above  Large Pool Oracle 8.0 and above  Java Pool Oracle 8.1.5 and above  Streams Pool Oracle 10.1 and above  Redo buffers  Buffer Pool includes  Default cache  Keep and Recycle cache Oracle 8.0 and above  2K, 4K, 8K, 16K and 32K cache Oracle 9.0.1 and above11 © 2005 Julian Dyke juliandyke.com
  12. 12. Granules  Introduced in Oracle 9.0.1  SGA divided into granules  In Oracle 9.2 granule size dependent on SGA_MAX_SIZE  4 mb SGA_MAX_SIZE <= 128 mb  16 mb SGA_MAX_SIZE > 128 mb  If SGA_MAX_SIZE not set explicitly then defaults to sum of individual pool parameters  SGA_MAX_SIZE cannot be dynamically modified12 © 2005 Julian Dyke juliandyke.com
  13. 13. Granules  Pool parameters rounded up to nearest granule  Each pool occupies one or more granules  Different buffer caches held in separate granules  First "granule" contains  Fixed SGA  Granule directory  Heap headers  Last "granule" contains  Guard pages  Redo buffer  Operating system specific overhead  Remaining space unused13 © 2005 Julian Dyke juliandyke.com
  14. 14. Granules SGA_MAX_SIZE = 128M 4M Fixed SGA 4M DB_CACHE_SIZE = 48M Free 16M JAVA_POOL_SIZE = 20M LARGE_POOL_SIZE = 12M Buffer Pool 48M SHARED_POOL_SIZE = 20M 128M Java Pool 20M Large Pool 12M Shared Pool 32M Note – shared pool size automatically increased Redo Buffer 4M from 20M to 32M 4M14 STOP 2005 Julian Dyke © juliandyke.com
  15. 15. Granule Operations  The following pools can be dynamically resized Pool Parameter Version Shared Pool SHARED_POOL_SIZE 9.0.1 and above Default DB_CACHE_SIZE 9.0.1 and above 2K DB_2K_CACHE_SIZE 9.0.1 and above 4K DB_4K_CACHE_SIZE 9.0.1 and above 8K DB_8K_CACHE_SIZE 9.0.1 and above 16K DB_16K_CACHE_SIZE 9.0.1 and above 32K DB_32K_CACHE_SIZE 9.0.1 and above Keep DB_KEEP_CACHE_SIZE 9.0.1 and above Recycle DB_RECYCLE_CACHE_SIZE 9.0.1 and above Large Pool LARGE_POOL_SIZE 9.2.0 and above Java Pool JAVA_POOL_SIZE 10.1 and above  Streams pool cannot be dynamically resized in Oracle 10.115 © 2005 Julian Dyke juliandyke.com
  16. 16. Granule Views  The following views support dynamic memory management  Introduced in Oracle 9.2  V$SGA_DYNAMIC_COMPONENTS  V$SGA_DYNAMIC_FREE_MEMORY  V$SGA_CURRENT_RESIZE_OPS  V$SGA_RESIZE_OPS  Not always reliable  Introduced in Oracle 10.1  V$SGAINFO16 © 2005 Julian Dyke juliandyke.com
  17. 17. X$KSMGE Introduced in Oracle 9.2 Describes individual granules Granule ID ADDR RAW(4) 0 Free 2 Shared Pool INDX NUMBER 3 Large Pool INST_ID NUMBER 4 Java Pool 5 Buffer Pool GRANNUM NUMBER GRANTYPE NUMBER INVALID (Free) ALLOCATED GRANSTATE VARCHAR2(16) GRANFLAGS NUMBER Granule Address LOCALITY NUMBER Granule Size BASEADDR RAW(4) GRANSIZE NUMBER Next granule ID GRANNEXT NUMBER Previous granule ID GRANPREV NUMBER17 © 2005 Julian Dyke juliandyke.com
  18. 18. Granule Dumps  Granules can be dumped using ALTER SESSION SET EVENTS ‘immediate trace name granulelist level <level>’  where <level> is Heap Level Null Granule 255 Home Granule 511 Shared Pool 767 Large Pool 1023 Java Pool 1279 Buffer Cache 153518 © 2005 Julian Dyke juliandyke.com
  19. 19. Fixed SGA  Area containing all fixed variables  Contains pointers to all other structures in SGA  Variable name, type, address and size determined when Oracle executable is linked  Located at start of first granule of SGA 50000000 Fixed SGA 5001D9E8 Granule Directory 5001DF50 Heap Headers19 STOP 2005 Julian Dyke © juliandyke.com
  20. 20. X$KSMFSV  Externalises name, type, address and size of all variables in fixed SGA Name ADDR RAW(4) INDX NUMBER Type INST_ID NUMBER Address KSMFSNAM VARCHAR2(64) KSMFSTYP VARCHAR2(64) Size KSMFSADR RAW(4) KSMFSSIZ NUMBER  SGA can be dumped using ORADEBUG FIXEDSGA20 © 2005 Julian Dyke juliandyke.com
  21. 21. Global Area Dumps  Global areas can be dumped using ALTER SESSION SET EVENTS ‘immediate trace name global_area level <level>’  where <level> is Heap Level PGA 1 SGA 2 PGA + SGA 3 UGA 4 PGA + UGA 5 SGA + UGA 6 PGA + SGA + UGA 7  More detail is included at levels 0x08 0x10 0x18 (OR)21 © 2005 Julian Dyke juliandyke.com
  22. 22. X$KSMMEM  Externalises contents of all locations in the SGA Address ADDR RAW(4) INDX NUMBER INST_ID NUMBER Value KSMMMVAL RAW(4)  Does not work on Windows platforms22 © 2005 Julian Dyke juliandyke.com
  23. 23. Buffer Cache 51400000 DB_CACHE_SIZE = 48M 51800000 DB_BLOCK_SIZE = 8192 51C00000  Buffer Cache includes 12 x 4M granules 52000000  Each granule contains 500 buffers 52400000  Buffer Cache contains 6000 buffers 52800000 Block Buffers Per 52C00000 Size Granule 53000000 4mb 16mb 53400000 53800000 2048 1875 7503 4096 979 3916 53C00000 8192 500 2002 54000000 16384 253 1012 32768 127 50923 © 2005 Julian Dyke STOP juliandyke.com
  24. 24. Buffer Headers  Each buffer has a buffer header  In 9.2.0.4 buffer headers are 188 bytes  Buffer headers are stored in same granule as buffers  Buffer headers include  Replacement list  Hash list  Pointer to buffer Buffer Headers Buffers Granule24 STOP 2005 Julian Dyke © juliandyke.com
  25. 25. X$BH  Externalises buffer headers ADDR RAW(4) Hash List Address INDX NUMBER INST_ID NUMBER Block Size HLADDR RAW(4) BLSIZ NUMBER Hash List NXT_HASH RAW(4) Replacement List PRV_HASH RAW(4) NXT_REPL RAW(4) Tablespace# PRV_REPL RAW(4) Absolute File Number TS# NUMBER FILE# NUMBER Relative File Number DBARFIL NUMBER Block Number DBABLK NUMBER OBJ NUMBER Object ID BA RAW(4) Buffer Address CR_SCN_BAS NUMBER25 © 2005 Julian Dyke juliandyke.com
  26. 26. Shared Pool 56400000 Shared Pool includes  Permanent Area 56800000  Segmented Arrays 56C00000  Library Cache 57000000  Row Cache  Reserved Area 57400000 57800000 Shared Pool occupies  8 x 4M granules = 32M 57C00000  SHARED_POOL_SIZE = 20M 5800000026 STOP 2005 Julian Dyke © juliandyke.com
  27. 27. V$SGASTAT  Describes sizes of individual components in SGA SELECT pool, name, value FROM v$sgastat; Pool Name Value fixed sga 452044 buffer cache 50331648 log buffer 656384 shared pool enqueues 51680 shared pool sessions 91656 shared pool library cache 1480240 shared pool dictionary cache 1614976 shared pool free memory 19746760 large pool free memory 12582912 java pool free memory 2097152027 © 2005 Julian Dyke juliandyke.com
  28. 28. Permanent Areas  Allocated at instance startup 56400000  Contain structures such as  processes 56800000  sessions 56C00000  segmented arrays SELECT ksmchptr, ksmchsiz 57000000 FROM x$ksmsp WHERE ksmchcls = perm; 57400000 Address Size 57800000 5641F000 3967868 5681F000 2718736 57C00000 56AB6C10 905116 56C1F00 4063188 58000000 5701F000 406732828 STOP 2005 Julian Dyke © juliandyke.com
  29. 29. Sessions  Array of sessions stored in shared pool permanent area  Allocated at instance startup  Number of elements specified by SESSIONS parameter  In Oracle 9.2 each element is 2412 bytes  Session array externalised by  X$KSUSE  General information  Used by V$SESSION  X$KSUSESTA  Statistics  Used by V$SESSTAT  X$KSUSECST  Current Waits  Used by V$SESSION_WAIT29 © 2005 Julian Dyke juliandyke.com
  30. 30. Sessions ksusga_struct ksusg Array of X$KSUSE X$KSUSESTA X$KSUSECST Pointers V$SESSION V$SESSTAT V$SESSION_WAIT30 STOP 2005 Julian Dyke © juliandyke.com
  31. 31. Segmented Arrays  Used to store arrays of objects  Array too large to fit in granule  Array may grow dynamically  Objects using segmented arrays include  enqueues (locks)  enqueue resources (resources)  transactions  transaction branches  Segmented arrays managed recursively by segmented array  Segmented arrays externalised in X$KSMDD31 © 2005 Julian Dyke juliandyke.com
  32. 32. Segmented Arrays Segmented Call Arrays Segmented Array Segmented Enqueues Array Segmented Header Array Segmented Array Enqueue Header Resources32 STOP 2005 Julian Dyke © juliandyke.com
  33. 33. X$KSMDD  Externalises segmented array headers Name of array ADDR RAW(4) INDX NUMBER INST_ID NUMBER NAME VARCHAR2(30) ELEMENTS_CHUNK NUMBER ITEMS_PT NUMBER INITENTRIES NUMBER NUMENTRIES NUMBER Number of chunks CURENTRIES NUMBER NUMCHUNKS NUMBER Address of parent ELEMSIZE NUMBER heap FLAGS NUMBER HEAP RAW(4) SECONDARY RAW(4)33 © 2005 Julian Dyke juliandyke.com
  34. 34. Heaps  A heap consists of one or more extents  Each heap extent occupies a single granule  Each extent contains one or more chunks  Each heap has a header containing  list of used chunks  list of free chunks Heap Extent 0 Extent 1 Extent 2 Header Free List Chunks34 STOP 2005 Julian Dyke © juliandyke.com
  35. 35. Extent Chunks Extent Header  Chunks contain Chunk  header Header  body Chunk Body  Size of chunk header dependent on chunk type  16 bytes <= size <= 32 bytes  Chunks chained through extent  Chunks can be  permanent  recreatable  freeable  free35 STOP 2005 Julian Dyke © juliandyke.com
  36. 36. X$KSMSP  Externalises chunks in the shared pool Description of chunk type Address of chunk ADDR RAW(4) Size including header INDX NUMBER INST_ID NUMBER Class ●Perm KSMCHIDX NUMBER ●Recreate KSMCHDUR NUMBER ●Freeable ●Free KSMCHCOM VARCHAR2(16) ●R-Free KSMCHPTR RAW(4) ●R-Freeable KSMCHSIZ NUMBER Type (recreate only) ●0x18 - KGL Handle KSMCHCLS VARCHAR2(8) ●0x24 - Fixed Allocation KSMCHTYP NUMBER ●0x74 - KQR PO ●0x80 - KQR SO KSMCHPAR RAW(4) ●0xFFF - Extended header Address of parent36 © 2005 Julian Dyke juliandyke.com
  37. 37. Heap Dumps  Heaps can be dumped using ALTER SESSION SET EVENTS ‘immediate trace name heapdump level <level>’;  where <level> is Heap Summary Detail PGA 1 1025 SGA 2 2050 UGA 4 4100 CGA – Current Call 8 8200 CGA – User Call 16 16400 LGA – Large Pool 32 3280037 © 2005 Julian Dyke juliandyke.com
  38. 38. Free List  Heap free lists contain 255 buckets  Each bucket contains double linked list to free chunks  Bucket sizes increase in  increments of 4 bytes - 16, 20, 24, 28, 32 ... 808, 812  increments of 64 bytes - 876, 940, 1004 ... 3948, 4012  then 4108, 8204, 16396, 32780, 65548  Reduces fragmentation38 © 2005 Julian Dyke juliandyke.com
  39. 39. Free List  Example Heap Header 16 24 byte chunks 20 Buckets 24 28 36 byte chunks 32 36 40 44 48 52 52 byte chunks 56 60 6439 © 2005 Julian Dyke juliandyke.com
  40. 40. Subheaps  Heaps can contain subheaps  Objects can have up to 10 subheaps  SQL statements include subheaps 0 and 6  Subheaps consist of one or more extents  Subheaps have heap headers  Subheap header format similar to heap header format  Only one freelist containing all free space Extent 0 Extent 1 Extent 2 Subheap Header Free List Chunk40 © 2005 Julian Dyke juliandyke.com
  41. 41. Subheap Dumps  In Oracle 9.0.1 and below to dump a subheap, first obtain the address of the subheap and convert to decimal 0x56b95c0c = 1454988300  For a summary dump use ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level 1454988300’;  For a detailed dump add 1 to the address e.g. ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level 1454988301’;  In Oracle 9.2 and above to dump the subheap summary use ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level 1, addr 0x56b95c0c’;  For a detailed dump use ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level 2, addr 0x56b95c0c’;41 © 2005 Julian Dyke juliandyke.com
  42. 42. Subheap Dumps  Example - dump the SGA using ALTER SESSION SET EVENTS ‘immediate trace name heapdump level 2’; Chunk 56b94dc8 sz= 304 recreate "KGL handles " latch=0x56efd918 Chunk 56b94ef8 sz= 560 freeable "library cache " ds=0x56b95c0c Chunk 56b95128 sz= 540 recreate "KQR PO " latch=(nil) Chunk 56b95344 sz= 540 recreate "KQR PO " latch=0x56d719f4 Chunk 56b95560 sz=1116 freeable "KGLS heap " ds=0x56b96d1c Chunk 56b959bc sz= 20 free " " Chunk 56b959d0 sz= 560 recreate "library cache " latch=(nil) ds 56b95c0c sz=1120 ct= 2 56b94ef8 sz= 560 Chunk 56b95c00 sz= 96 freeable "library cache "  Dump subheap using ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level 1, addr 0x56b95c0c’;42 © 2005 Julian Dyke juliandyke.com
  43. 43. Subheap Dumps HEAP DUMP heap name="library cache" desc=0x576193c4 Extent 0 extent sz=0x224 alt=32767 het=16 rec=9 flg=2 opc=2 parent=0x5000002c owner=0x5761826c nex=(nil) xsz=0x224 EXTENT 0 addr=0x57615130 Chunk 57615138 sz= 312 perm "perm " alo=260 Chunk 57615270 sz= 76 freeable "kgltbtab " Chunk 576152bc sz= 76 freeable "kgltbtab " Extent 1 Chunk 57615308 sz= 76 freeable "kgltbtab " EXTENT 1 addr=0x57616a88 Chunk 57616a90 sz= 512 perm "perm " alo=512 Extent 2 Chunk 57616c90 sz= 28 free " " EXTENT 2 addr=0x57618254 Chunk 5761825c sz= 172 perm "perm " alo=172 Chunk 57618308 sz= 36 free " " Free List Total heap size = 1288 FREE LISTS: Bucket 0 size=0 Chunk 57616c90 sz= 28 free " " Chunk 57618308 sz= 36 free " " Total free space = 64 UNPINNED RECREATABLE CHUNKS (lru first): PERMANENT CHUNKS: Chunk 57615138 sz= 312 perm "perm " alo=260 Chunk 57616a90 sz= 512 perm "perm " alo=512 Chunk 5761825c sz= 172 perm "perm " alo=172 Permanent space = 99643 © 2005 Julian Dyke juliandyke.com
  44. 44. X$KSMHP  Externalises chunks in a subheap ADDR RAW(4) INDX NUMBER Address of data segment INST_ID NUMBER KSMCHDS RAW(4) Description of chunk type KSMCHCOM VARCHAR2(16) Address of chunk KSMCHPTR RAW(4) KSMCHSIZ NUMBER Size including header KSMCHCLS VARCHAR2(8) Class KSMCHTYP NUMBER ●Perm ●Free KSMCHPAR RAW(4) KSMCHOWN RAW(4) Address of parent heap44 © 2005 Julian Dyke juliandyke.com
  45. 45. X$KSMHP SQL> SELECT COUNT(*) FROM x$ksmhp; COUNT(*) -------- SQL> SELECT COUNT(*) FROM 0 x$ksmhp; 0 rows SQL> SELECT kglobhd6 FROM x$kglob WHERE kglnaobj = SELECT SUM(c1) FROM t1 AND kglhdadr != kglhdpar; KGLOBHD6 -------- 5755E798 SQL> SELECT COUNT(*) FROM x$ksmhp WHERE ksmchds = HEXTORAW (5755E798); COUNT(*) -------- 145 STOP 2005 Julian Dyke © juliandyke.com
  46. 46. Library Cache  Database objects  Tables  Views  Packages  Functions  Shared cursors  SQL statements  Anonymous PL/SQL block  Stored PL/SQL procedures and functions  Java stored procedures  Methods46 © 2005 Julian Dyke juliandyke.com
  47. 47. Library Cache  For example CREATE TABLE t1 ( c1 NUMBER, c2 NUMBER, c3 NUMBER, c4 NUMBER ); CREATE INDEX i1 ON t1 (c1); CREATE INDEX i2 ON t1 (c3); SELECT SUM(c2) FROM t1 WHERE c3 = 42 AND c4 < 2004; 0 SELECT STATEMENT 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (BY INDEX ROWID) OF T1 3 2 INDEX (RANGE SCAN) OF I247 STOP 2005 Julian Dyke © juliandyke.com
  48. 48. Library Cache 512 x 1 word pointers Library Cache Object Handle 256 x DLL Heap headers ksmgsg_ KGLHD Library struct kgsms Cache KGLHD KGLHD KGLHD 512 x 256 = 131072 buckets Anonymous List KGLHD KGLHD KGLHD KGLHD48 STOP 2005 Julian Dyke © juliandyke.com
  49. 49. Library Cache Object - Parent KGLHD KGLNA Parent SELECT SUM (c2) FROM t1 Name WHERE c3 = 42 AND c4 < 2004 KGLOB Parent Object Heap 0 Parent Handle X$KGLOB Child Handle KGLHD Child 1 16 x 1 word KGLHD pointers Child 249 STOP 2005 Julian Dyke © juliandyke.com
  50. 50. Library Cache Object - Child Child Statistics Object Subheap KGLHD etc Header KGLOB Heap 0 Child Heap 6 Handle Subquery Header X$KGLOB Subheap Header SELECT Statement50 STOP 2005 Julian Dyke © juliandyke.com
  51. 51. Library Cache - Statement Subquery Header Explain SORT Plan Operation (AGGREGATE) Explain Plan Operation TABLE ACCESS (BY INDEX ROWID) Explain INDEX Plan Operation (RANGE SCAN)51 STOP 2005 Julian Dyke © juliandyke.com
  52. 52. Sort (Aggregate) Output SORT (AGGREGATE) Columns Expression Function Expression Op=SUM Expression Column Expression Variable Column Definition Column Alias Obj =1234 Alias=C2 Col=252 STOP 2005 Julian Dyke © juliandyke.com
  53. 53. Table Access (By Index Rowid) Output Predicate Columns TABLE ACCESS (BY INDEX ROWID) c4 < 2004 ROWID Variable Expression Expression Condition Column Definition Column Expression Expression Obj =1234 Col=2 Variable Function Expression Op=LT Column Definition Table Alias Expression Expression Obj =1234 Alias=T1 Col=ROWID Column Expression Constant Expression Variable Constant Value=2004 Column Definition Column Alias Obj =1234 Alias=C4 Col=453 STOP 2005 Julian Dyke © juliandyke.com
  54. 54. Index (Range Scan) Output Predicate Columns INDEX (RANGE SCAN) c3 = 42 Variable Expression Array Column Definition Expression Obj =1234 Col=ROWID Function Expression Op=EQ Expression Expression Column Expression Constant Expression Variable Constant Value=42 Column Definition Column Alias Obj =1234 Alias=C3 Col=354 STOP 2005 Julian Dyke © juliandyke.com
  55. 55. Shared Pool Reserved Area  Area of memory reserved for large contiguous requests for memory  Reduces fragmentation in shared pool  Only used if no space available in shared pool  Summarised in V$SHARED_POOL_RESERVED  SHARED_POOL_RESERVED_SIZE  specifies size of shared pool in bytes  defaults to 5% of SHARED_POOL_SIZE  _SHARED_POOL_RESERVED_PCT  specifies percentage of shared pool to reserve  defaults to 5%  _SHARED_POOL_RESERVED_MIN_ALLOC  specifies minimum chunk size e.g. 440055 © 2005 Julian Dyke juliandyke.com
  56. 56. X$KSMSPR  Externalises address, size and class of all chunks in the shared pool Comment ● free memory ADDR RAW(4) ● reserved_stopper INDX NUMBER INST_ID NUMBER Address KSMCHCOM VARCHAR2(16) KSMCHPTR RAW(4) Size in bytes KSMCHSIZ NUMBER KSMCHCLS VARCHAR2(8) Class ●R-free KSMCHTYP NUMBER ●R-freeable KSMCHPAR RAW(4)56 © 2005 Julian Dyke juliandyke.com
  57. 57. Shared Pool Reserved Area 56400000 SELECT ksmchcom,ksmchptr,ksmchsiz,ksmchcls FROM x$ksmspr 56800000 ORDER BY ksmchptr; 56C00000 KSMCHCOM KSMCHPTR KSMCHSIZ KSMCHCLS reserved_stopper 56400024 20 R-freeable 57000000 free memory 56400038 126900 R-free reserved_stopper 5641EFEC 20 R-freeable 57400000 reserved_stopper 56800024 20 R-freeable free memory 56800038 126900 R-free 57800000 reserved_stopper 5681EFEC 20 R-freeable reserved_stopper 56C00024 20 R-freeable 57C00000 free memory 56C00038 126900 R-free 58000000 reserved_stopper 56C1EFEC 20 R-freeable reserved_stopper 57000024 20 R-freeable57 STOP 2005 Julian Dyke © juliandyke.com
  58. 58. Log Buffer 58400000 Guard Page LOG_BUFFER = 524288  2 x 4K guard pages (DEADFACE)  1288 x 512 byte blocks for redo  Each 512 byte includes 16 byte header  Usable redo = 1288 x 496 = 638848 bytes Header - 16 bytes Body - 496 bytes 584A2000 Guard Page58 STOP 2005 Julian Dyke © juliandyke.com
  59. 59. Thank you for your interest For more information and to provide feedback please contact me My e-mail address is: info@juliandyke.com My website address is: www.juliandyke.com59 © 2005 Julian Dyke juliandyke.com

×