ORACLE
HOME > DB > ORACLE
2018.11.06 / 10:24

How to trace sql exectuion - Oracle 11gÀÇ Real-Time SQL Monitoring

hanulbit
Ãßõ ¼ö 206


2) Oracle 10g ~ 
GATHER_PLAN_STATISTICS ÈùÆ®

Oracle 10g¿¡ Ãß°¡µÈ ÀÌ ³î¶ó¿î ÈùÆ®´Â ±× µ¿¾È ¿ì¸®°¡ ±×Åä·Ï ¸ñ¸»¶óÇß´ø ±â´ÉÀ» Á¦°øÇÑ´Ù. Äõ¸®¸¦ ¼öÇàÇϸ鼭 ¹Ù·Î SQL Trace¿Í °°Àº ½ÇÇà Á¤º¸ ÃßÀûÀ» ÇÒ ¼ö ¾øÀ»±î? ´ÙÀ½°ú °°ÀÌ °¡´ÉÇÏ´Ù.

select /*+ gather_plan_statistics */ * from t_rtm where id between 1 and 100;

select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

PLAN_TABLE_OUTPUT
SQL_ID  bnxtw0wqkqmx5, child number 0
-------------------------------------
select /*+ gather_plan_statistics */ * from t_rtm where id between 1
and 100

Plan hash value: 2986615217

---------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name      | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
---------------------------------------------------------------------------------------------------
|   1 |  TABLE ACCESS BY INDEX ROWID| T_RTM     |      1 |     94 |     50 |00:00:00.01 |       5 |
|*  2 |   INDEX RANGE SCAN          | T_RTM_IDX |      1 |     94 |     50 |00:00:00.01 |       3 |
---------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("ID">=1 AND "ID"<=100)

gather_plan_statistics¶ó´Â ÈùÆ® Çϳª¸¸À¸·Î SQL Trace+Tkprof¸¦ ¼öÇàÇÑ °Í°ú °ÅÀÇ µ¿ÀÏÇÑ È¿°ú¸¦ ¾òÀ» ¼ö ÀÖ´Ù. ¸¸¼¼~
ÀÌ ±â´ÉÀº ÇÑ°¡Áö Å« ÀåÁ¡Àº Estimated °ª°ú Actual °ªÀ» ÇÑ ´«¿¡ ºñ±³ÇØ º¼ ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù. ºñ¿ë °è»êÀÌ ÇÕ¸®ÀûÀÎÁö °¡´ÆÇÒ ¼ö ÀÖ´Â ±âÁØÀÌ µÈ´Ù.

gather_plan_statistics ÈùÆ®Àº ¾Æ·¡ ºí·Î±×¿¡¼­ ¾ÆÁÖ »ó¼¼ÇÏ°Ô ´Ù·é¹Ù ÀÖ´Ù.
http://ukja.tistory.com/entry/%EC%98%A4%EB%9D%BC%ED%81%B4-%ED%8C%81-GATHERPLANSTATISTICS-%ED%9E%8C%ED%8A%B8

3) Oracle 11g ~
Real-Time SQL Monitoring (v$sql_monitor, v$sql_plan_monitor)

ºñ·Ï gather_plan_statistics ÈùÆ®°¡ ȹ±âÀûÀÎ ±â´ÉÀ» Á¦°øÇÏÁö¸¸, Àӽà ¹æÆí¿¡ ºÒ°úÇÏ´Ù. 
°¡·É ½ÇÇà ½Ã°£ÀÌ 5ÃÊ ÀÌ»óµÇ´Â ´À¸° Äõ¸®µéÀÇ ½ÇÇà ÀÌ·Â(plan°ú row source operation±îÁö Æ÷ÇÔÇÑ)À» º¼ ¼ö ÀÖ´Â ¹æ¹ýÀº ¾øÀ»±î? 

Oracle 11g¿¡¼­ Ãß°¡µÈ Real-Time Monitoring±â´ÉÀÌ ±× ÇØ´äÀ» Á¦°øÇÑ´Ù. OracleÀº ½ÇÇà ½Ã°£ÀÌ 5ÃÊ ÀÌ»ó(_sqlmon_threshold È÷µç ÆĶó¹ÌÅÍ·Î Á¶Á¤)ÀÎ ¸ðµç Äõ¸®ÀÇ ½ÇÇà ÀÌ·Â Á¤º¸¸¦ v$sql_monitor¿Í v$sql_plan_monitor ºä¿¡ ³²±ä´Ù. ±×¸®°í dbms_sqltune.report_sql_monitor ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ­ Á¤º¸¸¦ Á¶È¸ÇÒ ¼ö ÀÖµµ·Ï ÇØÁØ´Ù. ¶Ç´Â MONITOR ÈùÆ®¸¦ »ç¿ëÇؼ­ °­Á¦·Î ÃßÀûÇÏ°Ô ÇÒ ¼öµµ ÀÖ´Ù. ¾Æ·¡ ¿¹¸¦ º¸ÀÚ. (Á¤¸±ÀÌ ±úÁö´Â Çö»ó ÀÌÇØ ¹Ù¶÷)

select /*+ monitor */ * from t_rtm where id between 1 and 100;

select sql_id from v$sql where sql_text like 'select /*+ monitor */ * from t_rtm%';

sql_id = bpfu171khfbg6

select dbms_sqltune.report_sql_monitor(sql_id=>'bpfu171khfbg6') from dual

SQL Monitoring Report

SQL Text
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
select /*+ monitor */ * from t_rtm where id between 1 and 100
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Global Information
 Status              :  DONE (FIRST N ROWS) 
 Instance ID         :  1                   
 Session ID          :  147                 
 SQL ID              :  bpfu171khfbg6       
 SQL Execution ID    :  16777218            
 Plan Hash Value     :  2986615217          
 Execution Started   :  01/09/2008 11:05:18 
 First Refresh Time  :  01/09/2008 11:05:18 
 Last Refresh Time   :  01/09/2008 11:05:19 

---------------------------------------
| Elapsed |  Other   | Fetch | Buffer |
| Time(s) | Waits(s) | Calls |  Gets  |
---------------------------------------
|    0.00 |     0.00 |     2 |      5 |
---------------------------------------

SQL Plan Monitoring Details
==========================================================================================================================================
| Id |           Operation           |   Name    |  Rows   | Cost |   Time    | Start  | Starts |   Rows   | Activity  | Activity Detail |
|    |                               |           | (Estim) |      | Active(s) | Active |        | (Actual) | (percent) |   (sample #)    |
==========================================================================================================================================
|  0 | SELECT STATEMENT              |           |         |    3 |           |        |      1 |          |           |                 |
|  1 |   TABLE ACCESS BY INDEX ROWID | T_RTM     |      94 |    3 |           |        |      1 |          |           |                 |
|  2 |    INDEX RANGE SCAN           | T_RTM_IDX |      94 |    2 |         1 |     +0 |      1 |       50 |           |                 |
==========================================================================================================================================

±âº»ÀûÀ¸·Î gather_plan_statistics¿Í °ÅÀÇ ºñ½ÁÇÑ µ¥ÀÌÅ͸¦ Á¦°øÇÏ´Â °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù. ÀÌ µ¥ÀÌÅ͵éÀº v$sql_monitor¿Í v$sql_plan_monitor ºä¿¡ »óÁÖÇϱ⠶§¹®¿¡ ÇÊ¿äÇÏ¸é ¾ðÁ¦µçÁö Á÷Á¢ Á¶È¸ÇÒ ¼öµµ ÀÖ°í, dbms_sqltune.report_sql_monitor ÇÔ¼ö¸¦ ÀÌ¿ëÇØ °£ÆíÇÏ°Ô Á¶È¸ÇÒ ¼öµµ ÀÖ´Ù.

Real-Time SQL Monitoring±â´ÉÀº DBA³ª SQL TunerµéÀÌ Äõ¸®¸¦ Æ©´×ÇÏ´Â ¹æ¹ýÀ» ȹ±âÀûÀ¸·Î °³¼±½Ãų ¼ö ÀÖÀ» °ÍÀ¸·Î ±â´ëµÈ´Ù. Ưº°ÇÑ ÀÌÀ¯°¡ ¾ø´Â ÇÑ ´õ ÀÌ»ó SQL Trace¿Í Tkprof¸¦ ¹ø°¥¾Æ°¡¸ç »ç¿ëÇÒ ÇÊ¿ä°¡ ¾øÀ» °ÍÀÌ´Ù. 


PS) ºñ·Ï SQL ½ÇÇàÀ» ÃßÀûÇÒ ¼ö ÀÖ´Â ´Ù¾çÇÑ ±â¹ýµéÀÌ Ãß°¡µÇ°í ÀÖÁö¸¸, ¿©ÀüÈ÷ SQL Trace´Â °¡Àå °­·ÂÇÑ SQL ÃßÀû ÅøÀÌ´Ù. 

                      SQL Trace¿© ¿µ¿øÇ϶ó~
Trackback 0 : Comments 4
  1. ¹Ú±¤¼­ 2010.04.29 15:15 ½Å°í Modify/Delete Reply

    ¾ðÁ¦³ª À¯ÀÍÇÑ Á¤º¸ °¨»çÈ÷ ¾ò°í °©´Ï´Ù.
    ´Ã °Ç°­Çϼ¼¿ä^^

    • ÀÌÁ¾¿í 2010.06.29 10:53 ½Å°í Modify/Delete Reply

      select dbms_sqltune.report_sql_monitor(sql_id=>'20bk5bj29ggpj') from dual;
      ½ÇÇàÇϸé..

      SQL Monitoring Report ¸Þ¼¼Áö¿Í
      SQL Text ±îÁö¸¸ ³ª¿É´Ï´Ù~

      infomation ¹× planÀ» º¸·Á¸é.. ´Ù¸¥ ¼¼ÆÃÀÌ ÇÊ¿äÇÑ°Ç°¡¿ä??

    • Ä«¹ÌÀ¯ 2011.05.05 10:20 Modify/Delete Reply

      °ü¸®ÀÚÀÇ ½ÂÀÎÀ» ±â´Ù¸®°í ÀÖ´Â ´ñ±ÛÀÔ´Ï´Ù



    Ãâó: http://ukja.tistory.com/88 [¿À¶óŬ ¼º´É ¹®Á¦¿¡ ´ëÇÑ ÅëÂû - Á¶µ¿¿í]