Db_keep_cache_size

Hi All,
What is the functionality of db_keep_cache_size & db_recycle_size & how can i set it at my database.

Dear 788442,
Please see the following online documentations;
DB_KEEP_CACHE_SIZE;
http://download.oracle.com/docs/cd/E11882_01/server.112/e10820/initparams059.htm#REFRN10040
DB_KEEP_CACHE_SIZE specifies the size of the KEEP buffer pool. The size of the buffers in the KEEP buffer pool is the primary block size (the block size defined by the DB_BLOCK_SIZE initialization parameter).DB_RECYCLE_CACHE_SIZE;
http://download.oracle.com/docs/cd/E11882_01/server.112/e10820/initparams064.htm#REFRN10042
DB_RECYCLE_CACHE_SIZE specifies the size of the RECYCLE buffer pool. The size of the buffers in the RECYCLE pool is the primary block size (the block size defined by the DB_BLOCK_SIZE initialization parameter).Hope That Helps.
Ogan

Similar Messages

  • Questions about db_keep_cache_size and Automatic Shared Memory Management

    Hello all,
    I'm coming upon a server that I'm needing to pin a table and some objects in, per the recommendations of an application support call.
    Looking at the database, which is a 5 node RAC cluster (11gr2), I'm looking to see how things are laid out:
    SQL> select name, value, value/1024/1024 value_MB from v$parameter
    2 where name in ('db_cache_size','db_keep_cache_size','db_recycle_cache_size','shared_pool_size','sga_max_size');
    NAME VALUE VALUE_MB
    sga_max_size 1694498816 1616
    shared_pool_size 0 0
    db_cache_size 0 0
    db_keep_cache_size 0 0
    db_recycle_cache_siz 0 0
    e
    Looking at granularity level:
    SQL> select granule_size/value from v$sga_dynamic_components, v$parameter where name = 'db_block_size' and component like 'KEEP%';
    GRANULE_SIZE/VALUE
    2048
    Then....I looked, and I thought this instance was set up with Auto Shared Mem Mgmt....but I see that sga_target size is not set:
    SQL> show parameter sga
    NAME TYPE VALUE
    lock_sga boolean FALSE
    pre_page_sga boolean FALSE
    sga_max_size big integer 1616M
    sga_target big integer 0
    So, I'm wondering first of all...would it be a good idea to switch to Automatic Shared Memory Management? If so, is this as simple as altering system set sga_target =...? Again, this is on a RAC system, is there a different way to do this than on a single instance?
    If that isn't the way to go...let me continue with the table size, etc....
    The table I need to pin is:
    SQL> select sum (blocks) from all_tables where table_name = 'MYTABLE' and owner = 'MYOWNER';
    SUM(BLOCKS)
    4858
    And block size is:
    SQL> show parameter block_size
    NAME TYPE VALUE
    db_block_size integer 8192
    So, the space I'll need in memory for pinning this is:
    4858 * 8192 /1024/1024 = 37.95.......which is well below my granularity mark of 2048
    So, would this be as easy as setting db_keep_cache_size = 2048 with an alter system call? Do I need to set db_cache_size first? What do I set that to?
    Thanks in advance for any suggestions and links to info on this.
    cayenne
    Edited by: cayenne on Mar 27, 2013 10:14 AM
    Edited by: cayenne on Mar 27, 2013 10:15 AM

    JohnWatson wrote:
    This is what you need,alter system set db_keep_cache_size=40M;I do not understand the arithmetic you do here,select granule_size/value from v$sga_dynamic_components, v$parameter where name = 'db_block_size' and component like 'KEEP%';it shows you the number of buffers per granule, which I would not think has any meaning.I'd been looking at some different sites studying this, and what I got from that, was that this granularity gave you the minimum you could set the db_keep_cache_size, that if you tried setting it below this value, it would be bumped up to it, and also, that each bump you gave the keep_cache, would be in increments of the granularity number....?
    Thanks,
    cayenne

  • Table size exceeds Keep Pool Size (db_keep_cache_size)

    Hello,
    We have a situation where one of our applications started performing bad since last week.
    After some analysis, it was found this was due to data increase in a table that was stored in KEEP POOL.
    After the data increase, the table size exceeded db_keep_cache_size.
    I was of the opinion that in such cases KEEP POOL will still be used but the remaining data will be brought in as needed from the table.
    But, I ran some tests and found it is not the case. If the table size exceeds db_keep_cache_size, then KEEP POOL is not used at all.
    Is my inference correct here ?
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - ProductionSetup
    SQL> show parameter keep                    
    NAME                                 TYPE        VALUE
    buffer_pool_keep                     string
    control_file_record_keep_time        integer     7
    db_keep_cache_size                   big integer 4M
    SQL>
    SQL>     
    SQL> create table t1 storage (buffer_pool keep) as select * from all_objects union all select * from all_objects;
    Table created.
    SQL> set autotrace on
    SQL>
    SQL> exec print_table('select * from user_segments where segment_name = ''T1''');
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on
    SQL> exec print_table('select * from user_segments where segment_name = ''T1''');
    SEGMENT_NAME                  : T1
    PARTITION_NAME                :
    SEGMENT_TYPE                  : TABLE
    SEGMENT_SUBTYPE               : ASSM
    TABLESPACE_NAME               : HR_TBS
    BYTES                         : 16777216
    BLOCKS                        : 2048
    EXTENTS                       : 31
    INITIAL_EXTENT                : 65536
    NEXT_EXTENT                   : 1048576
    MIN_EXTENTS                   : 1
    MAX_EXTENTS                   : 2147483645
    MAX_SIZE                      : 2147483645
    RETENTION                     :
    MINRETENTION                  :
    PCT_INCREASE                  :
    FREELISTS                     :
    FREELIST_GROUPS               :
    BUFFER_POOL                   : KEEP
    FLASH_CACHE                   : DEFAULT
    CELL_FLASH_CACHE              : DEFAULT
    PL/SQL procedure successfully completed.DB_KEEP_CACHE_SIZE=4M
    SQL> select count(*) from t1;
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              9  recursive calls
              0  db block gets
           2006  consistent gets
           2218  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> /
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              0  recursive calls
              0  db block gets
           1940  consistent gets
           1937  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedDB_KEEP_CACHE_SIZE=10M
    SQL> connect / as sysdba
    Connected.
    SQL>
    SQL> alter system set db_keep_cache_size=10M scope=both;
    System altered.
    SQL>
    SQL> connect hr/hr@orcl
    Connected.
    SQL>
    SQL> show parameter keep
    NAME                                 TYPE        VALUE
    buffer_pool_keep                     string
    control_file_record_keep_time        integer     7
    db_keep_cache_size                   big integer 12M
    SQL>
    SQL> set autotrace on
    SQL>
    SQL> select count(*) from t1;
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              0  recursive calls
              0  db block gets
           1940  consistent gets
           1937  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> /
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              0  recursive calls
              0  db block gets
           1940  consistent gets
           1937  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedDB_KEEP_CACHE_SIZE=20M
    SQL> connect / as sysdba
    Connected.
    SQL>
    SQL> alter system set db_keep_cache_size=20M scope=both;
    System altered.
    SQL>
    SQL> connect hr/hr@orcl
    Connected.
    SQL>
    SQL> show parameter keep
    NAME                                 TYPE        VALUE
    buffer_pool_keep                     string
    control_file_record_keep_time        integer     7
    db_keep_cache_size                   big integer 20M
    SQL> set autotrace on
    SQL> select count(*) from t1;
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              0  recursive calls
              0  db block gets
           1943  consistent gets
           1656  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> /
      COUNT(*)
        135496
    Execution Plan
    Plan hash value: 3724264953
    | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |   538   (1)| 00:00:07 |
    |   1 |  SORT AGGREGATE    |      |     1 |            |          |
    |   2 |   TABLE ACCESS FULL| T1   |   126K|   538   (1)| 00:00:07 |
    Note
       - dynamic sampling used for this statement (level=2)
    Statistics
              0  recursive calls
              0  db block gets
           1943  consistent gets
              0  physical reads
              0  redo size
            424  bytes sent via SQL*Net to client
            419  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedOnly with 20M db_keep_cache_size I see no physical reads.
    Does it mean that if the db_keep_cache_size < table size, there is no caching for that table ?
    Or am I missing something ?
    Rgds,
    Gokul

    Hello Jonathan,
    Many thanks for your response.
    Here is the test I ran;
    SQL> select buffer_pool,blocks from dba_tables where owner = 'HR' and table_name = 'T1';
    BUFFER_     BLOCKS
    KEEP          1977
    SQL> select count(*) from v$bh where objd = (select data_object_id from dba_objects where owner = 'HR' and object_name = 'T1');
      COUNT(*)
          1939
    SQL> show parameter db_keep_cache_size
    NAME                                 TYPE        VALUE
    db_keep_cache_size                   big integer 20M
    SQL>
    SQL> alter system set db_keep_cache_size = 5M scope=both;
    System altered.
    SQL> select count(*) from hr.t1;
      COUNT(*)
        135496
    SQL> select count(*) from v$bh where objd = (select data_object_id from dba_objects where owner = 'HR' and object_name = 'T1');
      COUNT(*)
           992I think my inference is wrong and as you said I am indeed seeing the effect of tail end flushing the start of the table.
    Rgds,
    Gokul

  • Db_keep_cache_size aging

    Database Version: 10.2.0.4
    OS: RHEL 4
    SGA_MAX_SIZE=25G
    SGA_TARGET=10G
    Database block size=8K
    I am trying to cache the most recent 20 or so partitions of an index.
    No objects in my database were using the buffer keep pool before now.
    I did the following to accomplish this:
    alter system set sga_target=20G scope=both;
    alter system set db_keep_cache_size = 10G scope=both;
    ALTER INDEX [INDEX_NAME] modify PARTITION PART1 storage (buffer_pool keep);
    ALTER INDEX [INDEX_NAME] modify PARTITION PART2 storage (buffer_pool keep);
    ALTER INDEX [INDEX_NAME] modify PARTITION PART3 storage (buffer_pool keep);
    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR1);
    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR2);
    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR3);
    As the "SELECT" statements are running, I can see the buffer cache being populated with the blocks from this index's partitions using the following query:
    --- QUERY1
    select
    +     b.object_name,b.subobject_name,count(*)+
    from
    +     v$bh a,dba_objects b+
    where
    +     b.object_name = '[INDEX_NAME]'+
    +     and+
    +     b.owner = '[OWNER]'+
    +     and+
    +     b.object_id = a.objd and a.status != 'free'+
    group by
    +     b.object_name,b.subobject_name+
    order by 3
    +     desc;+
    I'm using the following query to determine when my db_keep_cache_size is approaching capacity:
    --- QUERY2
    select
    +     (sum(count(*))*8192)/1024/1024 BUFFER_KEEP_USED_IN_MB+
    from
    +     v$bh a,+
    +     dba_objects b+
    where
    +     b.object_name = '[INDEX_NAME]'+
    +     and+
    +     b.owner = '[OWNER]'+
    +     and+
    +     b.object_id = a.objd and a.status != 'free'+
    group by
    +     b.object_name,b.subobject_name;+
    My Problems/Questions:
    What I've noticed is that as the blocks are being cached, the index partitions that were cached first are being aged out.
    I know this is normal behavior if you reach the capacity of your buffer keep pool size but according to QUERY2 above I am not even close to reaching 10G.
    Why aren't the blocks remaining in the buffer cache? Is QUERY2 accurately depicting the usage of my buffer keep pool?
    I have already verified that this index's partitions are the only objects setup for my keep cache. (SELECT * fROM DBA_OBJECTS WHERE BUFFER_POOL <> 'DEFAULT')

    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR1);
    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR2);
    SELECT /*+ INDEX ([INDEX_NAME]) */ ... FROM [TABLE_NAME] partition (PAR3);Just to clarify.
    Do above queries follow index scan?
    ================================
    Dion Cho - Oracle Performance Storyteller
    http://dioncho.wordpress.com (english)
    http://ukja.tistory.com (korean)
    http://dioncho.blogspot.com (japanese)
    http://ask.ex-em.com (q&a)
    ================================

  • Db_keep_cache_size shows 0 when i keep object in KEEP buffer pool !

    Dear Frineds ,
    I use Oracle 10g . Form the oracle 10g documentaiton, I get the following information regarding ASMM (Automatic Shared Memory Management) :
    The following pools are manually sized components and are not affected by Automatic Shared Memory Management:
    Log buffer
    Other buffer caches (such as KEEP, RECYCLE, and other non-default block size)
    Fixed SGA and other internal allocations
    Now plz see the following examle :
    1) SQL> select sum(bytes)/1024/1024 " SGA size used in MB" from v$sgastat where name!='free memory';
    SGA size used in MB
    247.09124
    2) SQL> show parameter keep_
    NAME TYPE VALUE
    db_keep_cache_size big integer 0 (Here db_keep_cache_size is 0 )
    3) Now I keep the scott's dept table to KEEP cache :
    SQL> select owner,segment_type,segment_name,buffer_pool from dba_segments where buffer_pool != 'DEFAULT';
    no rows selected
    SQL> alter table scott.dept storage(BUFFER_POOL KEEP);
    Table altered.
    SQL> select owner,segment_type,segment_name,buffer_pool from dba_segments where buffer_pool != 'DEFAULT';
    OWNER SEGMENT_TYPE SEGMENT_NAME
    SCOTT TABLE DEPT
    4)
    After doing this , I have to see the following parameter :
    SQL> show parameter keep
    NAME TYPE VALUE
    db_keep_cache_size big integer 0
    SQL> select sum(bytes)/1024/1024 " SGA size used in MB" from v$sgastat where name!='free memory';
    SGA size used in MB
    246.76825
    Here I see that my sga is used but "db_keep_cache_size" still shows the '0' .
    Can u plz explain why this parameter value shows '0' now ?
    Thx in advance ... ...

    Hi,
    I am not sure I have understood the question fully but if you are trying to monitor usage of the buffer pools you should use some of the dynamic views like in the example query below. If this is not what you are interested in let me know.
    SELECT NAME, BLOCK_SIZE, SUM(BUFFERS)
    FROM V$BUFFER_POOL
    GROUP BY NAME, BLOCK_SIZE
    HAVING SUM(BUFFERS) > 0;

  • Buffer_pool and db_keep_cache_size

    hi all,
    i want to change the buffer_pool of one table to KEEP and my parameter settings are
    sga_target big integer 7516192768
    buffer_pool_recycle string
    db_recycle_cache_size big integer 0
    db_keep_cache_size big integer 0
    if i change the buffer_pool it KEEP for table, will it be cached or not with above settings.
    do i have to first set db_keep_cache_size to non-zero to make it effective.
    regards
    Mir

    user11972299 wrote:
    hi all,
    i want to change the buffer_pool of one table to KEEP and my parameter settings are
    sga_target big integer 7516192768
    buffer_pool_recycle string
    db_recycle_cache_size big integer 0
    db_keep_cache_size big integer 0
    if i change the buffer_pool it KEEP for table, will it be cached or not with above settings.
    do i have to first set db_keep_cache_size to non-zero to make it effective.
    buffer_pool_recycle is an old parameter. Why you want to combine with the new ASMM parameter? If you want to use Keep pool for your table, in the table, change the Storage's option BUFFER_POOL to Keep with the alter table option.
    Don't touch the db_cache_size . Let ASMM handle it.
    HTH
    Aman....

  • DB_KEEP_CACHE_SIZE  and  DB_RECYCLE_CACHE_SIZE  -- -- question

    db version = 10.2
    db block size = 8k
    I just added followiong two parameters to my init.ora:
    DB_KEEP_CACHE_SIZE=8k
    DB_RECYCLE_CACHE_SIZE=8k
    Question: I want to keep few lookup tables in 'KEEP' and 'RECYCLE'. Am I configuring the above two parameters correctly? Any inputs will be appreciated.
    regards,
    Lily.

    Sorry not mean how many rows in the tables rather the actual size like how many blocks.
    Check this from Performance Tuning Guide
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14211/memory.htm#sthref540
    You can compute an approximate size for the KEEP buffer pool by adding together the blocks used by all objects assigned to this pool. If you gather statistics on the segments, you can query DBA_TABLES.BLOCKS and DBA_TABLES.EMPTY_BLOCKS to determine the number of blocks used.

  • (9I) DYNAMIC SGA : SGA_MAX_SIZE, DB_CACHE_SIZE, DB_KEEP_CACHE_SIZE

    제품 : ORACLE SERVER
    작성날짜 : 2005-01-05
    (9I) DYNAMIC SGA : SGA_MAX_SIZE, DB_CACHE_SIZE, DB_KEEP_CACHE_SIZE
    ==================================================================
    PURPOSE
    Oracle 9i의 새 기능인 동적으로 SGA 파라미터들을 변경하는 방법에
    대하여 알아보기로 한다.
    Explanation
    Oracle 8i까지는 Buffer Cache, Shared Pool, Large Pool 등과 같은 SGA
    파라미터들에 대해 그 크기를 동적으로, db가 운영 중인 상태에서는 변경할
    수가 없었다.
    즉, 이러한 파라미터들을 변경하려면 db를 shutdown하고 initSID.ora 화일에
    서 그 크기를 다시 설정하고, 이 파라미터를 이용해서 db 인스턴스를 restart
    해야만 했었다.
    Oracle 9i에서는 DBA가 ALTER SYSTEM 명령을 이용해서 SGA 파라미터의 크기
    를 동적으로 변경할 수 있게 되었다. 이 특정을 'Dynamic SGA'라고 부른다.
    SGA 전체의 최대 크기(SGA_MAX_SIZE)를 정의하고 그 한도 내에서 파라미터의
    크기를 변경할 수 있는 것이다. 데이타베이스를 shutdown/startup 없이 작업
    이 가능하기 때문에 'Planned Downtime'을 줄이는 한 방법으로도 이해할 수
    있다.
    이 글에서는 SGA에 할당할 수 있는 최소 단위인 'Granule'의 개념을 살펴보
    고, 이 granule이 어떠한 방법에 의해 동적으로 할당되는지에 대해 알아보고
    자 한다.
    또한 Buffer Cache 파라미터 중 새로운 것과 이전 버전에 비해 달라진 내용
    을 소개하기로 한다.
    1. Granule
    Granule은 가상 메모리 상의 연속된 공간으로, dynamic SGA 모델에서 할당할
    수 있는 최소 단위이다. 이 granule의 크기는 SGA 전체의 추정값
    (SGA_MAX_SIZE)에 따라 다음과 같이 구분된다.
    4MB if estimated SGA size is < 128M
    16MB otherwise
    SGA의 Buffer Cache, Shared Pool, Large Pool 등의 파라미터는 이 granule
    단위로 늘어나거나 줄어들 수 있다. (현재 dynamic SGA를 사용할 수 있는
    SGA 관련 파라미터는 Buffer Cache, Shared Pool, Large Pool 세 가지이다.)
    2. Dynamic SGA(DB_CACHE_SIZE, SHARED_POOL_SIZE)
    DBA는 ALTER SYSTEM 명령을 통해 initSID.ora 화일에 정의된 SGA 관련 파라미
    터 값을 동적으로 변경할 수 있다. SGA 파라미터의 크기를 늘려주기 위해서
    는 필요한 만큼의 free granule이 존재해야만 하며, 현재 사용하고 있는 SGA
    의 크기가 SGA_MAX_SIZE보다 작아야 한다. Free granule이 없다고 해서 다른
    파라미터로부터 granule을 free시켜서 그 granule을 이용할 수 있는 것은 아
    니다.
    반드시 DBA가 명시적으로 free/allocate해야 한다.
    다음의 예를 살펴보자. 설명을 단순화하기 위해 이 경우는 SGA가 Buffer
    Cache와 Shared Pool로만 구성되었다고만 하자.
    예) initSID.ora
    SGA_MAX_SIZE = 128M
    DB_CACHE_SIZE = 96M
    SHARED_POOL_SIZE = 32M
    Note : DB_CACHE_SIZE는 Oracle 9i에 새롭게 도입된 파라미터이다.
    위와 같은 상태일 때 동적으로 SHARED_POOL_SIZE를 64M로 늘리면 에러가 발생
    한다.
    SQL> ALTER SYSTEM SET SHARED_POOL_SIZE=64M;
    (insufficient memory error message)
    이 에러는 SHARED_POOL_SIZE를 늘림으로써 전체 SGA의 크기가 SGA_MAX_SIZE
    보다 커지기 때문에 발생한다. (96M + 64M > 128M)
    이를 해결하기 위해서는 DB_CACHE_SIZE를 줄인 후, SHARED_POOL_SIZE를 늘린다.
    SQL> ALTER SYSTEM SET DB_CACHE_SIZE=64M;
    SQL> ALTER SYSTEM SET SHARED_POOL_SIZE=64M;
    Note : DB_CACHE_SIZE가 shrink되는 동안에
    ALTER SYSTEM SET SHARED_POOL_SIZE=64M;
    를 하면 insufficient error가 발생할 수도 있다.
    이 경우는 DB_CACHE_SIZE가 shrink된 후 다시 수행하면 정상적으로
    수행이 된다.
    Note : 위 예제의 경우 estimated SGA 크기가 128M 이상이므로, granule의
    단위는 16M이다. 따라서 SGA 파라미터의 크기를 16M의 정수배로 했다.
    16M의 정수배가 아닌 경우는 지정한 값보다 큰 값에 대해 16M의
    정수배 중 가장 가까운 값을 택하게 된다.
    즉, 아래 두 문장의 결과는 똑같다.
    SQL> ALTER SYSTEM SET SHARED_POOL_SIZE=64M;
    SQL> ALTER SYSTEM SET SHARED_POOL_SIZE=49M;
    Note : LARGE_POOL_SIZE 와 JAVA_POOL_SIZE 파라미터는 동적으로 변경하는
    것이 불가능하다.
    1) Dynamic Shared Pool
    인스턴스 start 후, Shared Pool의 크기는 다음과 같은 명령에 의해 동적으
    로 변경(grow or shrink)될 수 있다.
    ALTER SYSTEM SET SHARED_POOL_SIZE=64M;
    다음과 같은 제약 사항이 있다.
    - 실제 할당되는 크기는 16M의 정수배가 된다.
    - 전체 SGA의 크기는 SGA_MAX_SIZE를 초과할 수는 없다.
    2) Dynamic Buffer Cache
    인스턴스 start 후, Buffer Cache의 크기는 다음과 같은 명령에 의해 동적으
    로 변경(grow or shrink)될 수 있다.
    ALTER SYSTEM SET DB_CACHE_SIZE=96M;
    다음과 같은 제약 사항이 있다.
    - 실제 할당되는 크기는 16M의 정수배가 된다.
    - 전체 SGA의 크기는 SGA_MAX_SIZE를 초과할 수는 없다.
    - DB_CACHE_SIZE는 0이 될 수 없다.
    3. Buffer Cache 파라미터의 변경된 내용
    여기서는 Buffer Cache 파라미터와 관련하여 Oracle 9i에 의미가 없어진 파라
    미터와 새롭게 추가된 파라미터, 그리고 dynamic SGA 중 Buffer Cache와 관련
    이 있는 부분에 대해 기술하고자 한다.
    1) Deprecated Buffer Cache Parameters
    다음의 세 가지 파라미터는 backward compatibility를 위해 존재하는 것으
    로, 차후 의미가 없어진다.
    - DB_BLOCK_BUFFERS
    - BUFFER_POOL_KEEP
    - BUFFER_POOL_RECYCLE
    위의 파라미터들이 정의되어 있으면 이 값들을 사용하게 될 것이다. 하지만,
    다음에 나올 새로운 파라미터들을 사용하는 것이 좋으며, 만일 위 파라미터
    (DB_BLOCK_BUFFERS, BUFFER_POOL_KEEP, BUFFER_POOL_RECYCLE) 값들을 사용
    한다면 이 글에서 설명한 dynamic SGA 특징을 사용할 수는 없다. 또한
    initSID.ora 화일에 위 파라미터들과 새로운 파라미터를 동시에 기술한다면
    에러가 발생한다.
    2) New Buffer Cache Sizing Parameters
    다음의 세 파라미터가 추가되었다. 이 파라미터들은 primary block size에
    대한 buffer cache 정보를 다루고 있다.
    - DB_CACHE_SIZE
    - DB_KEEP_CACHE_SIZE
    - DB_RECYCLE_CACHE_SIZE
    DB_CACHE_SIZE 파라미터에 지정된 값은 primary block size에 대한 default
    Buffer Pool의 크기를 의미한다. 또한 이전 버전과 마찬가지로 KEEP과
    RECYCLE buffer pool을 둘 수 있는데, 이는 DB_KEEP_CACHE_SIZE,
    DB_RECYCLE_CACHE_SIZE 라는 파라미터를 이용한다.
    이전 버전과 다른 점은 이전 버전의 경우 각각의 파라미터
    (DB_BLOCK_BUFFERS, BUFFER_POOL_KEEP,BUFFER_POOL_RECYCLE)에 정의된 값들
    이 buffer 갯수(즉, 실제 메모리 크기를 구하려면 db_block_size를 곱했어야
    했다. )였는데 반해 이제는 구체적인 메모리 크기이다.
    또한 이전에는 DB_BLOCK_BUFFERS가 BUFFER_POOL_KEEP, BUFFER_POOL_RECYCLE
    의 값을 포함하고 있었지만, 이제는 DB_CACHE_SIZE가 DB_KEEP_CACHE_SIZE,
    DB_RECYCLE_CACHE_SIZE를 포함하고 있지 않다.
    즉, 각각의 파라미터들은 독립적이다.
    Note : Oracle 9i부터는 multiple block size(2K, 4K, 8K, 16K, 32K)를 지원한다.
    위에서 언급한 primary block size는 DB_BLOCK_SIZE에 의해 정해진 block
    size를 의미한다. (SYSTEM tablespace는 이 block size를 이용한다.)
    3) Dynamic Buffer Cache Size Parameters
    바로 위에서 언급한 세 파라미터는 아래와 같이 ALTER SYSTEM 명령에 의해
    동적으로 변경 가능하다.
    SQL> ALTER SYSTEM SET DB_CACHE_SIZE=96M;
    SQL> ALTER SYSTEM SET DB_KEEP_CACHE_SIZE=16M;
    SQL> ALTER SYSTEM SET DB_RECYCLE_CACHE_SIZE=16M;
    Example
    none
    Reference Documents
    <Note:148495.1>

    Hello Martin,
    Can I execute by ORA-27102 the following commandos in order to set and use the values of sga_max_size immediately?
    Variant 1)
    >sqlplus /nolog
    >connect / as sysdba
    > startup nomout
    > ALTER SYSTEM SET SGA_MAX_SIZE= ’value’ SCOPE=pfile;
    > shutdown immediate
    > startup
    Variant 2)
    Changing the values of sga_max_size, etc. in init<DBSID>.ora
    >sqlplus /nolog
    >connect / as sysdba
    > startup from pfile = /oracle/<SID>/dbs/ init<DBSID>.ora;
    Thank you very much!
    regards
    Thom

  • Three questions regarding DB_KEEP_CACHE_SIZE and caching tables.

    Folks,
    In my Oracle 10g db, which I got in legacy. It has the init.ora parameter DB_KEEP_CACHE_SIZE parameter configured to 4GB in size.
    Also there are bunch of tables that were created with CACHE turned on for them.
    By querying dba_tables table , with CACHE='Y', I can see the name of these tables.
    With time, some of these tables have grown in size (no. of rows) and also some of these tables are not required to be cached any longer.
    So here is my first question
    1) Is there a query I can run , to find out , what tables are currently in the DB_KEEP_CACHE_SIZE.
    2) Also how can I find out if my DB_KEEP_CACHE_SIZE is adqueataly sized or needs to be increased in size,as some of these
    tables have grown in size.
    Third question
    I know for fact, that there are 2 tables that do not need to be cached any longer.
    So how do I make sure they do not occupy space in the DB_KEEP_CACHE_POOL.
    I tried, alter table <table_name> nocache; statement
    Now the cache column value for these in dba_tables is 'N', but if I query the dba_segments tables, the BUFFER_POOL column for them still has value of 'KEEP'.
    After altering these tables to nocache, I did bounce my database.
    Again, So how do I make sure these tables which are not required to be cached any longer, do not occupy space in the DB_KEEP_CACHE_SIZE.
    Would very much appreciate your help.
    Regards
    Ashish

    Hello,
    1) Is there a query I can run , to find out , what tables are currently in the DB_KEEP_CACHE_SIZE:You may try this query:
    select owner, segment_name, segment_type, buffer_pool
    from dba_segments
    where buffer_pool = 'KEEP'
    order by owner, segment_name;
    2) Also how can I find out if my DB_KEEP_CACHE_SIZE is adqueataly sized or needs to be increased in size,as some of these tables have grown in size.You may try to get the total size of the Segments using the KEEP BUFFER:
    select sum(bytes)/(1024*10124) "Mo"
    from dba_segments
    where buffer_pool = 'KEEP';To be sure that all the blocks of these segments (Table / Index) won't be often aged out from the KEEP BUFFER, the total size given by the above query should be less than the size of your KEEP BUFFER.
    I know for fact, that there are 2 tables that do not need to be cached any longer.
    So how do I make sure they do not occupy space in the DB_KEEP_CACHE_POOL.You just have to execute the following statement:
    ALTER TABLE <owner>.<table> STORAGE(BUFFER_POOL DEFAULT);Hope this help.
    Best regards,
    Jean-Valentin

  • ASMM  - DB_KEEP_CACHE_SIZE

    Hello colleagues
    10.2.0.2 - MS2003 SP2
    I'm using ASMM and I like to pin a frequently scanned table to the KEEP buffer. The parameter DB_KEEP_CACHE_SIZE is per default 0. Do I have to change this parameter to the size of the object (at least) I like to pin?
    If I set a fixed size of e.g. 200M - is this space allocated as one piece and not used anymore by other SGA components or is the "unused" space still available?
    How can I prove that my object is located in the KEEP cache?
    Thx for your hints.
    TonyDBA

    Hello colleagues
    10.2.0.2 - MS2003 SP2
    I'm using ASMM and I like to pin a frequently scanned table to the KEEP buffer. The parameter DB_KEEP_CACHE_SIZE is per default 0. Do I have to change this parameter to the size of the object (at least) I like to pin?
    If I set a fixed size of e.g. 200M - is this space allocated as one piece and not used anymore by other SGA components or is the "unused" space still available?
    How can I prove that my object is located in the KEEP cache?
    Thx for your hints.
    TonyDBA
    Keep buffer usually to keep small, almost never updated table which used as look up table.
    Set DB_KEEP_CACHE_SIZE size big enough to keep the table. Memory allocated for DB_KEEP_CACHE_SIZE will not be used by other component of SGA.
    Use below query to check the tables that sitting on buffer cache:
    select
    object_name c1,
    object_type c2,
    num_blocks c3,
    (num_blocks/decode(sum(blocks), 0, .001, sum(blocks)))*100 c4
    from
    (select
    o.object_name object_name,
    o.object_type object_type,
    count(1) num_blocks
    from
    dba_objects o,
    v$bh bh
    where
    o.object_id = bh.objd
    and
    o.owner not in ('SYS','SYSTEM')
    group by
    o.object_name,
    o.object_type)
    t1,
    dba_segments s
    where
    s.segment_name = t1.object_name
    and
    num_blocks > 10
    group by
    object_name,
    object_type,
    num_blocks
    order by
    num_blocks desc
    regards
    AM

  • Buffer_pool & db_keep_cache_size

    Our database is 10.2.0.3 with 2 nodes RAC. The database servers are window 2003.
    I ran the query “select * from dba_tables where buffer_pool = 'KEEP'” and get 6 records come back. Some tables are pretty big.
    I ran “select sum(blocks) * 8192 from dba_tables where buffer_pool = 'KEEP'” and get:
    5489451008
    The parameter for db_keep_cache_size is 1073741824 for both instances.
    My question is: How Oracle handles this if Oracle allocated memory is smaller than the requested space? What are the impacts on the performance?
    Thanks,
    Shirley

    Yes, a buffer pool is a buffer pool and is managed as such. Each type of pool may have has some unique logic especially for how data is selected to go into the pool (keep, recycle, 16K block size, 2K block size) but when all else is said and done the end product is a buffer cache that has to be managed.
    Personally, I am not a fan of using multiple buffer pools. For most situations Oracle can probably do a better job of deciding what blocks to keep and purge from one large buffer cache than most DBA's can do by using the normal buffer cache, a keep, and a recycle pool. Over time the application data and usage changes. The pool configuration probably is not checked regularly enough to keep it properly aligned.
    Besides Oracle really uses a modified for touch count algorithm to manage the buffer cache instead of the documented LRU. Call it a modified LRU algorithm so the need to use a keep and/or recycle really isn’t there for most shops.
    IMHO -- Mark D Powell --

  • Db_keep_cache_size and cache in dba_tables

    Hello All:
    I have recently alter a table to cache it in db_keep_cache pool however i do not see the change reflected in dba_tables in cache column. Is this expected behaviour?
    Thanks
    S~

    The CACHE clause is specified when you create the table. It indicates how the blocks of this table handled in regular buffer cache. It's separate setting from keep cache.
    CACHE
    For data that is accessed frequently, this clause indicates that the blocks retrieved for this table are placed at the most recently used end of the least recently used (LRU) list in the buffer cache when a full table scan is performed. This attribute is useful for small lookup tables.
    Once you put your table in keep pool, the BUFFER_POOL should indicate which pool this object belong to.
    select buffer_pool from dba_tables
      2  where table_name='TEST1'
      3  /
    BUFFER_
    KEEP

  • DB_KEEP_CACHE_SIZE, DB_RECYCLE_CACHE_SIZE

    The keep buffer pool retains the schema objects in the memory. and the recycle buffer pool eliminates the data blocks from the memory as soon as they are no longer needed.
    Now i have a table shares with 230Mb of dataa (approx 34M rows).
    i use the alter table shares cache; statement to indicate that the blocks of the segment shares have to be kept in the memory.
    i use the alter table shares nocache; statement to indicate the blocks should be removed once the work is done.
    1. am i correct for the above statements regarding using the cache and nocache option.
    2. can any one tell me how to specify htat the blocks of a particular segment have to be in keep cache. if the above statement is false.
    3. please guys, can any one explain me the details regarding how to cache. and how to use recycle cache size for segments.

    Hi vishnusivathej ,
    Default cache: blocks will be kept or remove from database buffer cache based on LRU (Least Recent Used).
    Recycle cache: blocks will be removed from database buffer cache after being issued
    Keep cache: : blocks will be remain in database buffer cache
    You cannnot assign a db cache based on segment. This is a storage option for an entire object, unless you have a partitioned table (then you can define which cache to use on a partition level).
    Syntax:
    alter TABLE <schema>.<table_name> storage (buffer_pool keep);
    alter INDEX <schema>.<index_name> storage (buffer_pool keep);
    You can refer to the following discussions as well:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:23558719922648
    http://www.dba-oracle.com/t_script_automate_keep_pool_tables_indexes.htm
    HTH,
    Thierry
    Note: the use of the keep pool is intended for small / frenquently used tables (lookup tables). I implemented this some time ago, and acheived a substantial increase of performance.
    Edited by: Urgent-IT on Feb 2, 2011 9:00 AM

  • DB_KEEP_CACHE_SIZE suitable size

    I am using an Oracle 10g Release 1 database and was wondering if anybody has any suggestions on how one can investigate if it is appropriately sized ? The current setting in our environment is 1 Gbyte. We have a very large table 100 Gbyte , which contains LOB data where the KEEP option has been set (ALTER TABLE KEEP).
    I am looking for ways to investigate if the current setting of 1 Gbyte is appropriate ?

    That is depend up on the size of memory available and tables to be in Keep cache
    if you donot have less menory in keep than the table soze .. table will be on memory+disk
    Please go through the Doc ID: Note:257643.1

  • Package.......StatsPack...Error..

    Hi.. i m tuning my Oracle Database, for that i need to install Statspack package, when i compiled package... it returned following error.
    Warning: Package Body created with compilation errors.
    SQL> show error
    Errors for PACKAGE BODY STATSPACK:
    LINE/COL ERROR
    2045/3 PLS-00201: identifier 'SYS.DBMS_SHARED_POOL' must be declared
    2045/3 PL/SQL: Statement ignored
    HOw to solve above error..Please check the following Package, and do help me.
    Note: I m connected perfstat user, no as SYS user.
    create or replace package body STATSPACK as
    /* Define package variables.
    Variables prefixed with p_ are package variables.
    p_snap_id integer; /* snapshot id */
    p_instance_number number; /* instance number */
    p_instance_name varchar2(16); /* instance name */
    p_startup_time date; /* instance startup time */
    p_parallel varchar2(3); /* parallel server */
    p_version varchar2(17); /* Oracle release */
    p_dbid number; /* database id */
    p_host_name varchar2(64); /* host instance is on */
    p_name varchar2(9); /* database name */
    p_new_sga integer; /* Instance bounced since last snap? */
    tmp_int integer; /* initialise defaults */
    p_def_snap_level number default 5; /* default snapshot lvl */
    p_def_session_id number default 0; /* default session id */
    p_def_ucomment varchar2(160) default null;
    p_def_pin_statspack varchar2(10) default 'TRUE';
    p_def_last_modified date default SYSDATE;
    /* Below are the default threshold (_th) values for choosing SQL statements
    to store in the stats$sqlsummary table - these statements will typically
    be the statements using the most resources.
    p_def_num_sql number default 50; /* Num. SQL statements */
    p_def_executions_th number default 100; /* Num. executions */
    p_def_parse_calls_th number default 1000; /* Num. parse calls */
    p_def_disk_reads_th number default 1000; /* Num. disk reads */
    p_def_buffer_gets_th number default 10000; /* Num. buf gets */
    p_def_sharable_mem_th number default 1048576; /* Sharable memory */
    p_def_version_count_th number default 20; /* Child Cursors */
    p_def_all_init varchar2(10) default 'FALSE';
    cursor get_instance is
    select instance_number, instance_name
    , startup_time, parallel, version
    , host_name
    from v$instance;
    cursor get_db is
    select dbid, name
    from v$database;
    procedure SNAP
    (i_snap_level in number default null
    ,i_session_id in number default null
    ,i_ucomment in varchar2 default null
    ,i_num_sql in number default null
    ,i_executions_th in number default null
    ,i_parse_calls_th in number default null
    ,i_disk_reads_th in number default null
    ,i_buffer_gets_th in number default null
    ,i_sharable_mem_th in number default null
    ,i_version_count_th in number default null
    ,i_all_init in varchar2 default null
    ,i_pin_statspack in varchar2 default null
    ,i_modify_parameter in varchar2 default 'FALSE'
    is
    /* Takes a snapshot by calling the SNAP function, and discards
    the snapshot id. This is useful when automating taking
    snapshots from dbms_job
    l_snap_id number;
    begin
    l_snap_id := statspack.snap ( i_snap_level, i_session_id, i_ucomment
    , i_num_sql
    , i_executions_th
    , i_parse_calls_th
    , i_disk_reads_th
    , i_buffer_gets_th
    , i_sharable_mem_th
    , i_version_count_th
    , i_all_init
    , i_pin_statspack
    , i_modify_parameter);
    end SNAP;
    procedure MODIFY_STATSPACK_PARAMETER
    ( i_dbid in number default null
    , i_instance_number in number default null
    , i_snap_level in number default null
    , i_session_id in number default null
    , i_ucomment in varchar2 default null
    , i_num_sql in number default null
    , i_executions_th in number default null
    , i_parse_calls_th in number default null
    , i_disk_reads_th in number default null
    , i_buffer_gets_th in number default null
    , i_sharable_mem_th in number default null
    , i_version_count_th in number default null
    , i_all_init in varchar2 default null
    , i_pin_statspack in varchar2 default null
    , i_modify_parameter in varchar2 default 'TRUE'
    is
    /* Calls QAM with the modify flag, and discards the
    output variables
    l_snap_level number;
    l_session_id number;
    l_ucomment varchar2(160);
    l_num_sql number;
    l_executions_th number;
    l_parse_calls_th number;
    l_disk_reads_th number;
    l_buffer_gets_th number;
    l_sharable_mem_th number;
    l_version_count_th number;
    l_all_init varchar2(5);
    l_pin_statspack varchar2(10);
    begin
    statspack.qam_statspack_parameter( i_dbid
    , i_instance_number
    , i_snap_level
    , i_session_id
    , i_ucomment
    , i_num_sql
    , i_executions_th
    , i_parse_calls_th
    , i_disk_reads_th
    , i_buffer_gets_th
    , i_sharable_mem_th
    , i_version_count_th
    , i_all_init
    , i_pin_statspack
    , 'TRUE'
    , l_snap_level
    , l_session_id
    , l_ucomment
    , l_num_sql
    , l_executions_th
    , l_parse_calls_th
    , l_disk_reads_th
    , l_buffer_gets_th
    , l_sharable_mem_th
    , l_version_count_th
    , l_all_init
    , l_pin_statspack);
    /* As we have explicity been requested to change the parameters,
    independently of taking a snapshot, commit
    commit;
    end MODIFY_STATSPACK_PARAMETER;
    procedure QAM_STATSPACK_PARAMETER
    ( i_dbid in number default null
    , i_instance_number in number default null
    , i_snap_level in number default null
    , i_session_id in number default null
    , i_ucomment in varchar2 default null
    , i_num_sql in number default null
    , i_executions_th in number default null
    , i_parse_calls_th in number default null
    , i_disk_reads_th in number default null
    , i_buffer_gets_th in number default null
    , i_sharable_mem_th in number default null
    , i_version_count_th in number default null
    , i_all_init in varchar2 default null
    , i_pin_statspack in varchar2 default null
    , i_modify_parameter in varchar2 default 'FALSE'
    , o_snap_level out number
    , o_session_id out number
    , o_ucomment out varchar2
    , o_num_sql out number
    , o_executions_th out number
    , o_parse_calls_th out number
    , o_disk_reads_th out number
    , o_buffer_gets_th out number
    , o_sharable_mem_th out number
    , o_version_count_th out number
    , o_all_init out varchar2
    , o_pin_statspack out varchar2
    is
    /* Query And Modify statspack parameter procedure, allows query
    and/or user modification of the statistics collection parameters
    for an instance. If there are no pre-existing parameters for
    an instance, insert the Oracle defaults.
    l_instance_number number;
    l_dbid number;
    ui_all_init varchar2(5);
    l_params_exist varchar2(1);
    begin
    if ((i_dbid is null ) or (i_instance_number is null)) then
    l_dbid := p_dbid;
    l_instance_number := p_instance_number;
    else
    l_dbid := i_dbid;
    l_instance_number := i_instance_number;
    end if;
    /* Upper case any input vars which are inserted */
    ui_all_init := upper(i_all_init);
    if ( (i_modify_parameter is null)
    or (upper(i_modify_parameter) = 'FALSE') ) then
    /* Query values, if none exist, insert the defaults tempered
    with variables supplied */
    begin
    select nvl(i_session_id, session_id)
    , nvl(i_snap_level, snap_level)
    , nvl(i_ucomment, ucomment)
    , nvl(i_num_sql, num_sql)
    , nvl(i_executions_th, executions_th)
    , nvl(i_parse_calls_th, parse_calls_th)
    , nvl(i_disk_reads_th, disk_reads_th)
    , nvl(i_buffer_gets_th, buffer_gets_th)
    , nvl(i_sharable_mem_th, sharable_mem_th)
    , nvl(i_version_count_th, version_count_th)
    , nvl(ui_all_init, all_init)
    , nvl(i_pin_statspack, pin_statspack)
    into o_session_id
    , o_snap_level
    , o_ucomment
    , o_num_sql
    , o_executions_th
    , o_parse_calls_th
    , o_disk_reads_th
    , o_buffer_gets_th
    , o_sharable_mem_th
    , o_version_count_th
    , o_all_init
    , o_pin_statspack
    from stats$statspack_parameter
    where instance_number = l_instance_number
    and dbid = l_dbid;
    exception
    when NO_DATA_FOUND then
    insert into stats$statspack_parameter
    ( dbid
    , instance_number
    , session_id
    , snap_level
    , ucomment
    , num_sql
    , executions_th
    , parse_calls_th
    , disk_reads_th
    , buffer_gets_th
    , sharable_mem_th
    , version_count_th
    , all_init
    , pin_statspack
    , last_modified
    values
    ( l_dbid
    , l_instance_number
    , p_def_session_id
    , p_def_snap_level
    , p_def_ucomment
    , p_def_num_sql
    , p_def_executions_th
    , p_def_parse_calls_th
    , p_def_disk_reads_th
    , p_def_buffer_gets_th
    , p_def_sharable_mem_th
    , p_def_version_count_th
    , p_def_all_init
    , p_def_pin_statspack
    , SYSDATE
    returning nvl(i_session_id, p_def_session_id)
    , nvl(i_snap_level, p_def_snap_level)
    , nvl(i_ucomment, p_def_ucomment)
    , nvl(i_num_sql, p_def_num_sql)
    , nvl(i_executions_th, p_def_executions_th)
    , nvl(i_parse_calls_th, p_def_parse_calls_th)
    , nvl(i_disk_reads_th, p_def_disk_reads_th)
    , nvl(i_buffer_gets_th, p_def_buffer_gets_th)
    , nvl(i_sharable_mem_th, p_def_sharable_mem_th)
    , nvl(i_version_count_th, p_def_version_count_th)
    , nvl(ui_all_init, p_def_all_init)
    , nvl(i_pin_statspack, p_def_pin_statspack)
    into o_session_id
    , o_snap_level
    , o_ucomment
    , o_num_sql
    , o_executions_th
    , o_parse_calls_th
    , o_disk_reads_th
    , o_buffer_gets_th
    , o_sharable_mem_th
    , o_version_count_th
    , o_all_init
    , o_pin_statspack;
    end; /* don't modify parameter values */
    elsif upper(i_modify_parameter) = 'TRUE' then
    /* modify values, if none exist, insert the defaults tempered
    with the variables supplied */
    begin
    update stats$statspack_parameter
    set session_id = nvl(i_session_id, session_id)
    , snap_level = nvl(i_snap_level, snap_level)
    , ucomment = nvl(i_ucomment, ucomment)
    , num_sql = nvl(i_num_sql, num_sql)
    , executions_th = nvl(i_executions_th, executions_th)
    , parse_calls_th = nvl(i_parse_calls_th, parse_calls_th)
    , disk_reads_th = nvl(i_disk_reads_th, disk_reads_th)
    , buffer_gets_th = nvl(i_buffer_gets_th, buffer_gets_th)
    , sharable_mem_th = nvl(i_sharable_mem_th, sharable_mem_th)
    , version_count_th = nvl(i_version_count_th, version_count_th)
    , all_init = nvl(ui_all_init, all_init)
    , pin_statspack = nvl(i_pin_statspack, pin_statspack)
    where instance_number = l_instance_number
    and dbid = l_dbid
    returning session_id
    , snap_level
    , ucomment
    , num_sql
    , executions_th
    , parse_calls_th
    , disk_reads_th
    , buffer_gets_th
    , sharable_mem_th
    , version_count_th
    , all_init
    , pin_statspack
    into o_session_id
    , o_snap_level
    , o_ucomment
    , o_num_sql
    , o_executions_th
    , o_parse_calls_th
    , o_disk_reads_th
    , o_buffer_gets_th
    , o_sharable_mem_th
    , o_version_count_th
    , o_all_init
    , o_pin_statspack;
    if SQL%ROWCOUNT = 0 then
    insert into stats$statspack_parameter
    ( dbid
    , instance_number
    , session_id
    , snap_level
    , ucomment
    , num_sql
    , executions_th
    , parse_calls_th
    , disk_reads_th
    , buffer_gets_th
    , sharable_mem_th
    , version_count_th
    , all_init
    , pin_statspack
    , last_modified
    values
    ( l_dbid
    , l_instance_number
    , nvl(i_session_id, p_def_session_id)
    , nvl(i_snap_level, p_def_snap_level)
    , nvl(i_ucomment, p_def_ucomment)
    , nvl(i_num_sql, p_def_num_sql)
    , nvl(i_executions_th, p_def_executions_th)
    , nvl(i_parse_calls_th, p_def_parse_calls_th)
    , nvl(i_disk_reads_th, p_def_disk_reads_th)
    , nvl(i_buffer_gets_th, p_def_buffer_gets_th)
    , nvl(i_sharable_mem_th, p_def_sharable_mem_th)
    , nvl(i_version_count_th, p_def_version_count_th)
    , nvl(ui_all_init, p_def_all_init)
    , nvl(i_pin_statspack, p_def_pin_statspack)
    , SYSDATE
    returning session_id
    , snap_level
    , ucomment
    , num_sql
    , executions_th
    , parse_calls_th
    , disk_reads_th
    , buffer_gets_th
    , sharable_mem_th
    , version_count_th
    , all_init
    , pin_statspack
    into o_session_id
    , o_snap_level
    , o_ucomment
    , o_num_sql
    , o_executions_th
    , o_parse_calls_th
    , o_disk_reads_th
    , o_buffer_gets_th
    , o_sharable_mem_th
    , o_version_count_th
    , o_all_init
    , o_pin_statspack;
    end if;
    end; /* modify values */
    else
    /* error */
    raise_application_error
    (-20100,'QAM_STATSPACK_PARAMETER i_modify_parameter value is invalid');
    end if; /* modify */
    end QAM_STATSPACK_PARAMETER;
    procedure STAT_CHANGES
    /* Returns a set of differences of the values from corresponding pairs
    of rows in STATS$SYSSTAT, STATS$LIBRARYCACHE and STATS$WAITSTAT,
    based on the begin and end (bid, eid) snapshot id's specified.
    This procedure is the only call to STATSPACK made by the statsrep
    report.
    Modified to include multi-db support.
    ( bid IN number
    , eid IN number
    , db_ident IN number
    , inst_num IN number
    , parallel IN varchar2
    , lhtr OUT number, bfwt OUT number
    , tran OUT number, chng OUT number
    , ucal OUT number, urol OUT number
    , rsiz OUT number
    , phyr OUT number, phyrd OUT number
    , phyrdl OUT number
    , phyw OUT number, ucom OUT number
    , prse OUT number, hprse OUT number
    , recr OUT number, gets OUT number
    , rlsr OUT number, rent OUT number
    , srtm OUT number, srtd OUT number
    , srtr OUT number, strn OUT number
    , lhr OUT number, bc OUT varchar2
    , sp OUT varchar2, lb OUT varchar2
    , bs OUT varchar2, twt OUT number
    , logc OUT number, prscpu OUT number
    , tcpu OUT number, exe OUT number
    , prsela OUT number
    , bspm OUT number, espm OUT number
    , bfrm OUT number, efrm OUT number
    , blog OUT number, elog OUT number
    , bocur OUT number, eocur OUT number
    , dmsd OUT number, dmfc OUT number -- begin OPS
    , dfcms OUT number, dfcmr OUT number
    , dmsi OUT number, dmrv OUT number
    , dynal OUT number, dynares OUT number
    , pmrv OUT number, pmpt OUT number
    , npmrv OUT number, npmpt OUT number
    , scma OUT number, scml OUT number
    , pinc OUT number, picrnc OUT number
    , picc OUT number, picrcc OUT number
    , pbc OUT number, pbcrc OUT number
    , pcba OUT number, pccrba OUT number
    , pcrbpi OUT number
    , dynapres OUT number, dynapshl OUT number
    , prcma OUT number, prcml OUT number
    , pwrm OUT number, pfpim OUT number
    , pwnm OUT number
    , dpms OUT number, dnpms OUT number
    , glsg OUT number, glag OUT number
    , glgt OUT number, glsc OUT number
    , glac OUT number, glct OUT number
    , glrl OUT number
    , gcge OUT number, gcgt OUT number
    , gccv OUT number, gcct OUT number
    , gccrrv OUT number, gccrrt OUT number
    , gccurv OUT number, gccurt OUT number
    , gccrsv OUT number
    , gccrbt OUT number, gccrft OUT number
    , gccrst OUT number, gccusv OUT number
    , gccupt OUT number, gccuft OUT number
    , gccust OUT number -- end OPS
    ) is
    bval number;
    eval number;
    l_b_session_id number; /* begin session id */
    l_b_serial# number; /* begin serial# */
    l_e_session_id number; /* end session id */
    l_e_serial# number; /* end serial# */
    function LIBRARYCACHE_HITRATIO RETURN number is
    /* Returns Library cache hit ratio for the begin and end (bid, eid)
    snapshot id's specified
    cursor LH (i_snap_id number) is
    select sum(pins), sum(pinhits)
    from stats$librarycache
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num;
    bpsum number;
    bhsum number;
    epsum number;
    ehsum number;
    begin
    if not LH%ISOPEN then open LH (bid); end if;
    fetch LH into bpsum, bhsum;
    if LH%NOTFOUND then
    raise_application_error
    (-20100,'Missing start value for stats$librarycache');
    end if; close LH;
    if not LH%ISOPEN then open LH (eid); end if;
    fetch LH into epsum, ehsum;
    if LH%NOTFOUND then
    raise_application_error
    (-20100,'Missing end value for stats$librarycache');
    end if; close LH;
    return (ehsum - bhsum) / (epsum - bpsum);
    end LIBRARYCACHE_HITRATIO;
    function GET_PARAM (i_name varchar2) RETURN varchar2 is
    /* Returns the value for the init.ora parameter for the snapshot
    specified.
    cursor PARAMETER is
    select value
    from stats$parameter
    where snap_id = eid
    and dbid = db_ident
    and instance_number = inst_num
    and name = i_name;
    par_value varchar2(512);
    begin
    if not PARAMETER%ISOPEN then open PARAMETER; end if;
    fetch PARAMETER into par_value;
    if PARAMETER%NOTFOUND then
    raise_application_error
    (-20100,'Missing Init.ora parameter '|| i_name);
    end if; close PARAMETER;
    return par_value;
    end GET_PARAM;
    function GET_SYSSTAT (i_name varchar2, i_beid number) RETURN number is
    /* Returns the value for the System Statistic for the snapshot
    specified.
    cursor SYSSTAT is
    select value
    from stats$sysstat
    where snap_id = i_beid
    and dbid = db_ident
    and instance_number = inst_num
    and name = i_name;
    stat_value varchar2(512);
    begin
    if not SYSSTAT%ISOPEN then open SYSSTAT; end if;
    fetch SYSSTAT into stat_value;
    if SYSSTAT%NOTFOUND then
    raise_application_error
    (-20100,'Missing System Statistic '|| i_name);
    end if; close SYSSTAT;
    return stat_value;
    end GET_SYSSTAT;
    function BUFFER_WAITS RETURN number is
    /* Returns the total number of waits for all buffers in the interval
    specified by the begin and end snapshot id's (bid, eid)
    cursor BW (i_snap_id number) is
    select sum(wait_count)
    from stats$waitstat
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num;
    bbwsum number; ebwsum number;
    begin
    if not BW%ISOPEN then open BW (bid); end if;
    fetch BW into bbwsum;
    if BW%NOTFOUND then
    raise_application_error
    (-20100,'Missing start value for stats$waitstat');
    end if; close BW;
    if not BW%ISOPEN then open BW (eid); end if;
    fetch BW into ebwsum;
    if BW%NOTFOUND then
    raise_application_error
    (-20100,'Missing end value for stats$waitstat');
    end if; close BW;
    return ebwsum - bbwsum;
    end BUFFER_WAITS;
    function TOTAL_EVENT_TIME RETURN number is
    /* Returns the total amount of time waited for events for
    the interval specified by the begin and end snapshot id's
    (bid, eid) by foreground processes. This excludes idle
    wait events.
    cursor WAITS (i_snap_id number) is
    select sum(time_waited_micro)
    from stats$system_event
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num
    and event not in (select event from stats$idle_event);
    bwaittime number;
    ewaittime number;
    begin
    if not WAITS%ISOPEN then open WAITS (bid); end if;
    fetch WAITS into bwaittime;
    if WAITS%NOTFOUND then
    raise_application_error
    (-20100,'Missing start value for stats$system_event');
    end if; close WAITS;
    if not WAITS%ISOPEN then open WAITS (eid); end if;
    fetch WAITS into ewaittime;
    if WAITS%NOTFOUND then
    raise_application_error
    (-20100,'Missing end value for stats$system_event');
    end if; close WAITS;
    return ewaittime - bwaittime;
    end TOTAL_EVENT_TIME;
    function LATCH_HITRATIO return NUMBER is
    /* Returns the latch hit ratio specified by the begin and
    end snapshot id's (bid, eid)
    cursor GETS_MISSES (i_snap_id number) is
    select sum(gets), sum(misses)
    from stats$latch
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num;
    blget number; -- beginning latch gets
    blmis number; -- beginning latch misses
    elget number; -- end latch gets
    elmis number; -- end latch misses
    begin
    if not GETS_MISSES%ISOPEN then open GETS_MISSES (bid); end if;
    fetch GETS_MISSES into blget, blmis;
    if GETS_MISSES%NOTFOUND then
    raise_application_error
    (-20100,'Missing start value for STATS$LATCH gets and misses');
    end if; close GETS_MISSES;
    if not GETS_MISSES%ISOPEN then open GETS_MISSES (eid); end if;
    fetch GETS_MISSES into elget, elmis;
    if GETS_MISSES%NOTFOUND then
    raise_application_error
    (-20100,'Missing end value for STATS$LATCH gets and misses');
    end if; close GETS_MISSES;
    return ( ( elmis - blmis ) / ( elget - blget ) );
    end LATCH_HITRATIO;
    function SGASTAT (i_name varchar2, i_beid number) RETURN number is
    /* Returns the bytes used by i_name in the shared pool
    for the begin or end snapshot (bid, eid) specified
    cursor bytes_used is
    select bytes
    from stats$sgastat
    where snap_id = i_beid
    and dbid = db_ident
    and instance_number = inst_num
    and pool in ('shared pool', 'all pools')
    and name = i_name;
    total_bytes number;
    begin
    if i_name = 'total_shared_pool' then
    select sum(bytes)
    into total_bytes
    from stats$sgastat
    where snap_id = i_beid
    and dbid = db_ident
    and instance_number = inst_num
    and pool in ('shared pool','all pools');
    else
    open bytes_used; fetch bytes_used into total_bytes;
    if bytes_used%notfound then
    raise_application_error
    (-20100,'Missing value for SGASTAT: '||i_name);
    end if;
    close bytes_used;
    end if;
    return total_bytes;
    end SGASTAT;
    function SYSDIF (i_name varchar2) RETURN number is
    /* Returns the difference between statistics for the statistic
    name specified for the interval between the begin and end
    snapshot id's (bid, eid)
    cursor SY (i_snap_id number) is
    select value
    from stats$sysstat
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num
    and name = i_name;
    begin
    /* Get start value */
    open SY (bid); fetch SY into bval;
    if SY%notfound then
    raise_application_error
    (-20100,'Missing start value for statistic: '||i_name);
    end if; close SY;
    /* Get end value */
    open SY (eid); fetch SY into eval;
    if SY%notfound then
    raise_application_error
    (-20100,'Missing end value for statistic: '||i_name);
    end if; close SY;
    /* Return difference */
    return eval - bval;
    end SYSDIF;
    function SESDIF (st_name varchar2) RETURN number is
    /* Returns the difference between statistics values for the
    statistic name specified for the interval between the begin and end
    snapshot id's (bid, eid), for the session monitored for that
    snapshot
    cursor SE (i_snap_id number) is
    select ses.value
    from stats$sysstat sys
    , stats$sesstat ses
    where sys.snap_id = i_snap_id
    and ses.snap_id = i_snap_id
    and ses.dbid = db_ident
    and sys.dbid = db_ident
    and ses.instance_number = inst_num
    and sys.instance_number = inst_num
    and ses.statistic# = sys.statistic#
    and sys.name = st_name;
    begin
    /* Get start value */
    open SE (bid); fetch SE into bval;
    if SE%notfound then
    eval :=0;
    end if; close SE;
    /* Get end value */
    open SE (eid); fetch SE into eval;
    if SE%notfound then
    eval :=0;
    end if; close SE;
    /* Return difference */
    return eval - bval;
    end SESDIF;
    function DLMDIF (i_name varchar2) RETURN number is
    /* Returns the difference between statistics for the statistic
    name specified for the interval between the begin and end
    snapshot id's (bid, eid)
    cursor DLM (i_snap_id number) is
    select value
    from stats$dlm_misc
    where snap_id = i_snap_id
    and dbid = db_ident
    and instance_number = inst_num
    and name = i_name;
    begin
    /* Get start value */
    open DLM (bid); fetch DLM into bval;
    if DLM%notfound then
    raise_application_error
    (-20100,'Missing start value for statistic: '||i_name);
    end if; close DLM;
    /* Get end value */
    open DLM (eid); fetch DLM into eval;
    if DLM%notfound then
    raise_application_error
    (-20100,'Missing end value for statistic: '||i_name);
    end if; close DLM;
    /* Return difference */
    return eval - bval;
    end DLMDIF;
    begin /* main procedure body of STAT_CHANGES */
    lhtr := LIBRARYCACHE_HITRATIO;
    bfwt := BUFFER_WAITS;
    lhr := LATCH_HITRATIO;
    chng := SYSDIF('db block changes');
    ucal := SYSDIF('user calls');
    urol := SYSDIF('user rollbacks');
    ucom := SYSDIF('user commits');
    tran := ucom + urol;
    rsiz := SYSDIF('redo size');
    phyr := SYSDIF('physical reads');
    phyrd := SYSDIF('physical reads direct');
    phyrdl := SYSDIF('physical reads direct (lob)');
    phyw := SYSDIF('physical writes');
    hprse := SYSDIF('parse count (hard)');
    prse := SYSDIF('parse count (total)');
    gets := SYSDIF('session logical reads');
    recr := SYSDIF('recursive calls');
    rlsr := SYSDIF('redo log space requests');
    rent := SYSDIF('redo entries');
    srtm := SYSDIF('sorts (memory)');
    srtd := SYSDIF('sorts (disk)');
    srtr := SYSDIF('sorts (rows)');
    logc := SYSDIF('logons cumulative');
    prscpu := SYSDIF('parse time cpu');
    prsela := SYSDIF('parse time elapsed');
    tcpu := SYSDIF('CPU used by this session');
    exe := SYSDIF('execute count');
    bs := GET_PARAM('db_block_size');
    bc := GET_PARAM('db_block_buffers') * bs;
    if bc = 0 then
    bc := GET_PARAM('db_cache_size')
    + GET_PARAM('db_keep_cache_size')
    + GET_PARAM('db_recycle_cache_size')
    + GET_PARAM('db_2k_cache_size')
    + GET_PARAM('db_4k_cache_size')
    + GET_PARAM('db_8k_cache_size')
    + GET_PARAM('db_16k_cache_size')
    + GET_PARAM('db_32k_cache_size');
    end if;
    sp := GET_PARAM('shared_pool_size');
    lb := GET_PARAM('log_buffer');
    twt := TOTAL_EVENT_TIME; -- total wait time for all non-idle events
    bspm := SGASTAT('total_shared_pool', bid);
    espm := SGASTAT('total_shared_pool', eid);
    bfrm := SGASTAT('free memory', bid);
    efrm := SGASTAT('free memory', eid);
    blog := GET_SYSSTAT('logons current', bid);
    elog := GET_SYSSTAT('logons current', eid);
    bocur := GET_SYSSTAT('opened cursors current', bid);
    eocur := GET_SYSSTAT('opened cursors current', eid);
    /* Do we want to report on cluster-specific statistics? Check
    in procedure variable "parallel".
    if parallel = 'YES' then
    dmsd := DLMDIF('messages sent directly');
    dmfc := DLMDIF('messages flow controlled');
    dmsi := DLMDIF('messages sent indirectly');
    dmrv := DLMDIF('messages received');
    dfcms := DLMDIF('flow control messages sent');
    dfcmr := DLMDIF('flow control messages received');
    dynal := DLMDIF('dynamically allocated enqueues');
    dynares := DLMDIF('dynamically allocated resources');
    pmrv := DLMDIF('gcs msgs received');
    pmpt := DLMDIF('gcs msgs process time(ms)');
    npmrv := DLMDIF('ges msgs received');
    npmpt := DLMDIF('ges msgs process time(ms)');
    scma := DLMDIF('gcs side channel msgs actual');
    scml := DLMDIF('gcs side channel msgs logical');
    pinc := DLMDIF('gcs immediate (null) converts');
    picrnc := DLMDIF('gcs immediate cr (null) converts');
    picc := DLMDIF('gcs immediate (compatible) converts');
    picrcc := DLMDIF('gcs immediate cr (compatible) converts');
    pbc := DLMDIF('gcs blocked converts');
    pbcrc := DLMDIF('gcs blocked cr converts');
    pcba := DLMDIF('gcs compatible basts');
    pccrba := DLMDIF('gcs compatible cr basts');
    pcrbpi := DLMDIF('gcs cr basts to PIs');
    dynapres := DLMDIF('dynamically allocated gcs resources');
    dynapshl := DLMDIF('dynamically allocated gcs shadows');
    prcma := DLMDIF('gcs recovery claim msgs actual');
    prcml := DLMDIF('gcs recovery claim msgs logical');
    pwrm := DLMDIF('gcs write request msgs');
    pfpim := DLMDIF('gcs flush pi msgs');
    pwnm := DLMDIF('gcs write notification msgs');
    dpms := SYSDIF('gcs messages sent');
    dnpms := SYSDIF('ges messages sent');
    glsg := SYSDIF('global lock sync gets');
    glag := SYSDIF('global lock async gets');
    glgt := SYSDIF('global lock get time');
    glsc := SYSDIF('global lock sync converts');
    glac := SYSDIF('global lock async converts');
    glct := SYSDIF('global lock convert time');
    glrl := SYSDIF('global lock releases');
    gcge := SYSDIF('global cache gets');
    gcgt := SYSDIF('global cache get time');
    gccv := SYSDIF('global cache converts');
    gcct := SYSDIF('global cache convert time');
    gccrrv := SYSDIF('global cache cr blocks received');
    gccrrt := SYSDIF('global cache cr block receive time');
    gccurv := SYSDIF('global cache current blocks received');
    gccurt := SYSDIF('global cache current block receive time');
    gccrsv := SYSDIF('global cache cr blocks served');
    gccrbt := SYSDIF('global cache cr block build time');
    gccrft := SYSDIF('global cache cr block flush time');
    gccrst := SYSDIF('global cache cr block send time');
    gccusv := SYSDIF('global cache current blocks served');
    gccupt := SYSDIF('global cache current block pin time');
    gccuft := SYSDIF('global cache current block flush time');
    gccust := SYSDIF('global cache current block send time');
    end if;
    /* Determine if we want to report on session-specific statistics.
    Check that the session is the same one for both snapshots.
    select session_id
    , serial#
    into l_b_session_id
    , l_b_serial#
    from stats$snapshot
    where snap_id = bid
    and dbid = db_ident
    and instance_number = inst_num;
    select session_id
    , serial#
    into l_e_session_id
    , l_e_serial#
    from stats$snapshot
    where snap_id = eid
    and dbid = db_ident
    and instance_number = inst_num;
    if ( (l_b_session_id = l_e_session_id)
    and (l_b_serial# = l_e_serial#)
    and (l_b_session_id != 0) ) then
    /* we have a valid comparison - it is the
    same session - get number of tx performed
    by this session */
    strn := SESDIF('user rollbacks') + SESDIF('user commits');
    if strn = 0 then
    /* No new transactions */
    strn := 1;
    end if;
    else
    /* No valid comparison can be made */
    strn :=1;
    end if;
    end STAT_CHANGES;
    function SNAP
    (i_snap_level in number default null
    ,i_session_id in number default null
    ,i_ucomment in varchar2 default null
    ,i_num_sql in number default null
    ,i_executions_th in number default null
    ,i_parse_calls_th in number default null
    ,i_disk_reads_th in number default null
    ,i_buffer_gets_th in number default null
    ,i_sharable_mem_th in number default null
    ,i_version_count_th in number default null
    ,i_all_init in varchar2 default null
    ,i_pin_statspack in varchar2 default null
    ,i_modify_parameter in varchar2 default 'FALSE'
    RETURN integer IS
    /* This function performs a snapshot of the v$ views into the
    stats$ tables, and returns the snapshot id.
    If parameters are passed, these are the values used, otherwise
    the values stored in the stats$statspack_parameter table are used.
    l_snap_id integer;
    l_snap_level number;
    l_session_id number;
    l_serial# number;
    l_ucomment varchar2(160);
    l_num_sql number;
    l_executions_th number;
    l_parse_calls_th number;
    l_disk_reads_th number;
    l_buffer_gets_th number;
    l_sharable_mem_th number;
    l_version_count_th number;
    l_all_init varchar2(5);
    l_pin_statspack varchar2(10);
    l_sql_stmt varchar2(3000);
    l_slarti varchar2(20);
    l_threshold number;
    l_total_sql number := 0;
    l_total_sql_mem number := 0;
    l_single_use_sql number := 0;
    l_single_use_sql_mem number := 0;
    l_text_subset varchar2(31);
    l_sharable_mem number;
    l_version_count number;
    l_sorts number;
    l_module varchar2(64);
    l_loaded_versions number;
    l_executions number;
    l_loads number;
    l_invalidations number;
    l_parse_calls number;
    l_disk_reads number;
    l_buffer_gets number;
    l_rows_processed number;
    l_address raw(8);
    l_hash_value number;
    l_version_count number;
    l_max_begin_time date;
    cursor GETSERIAL is
    select serial#
    from v$session
    where sid = l_session_id;
    PROCEDURE snap_sql IS
    begin
    /* Gather summary statistics */
    insert into stats$sql_statistics
    ( snap_id
    , dbid
    , instance_number
    , total_sql
    , total_sql_mem
    , single_use_sql
    , single_use_sql_mem
    select l_snap_id
    , p_dbid
    , p_instance_number
    , count(1)
    , sum(sharable_mem)
    , sum(decode(executions, 1, 1, 0))
    , sum(decode(executions, 1, sharable_mem, 0))
    from stats$v$sqlxs
    where is_obsolete = 'N';
    /* Gather SQL statements which exceed any threshold,
    excluding obsolete parent cursors
    insert into stats$sql_summary
    ( snap_id
    , dbid
    , instance_number
    , text_subset
    , sharable_mem
    , sorts
    , module
    , loaded_versions
    , executions
    , loads
    , invalidations
    , parse_calls
    , disk_reads
    , buffer_gets
    , rows_processed
    , command_type
    , address
    , hash_value
    , version_count
    , cpu_time
    , elapsed_time
    , outline_sid
    , outline_category
    select l_snap_id
    , p_dbid
    , p_instance_number
    , substr(sql_text,1,31)
    , sharable_mem
    , sorts
    , module
    , loaded_versions
    , executions
    , loads
    , invalidations
    , parse_calls
    , disk_reads
    , buffer_gets
    , rows_processed
    , command_type
    , address
    , hash_value
    , version_count
    , cpu_time
    , elapsed_time
    , outline_sid
    , outline_category
    from stats$v$sqlxs
    where is_obsolete = 'N'
    and ( buffer_gets > l_buffer_gets_th
    or disk_reads > l_disk_reads_th
    or parse_calls > l_parse_calls_th
    or executions > l_executions_th
    or sharable_mem > l_sharable_mem_th
    or version_count > l_version_count_th
    /* Insert the SQL Text for hash_values captured in the snapshot
    into stats$sqltext if it's not already there. Identify SQL which
    execeeded the threshold by querying stats$sql_summary for this
    snapid and database instance
    insert into stats$sqltext
    ( hash_value
    , text_subset
    , piece
    , sql_text
    , address
    , command_type
    , last_snap_id
    select st1.hash_value
    , ss.text_subset
    , st1.piece
    , st1.sql_text
    , st1.address
    , st1.command_type
    , ss.snap_id
    from v$sqltext st1
    , stats$sql_summary ss
    where ss.snap_id = l_snap_id
    and ss.dbid = p_dbid
    and ss.instance_number = p_instance_number
    and st1.hash_value = ss.hash_value
    and st1.address = ss.address
    and not exists (select 1
    from stats$sqltext st2
    where st2.hash_value = ss.hash_value
    and st2.text_subset = ss.text_subset
    IF l_snap_level >= 6 THEN
    /* Identify SQL which execeeded the threshold by querying
    stats$sql_summary for this snapid and database instance.
    Capture the plans which were used for the high-load SQL if
    don't already have this data.
    Omit capturing plan usage information for cursors which
    have a zero plan hash value.
    Currently this is captured in a level 6 (or greater)
    snapshot, however this may be integrated into level 5
    snapshot at a later date.
    hl - high load
    insert into stats$sql_plan_usage
    ( hash_value
    , text_subset
    , plan_hash_value
    , cost
    , snap_id
    , address
    , optimizer
    select hl.hash_value
    , hl.text_subset
    , hl.plan_hash_value
    , hl.cost
    , max(hl.snap_id)
    , max(hl.address)
    , max(hl.optimizer)
    from (select /*+ ordered use_nl(sq) index(sq) */
    ss.hash_value
    , ss.text_subset
    , sq.plan_hash_value
    , nvl(sq.optimizer_cost,-9) cost
    , ss.snap_id snap_id
    , ss.address
    , sq.optimizer_mode optimizer
    from stats$sql_summary ss
    , v$sql sq
    where ss.snap_id = l_snap_id
    and ss.dbid = p_dbid
    and ss.instance_number = p_instance_number
    and sq.hash_value = ss.hash_value
    and sq.address = ss.address
    and sq.plan_hash_value > 0
    ) hl
    where not exists (select /*+ no_unnest */
    from stats$sql_plan_usage spu
    where spu.hash_value = hl.hash_value
    and spu.text_subset = hl.text_subset
    and spu.plan_hash_value
    = hl.plan_hash_value
    and spu.cost = hl.cost
    group by hl.hash_value
    , hl.text_subset
    , hl.plan_hash_value
    , hl.cost
    , hl.optimizer;
    /* For all new hash_value, plan_hash_value, cost combinations
    just captured, get the optimizer plans, if we don't already
    have them. Note that the plan (and hence the plan hash value)
    comprises the access path and the join order (and not
    variable factors such as the cardinality).
    insert into stats$sql_plan
    ( plan_hash_value
    , id
    , operation
    , options
    , object_node
    , object#
    , object_owner
    , object_name
    , optimizer
    , parent_id
    , depth
    , position
    , cost
    , cardinality
    , bytes
    , other_tag
    , partition_start
    , partition_stop
    , partition_id
    , other
    , distribution
    , cpu_cost
    , io_cost
    , temp_space
    , snap_id
    select /*+ ordered use_nl(s) use_nl(sp.p) */
    new_plan.plan_hash_value
    , sp.id
    , max(sp.operation)
    , max(sp.options)
    , max(sp.object_node)
    , max(sp.object#)
    , max(sp.object_owner)
    , max(sp.object_name)
    , max(sp.optimizer)
    , max(sp.parent_id)
    , max(sp.depth)
    , max(sp.position)
    , max(sp.cost)
    , max(sp.cardinality)
    , max(sp.bytes)
    , max(sp.other_tag)
    , max(sp.partition_start)
    , max(sp.partition_stop)
    , max(sp.partition_id)
    , max(sp.other)
    , max(sp.distribution)
    , max(sp.cpu_cost)
    , max(sp.io_cost)
    , max(sp.temp_space)
    , max(new_plan.snap_id)
    from (select /*+ index(spu) */
    distinct
    spu.plan_hash_value
    , spu.hash_value
    , spu.address
    , spu.text_subset
    , spu.snap_id
    from stats$sql_plan_usage spu
    where spu.snap_id = l_snap_id
    and not exists (select /*+ nl_aj */ *
    from stats$sql_plan ssp
    where ssp.plan_hash_value
    = spu.plan_hash_value
    ) new_plan
    , v$sql s
    , v$sql_plan sp
    where sp.hash_value = new_plan.hash_value
    and sp.address = new_plan.address
    and s.hash_value = new_plan.hash_value
    and s.address = new_plan.address
    and s.hash_value = sp.hash_value
    and s.address = sp.address
    and s.child_number = sp.child_number
    group by
    new_plan.plan_hash_value
    , sp.id;
    END IF; /* snap level >=6 */
    END snap_sql;
    begin /* Function SNAP */
    /* Get instance parameter defaults from stats$statspack_parameter,
    or use supplied parameters.
    If all parameters are specified, use them, otherwise get values
    from the parameters not specified from stats$statspack_parameter.
    statspack.qam_statspack_parameter
    ( p_dbid
    , p_instance_number
    , i_snap_level, i_session_id, i_ucomment, i_num_sql
    , i_executions_th, i_parse_calls_th
    , i_disk_reads_th, i_buffer_gets_th, i_sharable_mem_th
    , i_version_count_th, i_all_init
    , i_pin_statspack
    , i_modify_parameter
    , l_snap_level, l_session_id, l_ucomment, l_num_sql
    , l_executions_th, l_parse_calls_th
    , l_disk_reads_th, l_buffer_gets_th, l_sharable_mem_th
    , l_version_count_th, l_all_init
    , l_pin_statspack);
    /* Generate a snapshot id */
    select stats$snapshot_id.nextval
    into l_snap_id
    from dual
    where rownum = 1;
    /* Determine the serial# of the session to maintain stats for,
    if this was requested.
    if l_session_id > 0 then
    if not GETSERIAL%ISOPEN then open GETSERIAL; end if;
    fetch GETSERIAL into l_serial#;
    if GETSERIAL%NOTFOUND then
    /* Session has already disappeared - don't gather
    statistics for this session in this snapshot */
    l_session_id := 0;
    l_serial# := 0;
    end if; close GETSERIAL;
    else
    l_serial# := 0;
    end if;
    /* The instance has been restarted since the last snapshot */
    if p_new_sga = 0
    then
    begin
    p_new_sga := 1;
    /* Get the instance startup time, and other characteristics */
    insert into stats$database_instance
    ( dbid
    , instance_number
    , startup_time
    , snap_id
    , parallel
    , version
    , db_name
    , instance_name
    , host_name
    select p_dbid
    , p_instance_number
    , p_startup_time
    , l_snap_id
    , p_parallel
    , p_version
    , p_name
    , p_instance_name
    , p_host_name
    from sys.dual;
    commit;
    end;
    end if; /* new SGA */
    /* Work out the max undo stat time, used for gathering undo stat data */
    select nvl(max(begin_time), to_date('01011900','DDMMYYYY'))
    into l_max_begin_time
    from stats$undostat
    where dbid = p_dbid
    and instance_number = p_instance_number;
    /* Save the snapshot characteristics */
    insert into stats$snapshot
    ( snap_id, dbid, instance_number
    , snap_time, startup_time
    , session_id, snap_level, ucomment
    , executions_th, parse_calls_th, disk_reads_th
    , buffer_gets_th, sharable_mem_th
    , version_count_th, serial#, all_init)
    values
    ( l_snap_id, p_dbid, p_instance_number
    , SYSDATE, p_startup_time
    , l_session_id, l_snap_level, l_ucomment
    , l_executions_th, l_parse_calls_th, l_disk_reads_th
    , l_buffer_gets_th, l_sharable_mem_th
    , l_version_count_th, l_serial#, l_all_init);
    /* Begin gathering statistics */
    insert into stats$filestatxs
    ( snap_id
    , dbid
    , instance_number
    , tsname
    , filename
    , phyrds
    , phywrts
    , singleblkrds
    , readtim
    , writetim
    , singleblkrdtim
    , phyblkrd
    , phyblkwrt
    , wait_count
    , time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , tsname
    , filename
    , phyrds
    , phywrts
    , singleblkrds
    , readtim
    , writetim
    , singleblkrdtim
    , phyblkrd
    , phyblkwrt
    , wait_count
    , time
    from stats$v$filestatxs;
    insert into stats$tempstatxs
    ( snap_id
    , dbid
    , instance_number
    , tsname
    , filename
    , phyrds
    , phywrts
    , singleblkrds
    , readtim
    , writetim
    , singleblkrdtim
    , phyblkrd
    , phyblkwrt
    , wait_count
    , time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , tsname
    , filename
    , phyrds
    , phywrts
    , singleblkrds
    , readtim
    , writetim
    , singleblkrdtim
    , phyblkrd
    , phyblkwrt
    , wait_count
    , time
    from stats$v$tempstatxs;
    insert into stats$librarycache
    ( snap_id
    , dbid
    , instance_number
    , namespace
    , gets
    , gethits
    , pins
    , pinhits
    , reloads
    , invalidations
    , dlm_lock_requests
    , dlm_pin_requests
    , dlm_pin_releases
    , dlm_invalidation_requests
    , dlm_invalidations
    select l_snap_id
    , p_dbid
    , p_instance_number
    , namespace
    , gets
    , gethits
    , pins
    , pinhits
    , reloads
    , invalidations
    , dlm_lock_requests
    , dlm_pin_requests
    , dlm_pin_releases
    , dlm_invalidation_requests
    , dlm_invalidations
    from v$librarycache;
    insert into stats$buffer_pool_statistics
    ( snap_id
    , dbid
    , instance_number
    , id
    , name
    , block_size
    , set_msize
    , cnum_repl
    , cnum_write
    , cnum_set
    , buf_got
    , sum_write
    , sum_scan
    , free_buffer_wait
    , write_complete_wait
    , buffer_busy_wait
    , free_buffer_inspected
    , dirty_buffers_inspected
    , db_block_change
    , db_block_gets
    , consistent_gets
    , physical_reads
    , physical_writes
    select l_snap_id
    , p_dbid
    , p_instance_number
    , id
    , name
    , block_size
    , set_msize
    , cnum_repl
    , cnum_write
    , cnum_set
    , buf_got
    , sum_write
    , sum_scan
    , free_buffer_wait
    , write_complete_wait
    , buffer_busy_wait
    , free_buffer_inspected
    , dirty_buffers_inspected
    , db_block_change
    , db_block_gets
    , consistent_gets
    , physical_reads
    , physical_writes
    from v$buffer_pool_statistics;
    insert into stats$rollstat
    ( snap_id
    , dbid
    , instance_number
    , usn
    , extents
    , rssize
    , writes
    , xacts
    , gets
    , waits
    , optsize
    , hwmsize
    , shrinks
    , wraps
    , extends
    , aveshrink
    , aveactive
    select l_snap_id
    , p_dbid
    , p_instance_number
    , usn
    , extents
    , rssize
    , writes
    , xacts
    , gets
    , waits
    , optsize
    , hwmsize
    , shrinks
    , wraps
    , extends
    , aveshrink
    , aveactive
    from v$rollstat;
    insert into stats$rowcache_summary
    ( snap_id
    , dbid
    , instance_number
    , parameter
    , total_usage
    , usage
    , gets
    , getmisses
    , scans
    , scanmisses
    , scancompletes
    , modifications
    , flushes
    , dlm_requests
    , dlm_conflicts
    , dlm_releases
    select l_snap_id
    , p_dbid
    , p_instance_number
    , parameter
    , sum("COUNT")
    , sum(usage)
    , sum(gets)
    , sum(getmisses)
    , sum(scans)
    , sum(scanmisses)
    , sum(scancompletes)
    , sum(modifications)
    , sum(flushes)
    , sum(dlm_requests)
    , sum(dlm_conflicts)
    , sum(dlm_releases)
    from v$rowcache
    group by l_snap_id, p_dbid, p_instance_number, parameter;
    /* Collect parameters every snapshot, to cater for dynamic
    parameters changable while instance is running
    if l_all_init = 'FALSE' then
    insert into stats$parameter
    ( snap_id
    , dbid
    , instance_number
    , name
    , value
    , isdefault
    , ismodified
    select l_snap_id
    , p_dbid
    , p_instance_number
    , name
    , value
    , isdefault
    , ismodified
    from v$system_parameter;
    else
    insert into stats$parameter
    ( snap_id
    , dbid
    , instance_number
    , name
    , value
    , isdefault
    , ismodified
    select l_snap_id
    , p_dbid
    , p_instance_number
    , i.ksppinm
    , sv.ksppstvl
    , sv.ksppstdf
    , decode(bitand(sv.ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE')
    from stats$x$ksppi i
    , stats$x$ksppsv sv
    where i.indx = sv.indx;
    end if;
    /* To cater for variable size SGA - insert on each snapshot */
    insert into stats$sga
    ( snap_id
    , dbid
    , instance_number
    , name
    , value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , name
    , value
    from v$sga;
    /* Get current allocation of memory in the SGA */
    insert into stats$sgastat
    ( snap_id
    , dbid
    , instance_number
    , pool
    , name
    , bytes
    select l_snap_id
    , p_dbid
    , p_instance_number
    , pool
    , name
    , bytes
    from v$sgastat;
    insert into stats$system_event
    ( snap_id
    , dbid
    , instance_number
    , event
    , total_waits
    , total_timeouts
    , time_waited_micro
    select l_snap_id
    , p_dbid
    , p_instance_number
    , event
    , total_waits
    , total_timeouts
    , time_waited_micro
    from v$system_event;
    insert into stats$bg_event_summary
    ( snap_id
    , dbid
    , instance_number
    , event
    , total_waits
    , total_timeouts
    , time_waited_micro
    select l_snap_id
    , p_dbid
    , p_instance_number
    , e.event
    , sum(e.total_waits)
    , sum(e.total_timeouts)
    , sum(e.time_waited_micro)
    from v$session_event e
    where e.sid in (select s.sid from v$session s where s.type = 'BACKGROUND')
    group by l_snap_id, p_dbid, p_instance_number, e.event;
    insert into stats$sysstat
    ( snap_id
    , dbid
    , instance_number
    , statistic#
    , name
    , value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , statistic#
    , name
    , value
    from v$sysstat;
    insert into stats$waitstat
    ( snap_id
    , dbid
    , instance_number
    , class
    , wait_count
    , time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , class
    , "COUNT"
    , time
    from v$waitstat;
    insert into stats$enqueue_stat
    ( snap_id
    , dbid
    , instance_number
    , eq_type
    , total_req#
    , total_wait#
    , succ_req#
    , failed_req#
    , cum_wait_time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , eq_type
    , total_req#
    , total_wait#
    , succ_req#
    , failed_req#
    , cum_wait_time
    from v$enqueue_stat
    where total_req# != 0;
    insert into stats$latch
    ( snap_id
    , dbid
    , instance_number
    , name
    , latch#
    , level#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , name
    , latch#
    , level#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    from v$latch;
    insert into stats$latch_misses_summary
    ( snap_id
    , dbid
    , instance_number
    , parent_name
    , where_in_code
    , nwfail_count
    , sleep_count
    , wtr_slp_count
    select l_snap_id
    , p_dbid
    , p_instance_number
    , parent_name
    , "WHERE"
    , sum(nwfail_count)
    , sum(sleep_count)
    , sum(wtr_slp_count)
    from v$latch_misses
    where sleep_count > 0
    group by l_snap_id, p_dbid, p_instance_number
    , parent_name, "WHERE";
    insert into stats$resource_limit
    ( snap_id
    , dbid
    , instance_number
    , resource_name
    , current_utilization
    , max_utilization
    , initial_allocation
    , limit_value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , resource_name
    , current_utilization
    , max_utilization
    , initial_allocation
    , limit_value
    from v$resource_limit
    where limit_value != ' UNLIMITED'
    and max_utilization > 0;
    insert into stats$undostat
    ( begin_time
    , end_time
    , dbid
    , instance_number
    , snap_id
    , undotsn
    , undoblks
    , txncount
    , maxquerylen
    , maxconcurrency
    , unxpstealcnt
    , unxpblkrelcnt
    , unxpblkreucnt
    , expstealcnt
    , expblkrelcnt
    , expblkreucnt
    , ssolderrcnt
    , nospaceerrcnt
    select begin_time
    , end_time
    , p_dbid
    , p_instance_number
    , l_snap_id
    , undotsn
    , undoblks
    , txncount
    , maxquerylen
    , maxconcurrency
    , unxpstealcnt
    , unxpblkrelcnt
    , unxpblkreucnt
    , expstealcnt
    , expblkrelcnt
    , expblkreucnt
    , ssolderrcnt
    , nospaceerrcnt
    from v$undostat
    where begin_time > l_max_begin_time
    and begin_time + (1/(24*6)) <= end_time;
    insert into stats$db_cache_advice
    ( snap_id
    , dbid
    , instance_number
    , id
    , name
    , block_size
    , buffers_for_estimate
    , advice_status
    , size_for_estimate
    , estd_physical_read_factor
    , estd_physical_reads
    select l_snap_id
    , p_dbid
    , p_instance_number
    , id
    , name
    , block_size
    , buffers_for_estimate
    , advice_status
    , size_for_estimate
    , estd_physical_read_factor
    , estd_physical_reads
    from v$db_cache_advice
    where advice_status = 'ON';
    insert into stats$pgastat
    ( snap_id
    , dbid
    , instance_number
    , name
    , value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , name
    , value
    from v$pgastat;
    insert into stats$instance_recovery
    ( snap_id
    , dbid
    , instance_number
    , recovery_estimated_ios
    , actual_redo_blks
    , target_redo_blks
    , log_file_size_redo_blks
    , log_chkpt_timeout_redo_blks
    , log_chkpt_interval_redo_blks
    , fast_start_io_target_redo_blks
    , target_mttr
    , estimated_mttr
    , ckpt_block_writes
    select l_snap_id
    , p_dbid
    , p_instance_number
    , recovery_estimated_ios
    , actual_redo_blks
    , target_redo_blks
    , log_file_size_redo_blks
    , log_chkpt_timeout_redo_blks
    , log_chkpt_interval_redo_blks
    , fast_start_io_target_redo_blks
    , target_mttr
    , estimated_mttr
    , ckpt_block_writes
    from v$instance_recovery;
    if p_parallel = 'YES' then
    insert into stats$dlm_misc
    ( snap_id
    , dbid
    , instance_number
    , statistic#
    , name
    , value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , statistic#
    , name
    , value
    from v$dlm_misc;
    end if; /* parallel */
    /* Begin gathering Extended Statistics */
    IF l_snap_level >= 5 THEN
    snap_sql;
    END IF; /* snap level >=5 */
    IF l_snap_level >= 10 THEN
    insert into stats$latch_children
    ( snap_id
    , dbid
    , instance_number
    , latch#
    , child#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , latch#
    , child#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    from v$latch_children;
    insert into stats$latch_parent
    ( snap_id
    , dbid
    , instance_number
    , latch#
    , level#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    select l_snap_id
    , p_dbid
    , p_instance_number
    , latch#
    , level#
    , gets
    , misses
    , sleeps
    , immediate_gets
    , immediate_misses
    , spin_gets
    , sleep1
    , sleep2
    , sleep3
    , sleep4
    , wait_time
    from v$latch_parent;
    END IF; /* snap level >=10 */
    /* Record level session-granular statistics if a specific session
    has been requested
    if l_session_id > 0
    then
    insert into stats$sesstat
    ( snap_id
    , dbid
    , instance_number
    , statistic#
    , value
    select l_snap_id
    , p_dbid
    , p_instance_number
    , statistic#
    , value
    from v$sesstat
    where sid = l_session_id;
    insert into stats$session_event
    ( snap_id
    , dbid
    , instance_number
    , event
    , total_waits
    , total_timeouts
    , time_waited_micro
    , max_wait
    select l_snap_id
    , p_dbid
    , p_instance_number
    , event
    , total_waits
    , total_timeouts
    , time_waited_micro
    , max_wait
    from v$session_event
    where sid = l_session_id;
    end if;
    commit work;
    RETURN l_snap_id;
    end SNAP; /* Function SNAP */
    begin /* STATSPACK body */
    /* Query the database id, instance_number, database name, instance
    name and startup time for the instance we are working on
    /* Get information about the current instance */
    open get_instance;
    fetch get_instance into
    p_instance_number, p_instance_name
    , p_startup_time, p_parallel, p_version
    , p_host_name;
    close get_instance;
    /* Select the database info for the db connected to */
    open get_db;
    fetch get_db into p_dbid, p_name;
    close get_db;
    /* Keep the package
    sys.dbms_shared_pool.keep('PERFSTAT.STATSPACK', 'P');
    /* Determine if the instance has been restarted since the previous snapshot
    begin
    select 1
    into p_new_sga
    from stats$database_instance
    where startup_time = p_startup_time
    and dbid = p_dbid
    and instance_number = p_instance_number;
    exception
    when NO_DATA_FOUND then
    p_new_sga := 0;
    end;
    end STATSPACK;
    Warning: Package Body created with compilation errors.
    SQL> show error
    Errors for PACKAGE BODY STATSPACK:
    LINE/COL ERROR
    2045/3 PLS-00201: identifier 'SYS.DBMS_SHARED_POOL' must be declared
    2045/3 PL/SQL: Statement ignored

    When i compiled the package, it compiled with following error.
    Warning: Package Body created with compilation errors.
    SQL> show error
    Errors for PACKAGE BODY STATSPACK:
    LINE/COL ERROR
    2045/3 PLS-00201: identifier 'SYS.DBMS_SHARED_POOL' must be declared
    2045/3 PL/SQL: Statement ignored
    SQL>

Maybe you are looking for