practice4-Sizing the Buffer cache
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2003-08-12 16:22:46
 

1.perfstat/perfstat·Î loginÇÏ°í snap.sqlÀ» ½ÇÇàÇÏ¿© snapshot id¸¦ È®ÀÎÇØ µÐ´Ù.

$sqlplus 'sys/oracle as sysdba'
SQL> startup
SQL>exit

$sqlplus /nolog
SQL> @$HOME/LABS/ptw9i/snap.sql
SQL> exit

2. hr/hr·Î loginÇÏ¿© database buffer cache¿¡ ´ëÇÑ userÀÇ ÀÛ¾÷À» simulate ÇÑ´Ù.

$ sqlplus hr/hr
SQL> !more $HOME/LABS/ptw9i/lab04_02.sql
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;
commit;
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;
commit;               
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;
commit;               
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;     
commit;
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;     
commit;
insert into hr.employees
  (employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
  salary, commission_pct, manager_id, department_id)
    select (employees_seq.nextval), first_name, last_name,
            to_char((employees_seq.nextval)), phone_number,
            hire_date, job_id, salary, commission_pct, manager_id,
            department_id
    from hr.employees
    where rownum < 5;     
commit;

SQL> @$HOME/LABS/ptw9i/lab04_02.sql

SQL> exit
$ sqlplus system/manager

SQL> select 1 - (phy.value - lob.value - dir.value) / ses.value "Cache Hit Ratio"
  2  from  v$sysstat ses,v$sysstat lob,v$sysstat dir, v$sysstat phy
  3  where ses.name='session logical reads'
  4  and dir.name='physical reads direct'
  5  and lob.name=
  6  'physical reads direct (lob)'
  7  and phy.name='physical reads';

Cache Hit Ratio
---------------
      .94251138

Cache Hit Ratio´Â 90%ÀÌ»ó À̾î¾ß ÇÑ´Ù.

4. perfstat/perfstat·Î loginÇÑ ÈÄ ÀÌÀü snapshot°ú Áö±ÝÀÇ snapshots»çÀÌÀÇ Åë°è¸¦ È®ÀÎÇÑ´Ù.

$ sqlplus /nolog
SQL>@$HOME/LABS/snap.sql
SQL>@$HOME/LABS/spreport.sql
Enter value for begin_snap: ??
Enter value for end_snap: ??
Enter value for report_name:

SQL> exit

$vi sp_??_??.lst
Instance Efficiency Percentages (Target 100%)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Buffer Nowait %:  100.00      Redo NoWait %:  100.00
  **--> Buffer  Hit  %:  97.19    In-memory Sort %:  100.00
            Library Hit  %:  91.63        Soft Parse %:  95.37
        Execute to Parse %:  55.48        Latch Hit %:  100.00
Parse CPU to Parse Elapsd %:  88.24    % Non-Parse CPU:  99.91

<-- Production DB¿¡¼­ ¸¸ÀÏ HitÀ²ÀÌ ³ª»Ú´Ù¸é »õ·Î¿î buffer¸¦ Ãß°¡ÇÏ°í ¾ÕÀÇ °úÁ¤À» ¹Ýº¹ÇÏ¿© hitÀ²ÀÌ °³¼±µÇ¾ú´Â°¡ È®ÀÎÇÑ´Ù.
BufferÀÇ Å©±â°¡ ³Ê¹« Å©´Ù¸é BufferÀÇ ¼ö¸¦ ÁÙ¿©µµ ¿¬ÀüÈ÷ HitÀ²ÀÌ ÁÁÀ» °ÍÀÌ´Ù.

6. system/manager·Î loginÇÑ ÈÄ hr schemaÀÇ TEMP_EMP tableÀÇ Å©±â¸¦ È®ÀÌÇÑ ÈÄ ±×°ÍÀ» KEEP buffer pool¿¡ À¯ÁöÇغ¸ÀÚ
-¸ÕÀú hr.EMP_TEMP tableÀÇ size¸¦ È®ÀÎÇÑ´Ù.

$sqlplus system/manager

SQL> analyze table hr.temp_emps compute statistics;

SQL> select table_name,blocks from dba_tables
  2  where table_name in ('TEMP_EMPS');

TABLE_NAME                        BLOCKS
------------------------------ ----------
TEMP_EMPS                              7        <-- segment header blockÀ» Á¦¿ÜÇÏ°í 7°³ block

(7+1)*4096bytes = 32K ¹Û¿¡ ¾È µÇÁö¸¸ buffer cacheÀÇ ÇÒ´ç ´ÜÀ§´Â granuleÀÌ´Ù.

============================================================
sga_max_size <= 128M À̸é 4M
¾Æ´Ï¸é                              16M        ===> ±×·¯¹Ç·Î 4M·Î ÇÏÀÚ
============================================================

- keep buffer poolÀ» ±¸¼ºÇÑ´Ù.

SQL> alter system set db_keep_cache_size= 4M;
alter system set db_keep_cache_size= 4M
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-00384: Insufficient memory to grow cache <--¿Ö error°¡ ³¯±î?

SQL> show parameter shared_pool_size

NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
shared_pool_size                    big integer 25165824
SQL>
SQL> alter system set shared_pool_size=20M;
<-- SGA¿¡ »õ·Î¿î Memory component¸¦ Ãß°¡ÇÒ ¸¸Å­ÀÇ ÃæºÐÇÑ Å©±â¸¦ °¡Áö°í ÀÖÁö ¾Ê°í ´Ù¸¥ component ÁÙ¿©µµ ¼º´É¿¡ ¹®Á¦°¡ µÇÁö ¾Ê´Â´Ù¸é

SQL> alter system set db_keep_cache_size=4M;

SQL> select id,name,block_size,current_size,buffers
  2  from v$buffer_pool;

        ID NAME                BLOCK_SIZE CURRENT_SIZE    BUFFERS
---------- -------------------- ---------- ------------ ----------
        1 KEEP                      8192            4        500
        3 DEFAULT                    8192            4        500

--ÀÌÁ¦ hr.TEMP_EMPS tableÀ» keep buffer pool¿¡ cache½ÃŲ´Ù.

SQL> alter table hr.temp_emps
  2  storage(buffer_pool keep);

Table altered.

SQL> select table_name,buffer_pool
  2  from dba_tables
  3  where buffer_pool='KEEP';

TABLE_NAME                    BUFFER_
------------------------------ -------
TEMP_EMPS                      KEEP

<-- ÀÌ sessionÀº ±×´ë·Î À¯ÁöÇÑ´Ù.

-º°µµ·Î hr/hr·Î loginÇÏ¿© lab04_10.sqlÀ» ½ÇÇàÇÏ¿©  TEMP_EMPS table¿¡ ´ëÇØ query¸¦ ½ÇÇàÇÑ ÈÄ buffer cache¿¡ ´ëÇÑ hit ratio¸¦ check ÇÑ´Ù.

$ sqlplus hr/hr

SQL> !cat $HOME/LABS/ptw9i/lab04_10.sql
variable n number;
begin
for i in 1..40
loop
select count(*) into :n from hr.temp_emps;
end loop;
end;
/

SQL> @LABS/ptw9i/lab04_10.sql

-ÀÌÀü¿¡ openµÈ system/manager sessionÀ¸·Î À̵¿

SQL> select name,physical_reads,db_block_gets,consistent_gets,
  2  1 - (physical_reads / (db_block_gets + consistent_gets)) "Hits"
  3  from v$buffer_pool_statistics;

NAME                PHYSICAL_READS DB_BLOCK_GETS CONSISTENT_GETS      Hits
-------------------- -------------- ------------- --------------- ----------
KEEP                              8          360            360 .988888889
DEFAULT                        4286        52780          37684 .952622037

SQL>exit


¸ñ·Ï | ÀÔ·Â | ¼öÁ¤ | ´äº¯ | »èÁ¦