À¯¿ëÇÑ SQL scripts 2
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2006-03-07 16:39:44
 

RowCacheÀÇ MissÀ²À» º¸¿©ÁØ´Ù



/* rowCache ÀÇ MissRatio¸¦ Á¶»çÇÏ´Â ½ºÅ©¸³Æ®

** <<¹ÚÁ¦¿ë 99.11>>

** Row chache ÀÇ Miss ratio´Â 15% ÀÌÇÏ·Î À¯ÁöÇÏ´Â °ÍÀÌ ÁÁ´Ù.

** ±×·¸Áö ¾ÊÀ»°æ¿ì shared_pool_size¸¦ ´Ã¸®´Â°ÍÀ» °í·ÁÇØ¾ß ÇÑ´Ù.

*/

select sum(gets) "Gets",

sum(getmisses) "Misses",

(1-(sum(getmisses)/(sum(gets)+sum(getmisses))))*100 "HitRate"

from v$rowcache;



Library CacheÀÇ Hitratio¸¦ º¸¿©ÁØ´Ù.(shared_poolÀÇ size°áÁ¤À»À§ÇØ)



/* library Cache Hitratio Ãâ·Â ½ºÅ©¸³Æ®

** <<¹ÚÁ¦¿ë 99.11>>

** library Cache ÀÇ hitratio °¡ 0.9 ÀÌÇÏÀ̸é

** Shared Pool Size¸¦ ´Ã·ÁÁְųª, SQL ¹®ÀÇ ÀÌ»óÀ»

** Á¶»çÇØ¾ß ÇÑ´Ù.

*/

select sum(pins) Executions,

sum(pinhits) "Execution Hits",

sum(reloads) Misses,

((sum(pins) / (sum(pins) + sum(reloads))) * 100) hitratio

from v$librarycache;



SQL Cursor¸¦ º¸¿©ÁÖ´Â ½ºÅ©¸³Æ®



/* SQL Cursor¸¦ Á¶»çÇÏ´Â ½ºÅ©¸³Æ®.

** <<¹ÚÁ¦¿ë 99.11>>

** SQL Cursor ¸¦ Á¶»çÇÏ¿© ºÎÇÏ°¡ ¸¹ÀÌ °É¸®´Â SQL¹®°ú

** ¸Þ¸ð¸®¸¦ Á¶»çÇÑ´Ù.

** loads : ij½¬¿¡¼­ ³ª°¬´Ù µé¾î¿Â Ƚ¼ö(best=1).

** invalidations : LRU¿¡¼­ ¹«È¿È­µÈ Ƚ¼ö. ÀÌ °ªÀÌ 4ÀÌ»óÀ̸é

** shared_pool_area¸¦ È®ÀåÇؾßÇÑ´Ù.

** parse_calls : ÀÌ Ä¿¼­ÀÇ È£Ãâ ¼ö.

** sorts : ¼öÇàµÈ ¼ÒƮȽ¼ö

** command_type: 2 - insert, 3-select, 4-update, 7-delete

*/

select sql_text, loads, invalidations, parse_calls, sorts

FROM v$sqlarea

WHERE sql_text NOT LIKE '%$%'

AND command_type IN(2,3,6,7);



explainÀ» º¸±â ½±°Ô Ãâ·ÂÇØÁÖ´Â SQL



*

** expain plan °á°ú¸¦ º¸±â ½±°Ô Ãâ·ÂÇØÁÖ´Â ½ºÅ©¸³Æ®.

**

** 1) expainÀ» óÀ½ »ç¿ëÇÒ °æ¿ì¿£ [ORACLE_HOME]/rdbms/admin/utlxplan.sqlÀ» ½ÇÇà,

** plan_tableÀ» »ý¼ºÇÑ´Ù.

** 2) óÀ½ »ç¿ëÀÌ ¾Æ´Ï¸é delete from plan_table; À» ½ÇÇàÇÏ¿© ÀÌÀü °á°ú¸¦ »èÁ¦.

**

** ½ÇÇà°á°ú ÆĽ̹øÈ£(id)°¡ ±æ¸é SQLÀÌ ºñÈ¿À²ÀûÀ̰ųª, shared_pool_size°¡ ÀÛÀº°ÍÀÌ´Ù.

** ±âŸ SQL¹®ÀÌ À妽º¸¦ »ç¿ëÇÏ´ÂÁö µîµîÀ» ¾Ë¼ö ÀÖ´Ù.

*/

col operation format a30

col options format a20

col id format 99



select id, lpad(' ',2*level) || operation ||

decode(id, 0, ' Cost= ' || position )"operation",

options, object_name "object"

from plan_table

connect by prior id=parent_id

start with id =0;



¼¼¼Çº°·Î °úµµÇÑ memory read¸¦ ÇÏ´Â SQL¹®À» ã¾ÆÁÖ´Â ½ºÅ©¸³Æ®



/*

** SQL query Æ©´× ½ºÅ©¸³Æ®.. <¹ÚÁ¦¿ë>

**

** À¯Àúº°·Î °úµµÇÑ logical read¸¦ ¼öÇàÇÏ´Â sql ¹® ã±â

**

**

*/

Break on User_Name On Disk_Reads on Buffer_Gets on Rows_Processed

Select A.User_Name, B.Disk_Reads, B.Buffer_Gets, B.Rows_Processed, C.SQL_Text

From V$Open_Cursor A, V$SQLArea B, V$SQLText C

Where A.User_Name = Upper('&&User') And A.Address = C.Address

And A.Address = B.Address

Order By A.User_Name, A.Address, C.Piece;



°úµµÇÑ memory read¸¦ ÇÏ´Â SQL¹®À» ã¾ÆÁÖ´Â ½ºÅ©¸³Æ®



/*

** SQL query Æ©´× ½ºÅ©¸³Æ®.. <¹ÚÁ¦¿ë>

**

** °úµµÇÑ logical read¸¦ ¼öÇàÇÏ´Â SQL¹®À» V$SQLAREA ¿¡¼­ °Ë»öÇØÁÜ.

**

** ¿øÀÎ => 1) À妽º Ä÷³¿¡ distinctÇÑ °ªÀÌ ÀûÀº, ºÎÀûÀýÇÑ À妽ºÀÇ »ç¿ë. (´ëü·Î À妽º¸¦ Áö¿ö¾ß ÇÒ °æ¿ì)

** 2) ÃÖÀûÈ­ µÇÁö ¾ÊÀº SQL ¹®Àå

*/

select buffer_gets, sql_text from v$sqlarea

where buffer_gets > 200000

order by buffer_gets desc;



°úµµÇÑ disk read¸¦ ÇÏ´Â SQL¹®À» ã¾ÆÁÖ´Â ½ºÅ©¸³Æ®



/*

** SQL query Æ©´× ½ºÅ©¸³Æ®.. <¹ÚÁ¦¿ë>

**

** °úµµÇÑ disk read¸¦ ¼öÇàÇÏ´Â SQL¹®À» V$SQLAREA ¿¡¼­ °Ë»öÇØÁÜ.

**

** ¿øÀÎ => 1) SQL¹®ÀÌ ÃÖÀûÈ­ µÇÁö ¾Ê¾Æ disk read¸¦ ¸¹ÀÌ ÇÒ ¼ö ¹Û¿¡ ¾ø´Â Äõ¸®ÀÏ°æ¿ì.

** (index°¡ ¾ø°Å³ª »ç¿ëµÇÁö ¾ÊÀ»¶§)

** 2) db_block_buffers ¶Ç´Â shared_pool_size °¡ ÀÛÀº °æ¿ì. (¸Þ¸ð¸®°¡ ÀûÀ½)

*/

select disk_reads, sql_text from v$sqlarea

where disk_reads > 10000

order by disk_reads desc;



SGAÀÇ shared pool³»¿¡ ij½¬µÈ objectÁß Å« ¿µ¿ªÀ» Â÷Áö ÇÏ°í ÀÖ´Â °ÍÀ» ã¾ÆÁÖ´Â ½ºÅ©¸³Æ®



/*

** Shared_pool¿¡ ÀúÀåµÈ ³»¿ëº¸±â <¹ÚÁ¦¿ë>

**

** ÇÁ·Î½ÃÁ®³ª ÆÐÅ°ÁöµîÀº shared_pool¿¡ ÀúÀåµÇ¸ç ÀúÀåµÈ °´Ã¼Áß

** ±× Å©±â°¡ 100K °¡ ³Ñ´Â°ÍÀ» º¸¿©ÁØ´Ù.

*/

col name format a30



select name, sharable_mem

from v$db_object_cache

where sharable_mem > 100000

and type in ('PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'PROCEDURE')

and kept = 'NO';



SGAÀÇ shared pool ÀÇ ÇöÀç »ç¿ëµµ¸¦ Ãâ·ÂÇØÁÖ´Â SQL



/*

** shared_pool_sizeÀÇ ÇöÀç »ç¿ë ÇöȲÀ» º¸¿©ÁÜ. <¹ÚÁ¦¿ë>

**

** shared_pool_sizeÀÇ ÇöÀçÀÇ »ç¿ëÇöȲÀ» º¸¿©ÁØ´Ù.

** ÀÌ µ¥ÀÌÅ͸¦ ÁÖ±âÀûÀ¸·Î º¸°üÇÏ¿© ºÐ¼®ÇÑ´Ù.

*/

col value for 999,999,999,999 heading "Shared Pool Size"

col bytes for 999,999,999,999 heading "Free Bytes"

select to_number(v$parameter.value) value, v$sgastat.bytes,

(v$sgastat.bytes/v$parameter.value)*100 "Percent Free"

from v$sgastat, v$parameter

where v$sgastat.name = 'free memory'

and v$ parameter .name = ¡®shared_pool_size;


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