autotrace

No. 10712

NEW FEATURE:AUTOTRACE IN SQL*PLUS 3.3
======================================  

Autotrace는 SQL*Plus 3.3부터 지원하는 New feature로서 기존에는 init.ora에  SQL_TRACE=TRUE를 setting 후 얻어진 trace file을 TKPROF란 utility를   이용하여 SQL 문의 수행 경로, 각종 통계 정보를 얻었다.  그러나, SQL*Plus 3.3부터는 이것을 간단히 처리할 수 있는 방법을 제공한다.

  1. SQL*Plus를 실행하여 scott user로 접속한 후, plan table을 생성한다.
  
     #sqlplus scott/tiger
     SQL>@$ORACLE_HOME/rdbms/admin/utlxplan
    
   <베낀이 추가>
    이왕이면 public synonym를 만들어서 공통으로 사용하면 좋음

  2. 다음에 sys user에서 PLUSTRACE란 ROLE을 만든다.

     SVRMGR>connect internal;
     SVRMGR>create role plustrace;
     SVRMGR>grant select on v_$sesstat  to plustrace;
     SVRMGR>grant select on v_$statname to plustrace;
     SVRMGR>grant select on v_$session  to plustrace;
     SVRMGR>grant plustrace to dba with admin option;
     SVRMGR>grant plustrace to scott;
    
     비고) 위의 grant 문은 client에 SQL*Plus 3.3이 install되어 있는 경우
     C:ORAWIN95PLUS33PLUSTRCE.SQL이라는 script에 기록되어 있다.
     다음과 같이 실행해 주면 된다.

     1> connect sys AS SYSDBA
     2> @$ORACLE_HOME/sqlplus/admin/plustrce.sql
     3> grant plustrace to scott;

   <베낀이 추가>
    위의 예제에서 “as sysdba”를 빼면 안됨
    
  3. 다음에는 scott user로 connect하여 작업한다.

     #sqlplus  scott/tiger
     SQL>set autotrace on
     SQL>select * from emp;
  
           Execution Plan
         ———————————————–
           0      SELECT STATEMENT Optimizer=CHOOSE
           1    0   TABLE ACCESS (FULL) OF ‘EMP’
  
           Statistics
         ———————————————–
          389  recursive calls
            5  db block gets
           53  consistent gets
           12  physical reads
            0  redo size
         1049  bytes sent via SQL*Net to client
          239  bytes received via SQL*Net from client
            4  SQL*Net round-trips to/from client
            0  sorts (memory)
            0  sorts (disk)
           13  rows processed
  
    <베낀이 추가>
    만약, “set autot on”에서 plustrace role관련 오류가 나면 sys권한으로 해당 role를 다시 만들어 주어야 함(as dba생략시 오류가 남)
  
  4. 참고로 set autotrace에는 여러가지 option을 부여해 작업할 수도 있다.
      
   예)set autotrace on           => Explain plan and statistics.
      set autotrace on explain   => Explain plan only.
      set autotrace traceonly    => select된 결과는 빼고 trace만 display
                                    시킴.
      set autotrace on statistics=> sql statement execution statistics.
    
  5. 서버 버젼과 상관없다.

    Server가 7.2 version 이하일지라도 clinet에 SQL*Plus 3.3이 install되어
    있으면 client에서 sqlplus 3.3을 구동시켜 server에 접속하여 위와 같이
    작업하면 무리없이 작업이 가능하다.

Reference Documents
——————-
RCNote:43214.1

<베낀이 추가>
참고로 TOAD에서 이용시에는 메뉴(view-option-oracle)에서 plan_table명을 변경해 주어야 한다. 아니면, TOAD도움말에 있는 것처럼 별도의 TOAD유저를 만들거나(Default), 관련 OBJECT를 생성하여야 함

Leave a Comment

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.