(Obscure) Tools of the Trade   for Tuning Oracle SQLs   [email_address] Tony Jambu Melbourne, Australia
Agenda <ul><li>Tuning Methodology </li></ul><ul><li>Generating Explain Plan & Tracing </li></ul><ul><li>TRCSESS </li></ul>...
Tuning Methodology <ul><li>Where do you start? </li></ul><ul><ul><li>In development or production? </li></ul></ul><ul><ul>...
Tuning Methodology <ul><li>Tracing: </li></ul><ul><ul><li>Numerous methods to trace </li></ul></ul><ul><ul><li>Produces ra...
Tracing <ul><li>Various methods </li></ul><ul><ul><li>Init.ora parameters </li></ul></ul><ul><ul><li>alter session set eve...
Tracing <ul><li>Add name identifier to trace file </li></ul><ul><ul><li>alter session set  tracefile_identifier ='MyTrc_';...
Tracing <ul><li>Trace Enabling </li></ul><ul><ul><li>New : DBMS_MONITOR.CLIENT_ID_ TRACE _ENABLE('account_update') </li></...
Tracing <ul><li>Statistics Enabling </li></ul><ul><ul><li>New : DBMS_MONITOR.CLIENT_ID_ STAT _ENABLE('account_update') </l...
TRCSESS <ul><li>Tkprof </li></ul><ul><ul><li>Only works with one file at a time </li></ul></ul><ul><ul><li>How to handle m...
SQL&Plus and AUTOTRACE <ul><li>An SQL*Plus command </li></ul><ul><li>Usage: set autot[race]  {off | on | trace[only]}  [ex...
SQL&Plus and AUTOTRACE <ul><li>set autotrace  on : Shows the  execution plan  as well as  statistics  of the statement.  <...
SQL&Plus and AUTOTRACE <ul><li>Pre-requisite: PLAN_TABLE.  </li></ul><ul><ul><li>Be careful that you have your own copy of...
SQL&Plus and AUTOTRACE <ul><li>DEMO_1   (not for dba) </li></ul><ul><li>cd Trace Analyzer </li></ul><ul><li>sqlplus tjambu...
DBMS_XPLAN <ul><li>DBMS_XPLAN is an explain plan formatter </li></ul><ul><ul><li>Has 4 Procedures </li></ul></ul><ul><ul><...
DBMS_XPLAN <ul><li>dbms_xplan.display (Explain Plan) </li></ul><ul><ul><li>Usage: SELECT * FROM table(DBMS_XPLAN.DISPLAY);...
DBMS_XPLAN <ul><li>DBMS_XPLAN.DISPLAY  – Examples </li></ul><ul><ul><li>select * from table(dbms_xplan.display ('PLAN_TABL...
DBMS_XPLAN <ul><li>DBMS_XPLAN.DISPLAY_CURSOR    ( Execution  Plan)  -  DEMO 2   </li></ul><ul><ul><li>Run with and without...
TRCA -  TRACE ANALYZER <ul><li>Tool from Oracle Support Center of Expertise </li></ul><ul><ul><li>Available from Metalink ...
TRCA -  TRACE ANALYZER <ul><li>Usage </li></ul><ul><ul><li>Only need one file ( trcanlzr.sql)  to run from client </li></u...
TRCA -  TRACE ANALYZER <ul><li>DEMO 3 </li></ul><ul><ul><li>Only need one SQL file to run from client </li></ul></ul><ul><...
SQLT-  SQLTXPLAIN <ul><li>Tool from Oracle Support Center of Expertise </li></ul><ul><ul><li>Available from Metalink – Doc...
SQLT-  SQLTXPLAIN <ul><li>Execution – 3 Methods </li></ul><ul><ul><li>XPLAIN  Method  - smaller output, does not understan...
SQLT-  SQLTXPLAIN <ul><li>DEMO 4 - XPLAIN </li></ul><ul><ul><li>Input: Single SQL </li></ul></ul><ul><li># cd sqlt </li></...
SQLT-  SQLTXPLAIN <ul><li>DEMO 5 - XTRACT </li></ul><ul><ul><li>Input: SQL_ID or HASH_VALUE </li></ul></ul><ul><li>-- Chec...
SQLT-  SQLTXPLAIN <ul><li>DEMO 6 - XECUTE </li></ul><ul><ul><li>Input: Single SQL statement </li></ul></ul><ul><li>cd sqlt...
Oracle Active Report- Real-Time SQL Monitoring <ul><li>New in 11gR2 </li></ul><ul><ul><li>EM function via DBMS_SQLTUNE </l...
Oracle Active Report- Real-Time SQL Monitoring <ul><li>DEMO 7 </li></ul><ul><li>cd  “Active Report” </li></ul><ul><li>sqlp...
Other Tools - TOAD <ul><li>TOAD functionalities </li></ul><ul><ul><li>Explain Plan customisation </li></ul></ul><ul><ul><l...
Summary  <ul><ul><li>There are different approaches to SQL tuning </li></ul></ul><ul><ul><li>We covered some less known to...
xxxxxxx <ul><li>XXX </li></ul><ul><ul><li>Xxx </li></ul></ul><ul><li>XXX </li></ul><ul><ul><li>XXX </li></ul></ul>
<ul><li>Texas Memory Systems ,  </li></ul><ul><ul><li>http://www.superssd.com/whitepapers.htm </li></ul></ul><ul><ul><li>h...
Session:  715  Title: Understanding Solid State Drives (SSD)  Technology for Databases, Presenter: Tony Jambu For feedback...
 
Upcoming SlideShare
Loading in...5
×

Tony Jambu (obscure) tools of the trade for tuning oracle sq ls

2,100

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,100
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
123
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Who attended last years presentation?
  • Tony Jambu (obscure) tools of the trade for tuning oracle sq ls

    1. 1. (Obscure) Tools of the Trade for Tuning Oracle SQLs [email_address] Tony Jambu Melbourne, Australia
    2. 2. Agenda <ul><li>Tuning Methodology </li></ul><ul><li>Generating Explain Plan & Tracing </li></ul><ul><li>TRCSESS </li></ul><ul><li>DBMS_XPLAN </li></ul><ul><li>SQL*Plus and Autotrace </li></ul><ul><li>TRCANLZR - Trace Analyzer </li></ul><ul><li>SQLT - SQLTXPLAIN </li></ul><ul><li>Oracle Active Report </li></ul><ul><li>Other Tools </li></ul>
    3. 3. Tuning Methodology <ul><li>Where do you start? </li></ul><ul><ul><li>In development or production? </li></ul></ul><ul><ul><li>Do you have the volume of data? </li></ul></ul><ul><ul><li>Proactive or Reactive ? </li></ul></ul><ul><ul><li>Explain Plans only or database tracing? </li></ul></ul><ul><li>Explain Plan: </li></ul><ul><ul><li>Quick but is ‘best guess’ </li></ul></ul><ul><ul><li>Need to validate changes </li></ul></ul>
    4. 4. Tuning Methodology <ul><li>Tracing: </li></ul><ul><ul><li>Numerous methods to trace </li></ul></ul><ul><ul><li>Produces raw data from the execution </li></ul></ul><ul><ul><li>Not practical for some very large data warehouse SQLs </li></ul></ul><ul><li>How </li></ul><ul><ul><li>At own session , other sessions or database level? </li></ul></ul><ul><ul><li>Numerous ways of turning tracing on </li></ul></ul>
    5. 5. Tracing <ul><li>Various methods </li></ul><ul><ul><li>Init.ora parameters </li></ul></ul><ul><ul><li>alter session set event….. eg 10046, 10053, alter [session|system] set sql_trace=true; </li></ul></ul><ul><ul><li>dbms_session.set_sql_trace(true), dbms_system.set_bool_param_in_session(...), dbms_system.set_sql_trace_in_session(...), dbms_support.start_trace, dbms_support.start_trace_in_session(...), dbms_system.set_ev(…), ***dbms_monitor.* - Oracle 10g and up. Replaces DBMS_SUPPORT </li></ul></ul><ul><ul><li>oradebug session_event … </li></ul></ul>
    6. 6. Tracing <ul><li>Add name identifier to trace file </li></ul><ul><ul><li>alter session set tracefile_identifier ='MyTrc_'; </li></ul></ul><ul><li>Session Information are useful for end-to-end tracing and can be set with </li></ul><ul><ul><li>Machine : The name of your machine </li></ul></ul><ul><ul><li>Module : The application module name </li></ul></ul><ul><ul><li>Action : What you are doing eg ‘Before Transforming data’ or ‘Aggregating base data’ </li></ul></ul><ul><ul><li>Service : The service name </li></ul></ul><ul><ul><li>Client ID : Either logon id or set with dbms_session.set_identifier(‘A Name’) – Case sensitive </li></ul></ul>
    7. 7. Tracing <ul><li>Trace Enabling </li></ul><ul><ul><li>New : DBMS_MONITOR.CLIENT_ID_ TRACE _ENABLE('account_update') </li></ul></ul><ul><ul><li>Means, auto enable tracing for all sessions with the identifier ‘account_update’ </li></ul></ul><ul><ul><li>To disable: DBMS_MONITOR.CLIENT_ID_ TRACE _DISABLE('account_update'); </li></ul></ul>
    8. 8. Tracing <ul><li>Statistics Enabling </li></ul><ul><ul><li>New : DBMS_MONITOR.CLIENT_ID_ STAT _ENABLE('account_update') </li></ul></ul><ul><ul><li>Enable stats gathering for Client_ID = ‘account_update’ </li></ul></ul><ul><ul><li>To disable: DBMS_MONITOR.CLIENT_ID_ STAT _DISABLE('account_update'); </li></ul></ul><ul><ul><li>Also possible for Service, Module & Action DBMS_MONITOR.SERV_MOD_ACT_STAT_DISABLE( service_name => 'ACCTG', module_name => 'GLEDGER', action_name => 'INSERT ITEM'); *** 10g </li></ul></ul>
    9. 9. TRCSESS <ul><li>Tkprof </li></ul><ul><ul><li>Only works with one file at a time </li></ul></ul><ul><ul><li>How to handle multiple files like PX files? </li></ul></ul><ul><li>trcsess </li></ul><ul><ul><li>Oracle utility that aggregates/consolidates and format numerous trace files into a single file </li></ul></ul>Trcsess output= output_file_name ] [session= session_id ] [clientid= client_id ] [service= service_name ] [action= action_name ] [module= module_name ] [ trace_files ]
    10. 10. SQL&Plus and AUTOTRACE <ul><li>An SQL*Plus command </li></ul><ul><li>Usage: set autot[race] {off | on | trace[only]} [exp[lain]] [stat[istics]] </li></ul><ul><ul><li>ON – returns results </li></ul></ul><ul><ul><li>Traceonly – Do not return results </li></ul></ul><ul><ul><li>Exp – Shows execution plan </li></ul></ul><ul><ul><li>Stat – Gathers execution stats </li></ul></ul>
    11. 11. SQL&Plus and AUTOTRACE <ul><li>set autotrace on : Shows the execution plan as well as statistics of the statement. </li></ul><ul><li>set autotrace on explain: Displays the execution plan only. </li></ul><ul><li>set autotrace on statistics : Displays the statistics only. </li></ul><ul><li>set autotrace traceonly : Displays the execution plan and the statistics (as set autotrace on does), but doesn't print a query's result. </li></ul><ul><li>set autotrace off : Disables all autotrace </li></ul>
    12. 12. SQL&Plus and AUTOTRACE <ul><li>Pre-requisite: PLAN_TABLE. </li></ul><ul><ul><li>Be careful that you have your own copy of the plan_table and is the latest version in $ORACLE_HOME/rdbms/admin/utlxplan.sql </li></ul></ul><ul><ul><li>In 11g, no need as there is a public Synonym to SYS.PLAN_TABLE$ . </li></ul></ul><ul><li>Pre-requisite: PLUSTRACE Role </li></ul><ul><ul><li>Users will require the PLUSTRACE role ($ORACLE_HOME/sqlplus/admin/plustrce.sql) </li></ul></ul>
    13. 13. SQL&Plus and AUTOTRACE <ul><li>DEMO_1 (not for dba) </li></ul><ul><li>cd Trace Analyzer </li></ul><ul><li>sqlplus tjambu/tjambu </li></ul><ul><li>set autotrace trace exp </li></ul><ul><li>@TJ_Test1a.sql </li></ul><ul><li>set autotrace trace exp STAT </li></ul><ul><li>@TJ_Test1a.sql </li></ul><ul><li>-See diff between ON and STATS </li></ul>
    14. 14. DBMS_XPLAN <ul><li>DBMS_XPLAN is an explain plan formatter </li></ul><ul><ul><li>Has 4 Procedures </li></ul></ul><ul><ul><ul><li>DISPLAY – Displays the explain plan from the Plan Table </li></ul></ul></ul><ul><ul><ul><li>DISPLAY_CURSOR – Displays the Execution plan of a SQL in the cursor cache </li></ul></ul></ul><ul><ul><ul><li>DISPLAY_AWR – Displays the Execution plan for a SQL_ID in the AWR </li></ul></ul></ul><ul><ul><ul><li>DISPLAY_SQLSET – Displays the Execution plan for statement in a SQL tuning set </li></ul></ul></ul>
    15. 15. DBMS_XPLAN <ul><li>dbms_xplan.display (Explain Plan) </li></ul><ul><ul><li>Usage: SELECT * FROM table(DBMS_XPLAN.DISPLAY); </li></ul></ul><ul><ul><li>Usage Accepts 3 parameters </li></ul></ul><ul><ul><ul><li>Table_Name - Name of plan table, default value 'PLAN_TABLE'. </li></ul></ul></ul><ul><ul><ul><li>Statement_ID - Statement id of the plan to be displayed, default value NULL. </li></ul></ul></ul><ul><ul><ul><li>Format - Level of detail displayed, default value 'TYPICAL'. Also 'BASIC', 'ALL', 'SERIAL‘. </li></ul></ul></ul>
    16. 16. DBMS_XPLAN <ul><li>DBMS_XPLAN.DISPLAY – Examples </li></ul><ul><ul><li>select * from table(dbms_xplan.display ('PLAN_TABLE', 'TJ2' , 'BASIC ')); </li></ul></ul><ul><ul><li>select * from table(dbms_xplan.display ('PLAN_TABLE', 'TJ2' , 'SERIAL ')); </li></ul></ul><ul><ul><li>select * from table(dbms_xplan.display ('PLAN_TABLE', 'TJ2' , 'TYPICAL ')); </li></ul></ul><ul><ul><li>select * from table(dbms_xplan.display ('PLAN_TABLE', 'TJ2' , 'ALL ')); </li></ul></ul><ul><ul><li>SELECT tf.* FROM DBA_HIST_SQLTEXT ht, table (DBMS_XPLAN. DISPLAY_AWR (ht.sql_id,null, null, 'ALL' )) tf WHERE ht.sql_text like ‘% EV_INTERMEDIATE %’; </li></ul></ul>
    17. 17. DBMS_XPLAN <ul><li>DBMS_XPLAN.DISPLAY_CURSOR ( Execution Plan) - DEMO 2 </li></ul><ul><ul><li>Run with and without GATHER_PLAN_STATS hint </li></ul></ul><ul><li>SELECT * FROM TABLE ( DBMS_XPLAN.display_cursor (NULL, NULL, 'ALLSTATS LAST +peeked_binds') ); </li></ul><ul><li>cd DBMS_XPLAN </li></ul><ul><li>sqlplus sh/sh </li></ul><ul><li>@demo_dbms_xplan1.sql </li></ul><ul><li>@demo_dbms_xplan2.sql </li></ul>
    18. 18. TRCA - TRACE ANALYZER <ul><li>Tool from Oracle Support Center of Expertise </li></ul><ul><ul><li>Available from Metalink – Doc ID: 224270.1 </li></ul></ul><ul><ul><li>Input : One or more trace file from 10046 </li></ul></ul><ul><ul><li>Output : Diagnostics report in HTML and Text format. </li></ul></ul><ul><ul><li>Excellent for tuning SQLS </li></ul></ul><ul><ul><li>Contains information about all objects accesses and their statistics </li></ul></ul><ul><ul><li>NOTE : Developers now have access to trace files on server! </li></ul></ul>
    19. 19. TRCA - TRACE ANALYZER <ul><li>Usage </li></ul><ul><ul><li>Only need one file ( trcanlzr.sql) to run from client </li></ul></ul><ul><ul><li>4 ways </li></ul></ul><ul><ul><ul><li>Analyzing one trace on the same system where it was generated. sqlplus user/passwd @trcanlzr file.trc </li></ul></ul></ul><ul><ul><ul><li>Analyzing a set of related traces (PX) on the same system where they were generated. sqlplus user/passwd @trcanlzr TraceFiles.lis </li></ul></ul></ul><ul><ul><ul><li>Analyzing one trace on a different system (target) to the one where it was generated (source). </li></ul></ul></ul><ul><ul><ul><li>Analyzing a set of related traces (PX) on a different system (target) to where they were generated (source) </li></ul></ul></ul>
    20. 20. TRCA - TRACE ANALYZER <ul><li>DEMO 3 </li></ul><ul><ul><li>Only need one SQL file to run from client </li></ul></ul><ul><li>cd trca/run </li></ul><ul><li>sqlplus sh/sh </li></ul><ul><li>@trcanlzr.sql TraceFiles.lis </li></ul>
    21. 21. SQLT- SQLTXPLAIN <ul><li>Tool from Oracle Support Center of Expertise </li></ul><ul><ul><li>Available from Metalink – Doc ID: 215187.1 </li></ul></ul><ul><ul><li>Input : Single SQL statement, SQL_ID or HASH_VALUE </li></ul></ul><ul><ul><li>Output : Diagnostics report in HTML and Text format reporting on execution plans, CBO statistics, schema objects metadata, performance statistics, configuration parameters, and similar elements </li></ul></ul><ul><ul><li>Can utilise Oracle Diagnostic and the Oracle Tuning Packs </li></ul></ul><ul><ul><li>Understands database links </li></ul></ul>
    22. 22. SQLT- SQLTXPLAIN <ul><li>Execution – 3 Methods </li></ul><ul><ul><li>XPLAIN Method - smaller output, does not understand bind variables </li></ul></ul><ul><ul><li>XTRACT Method - for when the SQL still resides in memory or in the Automatic Workload Repository AWR. Need SQL_ID or HASH_VALUE. </li></ul></ul><ul><ul><li>XECUTE Method - provides the maximum level of detail. Executes the SQL being analyzed, then it produces a set of diagnostics files. Its major drawback is that if the SQL being analyzed takes long to execute, this method will take longer. For statements < 1hr </li></ul></ul>
    23. 23. SQLT- SQLTXPLAIN <ul><li>DEMO 4 - XPLAIN </li></ul><ul><ul><li>Input: Single SQL </li></ul></ul><ul><li># cd sqlt </li></ul><ul><li># sqlplus sh/sh </li></ul><ul><li>SQL> @run/sqltxplain.sql ../TJ_Test1.sql </li></ul>
    24. 24. SQLT- SQLTXPLAIN <ul><li>DEMO 5 - XTRACT </li></ul><ul><ul><li>Input: SQL_ID or HASH_VALUE </li></ul></ul><ul><li>-- Check TOAD for SQL_ID or HASH_VALUE or </li></ul><ul><li>-- Check trace file </li></ul><ul><li>  </li></ul><ul><li>cd sqlt </li></ul><ul><li>sqlplus sh/sh </li></ul><ul><li>SQL> @run/sqltxtract.sql 2751883218 </li></ul><ul><li>  </li></ul><ul><li>hv =2751883218 ad='92da13d4' sqlid ='5y7bskyk0ctyk‘ </li></ul><ul><li>@run/sqltxtract.sql 2751883218 Or </li></ul><ul><li>@run/sqltxtract.sql 5y7bskyk0ctyk </li></ul>
    25. 25. SQLT- SQLTXPLAIN <ul><li>DEMO 6 - XECUTE </li></ul><ul><ul><li>Input: Single SQL statement </li></ul></ul><ul><li>cd sqlt </li></ul><ul><li>sqlplus sh/sh </li></ul><ul><li>SQL> @run/ sqltxecute.sql ../TJ_Test1.sql </li></ul>
    26. 26. Oracle Active Report- Real-Time SQL Monitoring <ul><li>New in 11gR2 </li></ul><ul><ul><li>EM function via DBMS_SQLTUNE </li></ul></ul><ul><ul><li>Extract session/SQL information and presents infomation in GUI/Adobe Flash </li></ul></ul><ul><ul><li>Needs internet connection </li></ul></ul><ul><ul><li>Good for database support. Able to capture and encapsulate all the information in one HTML report. </li></ul></ul><ul><ul><li>dbms_sqltune. report_sql_detail dbms_sqltune. report_sql_monitor . </li></ul></ul>
    27. 27. Oracle Active Report- Real-Time SQL Monitoring <ul><li>DEMO 7 </li></ul><ul><li>cd “Active Report” </li></ul><ul><li>sqlplus tjambu/tjambu </li></ul><ul><li>SQL> @ report_sql_monitor.sql </li></ul><ul><li>SQL> @ report_sql_detail.sql </li></ul>
    28. 28. Other Tools - TOAD <ul><li>TOAD functionalities </li></ul><ul><ul><li>Explain Plan customisation </li></ul></ul><ul><ul><li>Explain Plan comparison </li></ul></ul><ul><ul><li>Trace file browser </li></ul></ul><ul><ul><li>Tkprof utility </li></ul></ul>
    29. 29. Summary <ul><ul><li>There are different approaches to SQL tuning </li></ul></ul><ul><ul><li>We covered some less known tools </li></ul></ul><ul><ul><li>Which to choose depends on your particular situation </li></ul></ul><ul><ul><li>Do try out some of the newer tools </li></ul></ul>For feedback & discussion: [email_address]
    30. 30. xxxxxxx <ul><li>XXX </li></ul><ul><ul><li>Xxx </li></ul></ul><ul><li>XXX </li></ul><ul><ul><li>XXX </li></ul></ul>
    31. 31. <ul><li>Texas Memory Systems , </li></ul><ul><ul><li>http://www.superssd.com/whitepapers.htm </li></ul></ul><ul><ul><li>http://www.texmemsys.com/files/whitepaper_opera.pdf </li></ul></ul><ul><li>Anand Tech, http://anandtech.com/storage/showdoc.aspx?i=3631 http://www.anandtech.com/storage/showdoc.aspx?i=3531&p=1 </li></ul><ul><li>StorageSearch.com/SolidData, http://www.storagesearch.com/soliddata-art2-comparisons.pdf </li></ul>References & Acknowledgement
    32. 32. Session: 715  Title: Understanding Solid State Drives (SSD) Technology for Databases, Presenter: Tony Jambu For feedback & discussion: [email_address] Please fill in the evaluation form. <ul><li>What did we do to reduce the End of Fin year processing from 2days to 4 hours? </li></ul><ul><li>ANSWER </li></ul>Select Star Mailing list http://groups.yahoo.com/group/Select_Star/ or email [email_address]
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×