Upload
insync-conference
View
109
Download
5
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
(Obscure) Tools of the Trade
for Tuning Oracle SQLs
Tony JambuMelbourne, Australia
Agenda• Tuning Methodology
• Generating Explain Plan & Tracing
• TRCSESS
• DBMS_XPLAN
• SQL*Plus and Autotrace
• TRCANLZR - Trace Analyzer
• SQLT - SQLTXPLAIN
• Oracle Active Report
• Other Tools
Tuning Methodology
Where do you start?
In development or production?
Do you have the volume of data?
Proactive or Reactive ?
Explain Plans only or database tracing?
Explain Plan:
Quick but is ‘best guess’
Need to validate changes
Tuning Methodology
Tracing:
Numerous methods to trace
Produces raw data from the execution
Not practical for some very large data warehouse SQLs
How
At own session , other sessions or database level?
Numerous ways of turning tracing on
DBMS_XPLAN
DBMS_XPLAN is an explain plan formatter
Has 4 Procedures
DISPLAY – Displays the explain plan from the Plan Table
DISPLAY_CURSOR – Displays the Execution plan of a SQL in the cursor cache
DISPLAY_AWR – Displays the Execution plan for a SQL_ID in the AWR
DISPLAY_SQLSET – Displays the Execution plan for statement in a SQL tuning set
DBMS_XPLAN
dbms_xplan.display (Explain Plan)
Usage: SELECT * FROM table(DBMS_XPLAN.DISPLAY);
Usage Accepts 3 parameters
Table_Name - Name of plan table, default value 'PLAN_TABLE'.
Statement_ID - Statement id of the plan to be displayed, default value NULL.
Format - Level of detail displayed, default value 'TYPICAL'. Also 'BASIC', 'ALL', 'SERIAL‘.
DBMS_XPLAN
DBMS_XPLAN.DISPLAY – Examples select * from table(dbms_xplan.display('PLAN_TABLE', 'TJ2' , 'BASIC'));
select * from table(dbms_xplan.display('PLAN_TABLE', 'TJ2' , 'SERIAL'));
select * from table(dbms_xplan.display('PLAN_TABLE', 'TJ2' , 'TYPICAL'));
select * from table(dbms_xplan.display('PLAN_TABLE', 'TJ2' , 'ALL'));
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%’;
DBMS_XPLAN
DBMS_XPLAN.DISPLAY_CURSOR (Execution Plan) - DEMO 2 Run with and without GATHER_PLAN_STATS hint
• SELECT * FROM TABLE ( DBMS_XPLAN.display_cursor (NULL, NULL, 'ALLSTATS LAST +peeked_binds') );
• cd DBMS_XPLAN• sqlplus sh/sh• @demo_dbms_xplan1.sql• @demo_dbms_xplan2.sql
TRCA - TRACE ANALYZER
Tool from Oracle Support Center of Expertise
Available from Metalink – Doc ID:224270.1
Input: One or more trace file from 10046
Output: Diagnostics report in HTML and Text format.
Excellent for tuning SQLS
Contains information about all objects accesses and their statistics
NOTE: Developers now have access to trace files on server!
TRCA - TRACE ANALYZER
Usage Only need one file (trcanlzr.sql) to run from client 4 ways
1. Analyzing one trace on the same system where it was generated.sqlplus user/passwd @trcanlzr file.trc
2. Analyzing a set of related traces (PX) on the same system where they were generated. sqlplus user/passwd @trcanlzr TraceFiles.lis
3. Analyzing one trace on a different system (target) to the one where it was generated (source).
4. Analyzing a set of related traces (PX) on a different system (target) to where they were generated (source)
TRCA - TRACE ANALYZER
DEMO 3
Only need one SQL file to run from client
• cd trca/run• sqlplus sh/sh• @trcanlzr.sql TraceFiles.lis
SQLT- SQLTXPLAIN
Tool from Oracle Support Center of Expertise
Available from Metalink – Doc ID:215187.1
Input: Single SQL statement, SQL_ID or HASH_VALUE
Output: Diagnostics report in HTML and Text format reporting on execution plans, CBO statistics, schema objects metadata, performance statistics, configuration parameters, and similar elements
Can utilise Oracle Diagnostic and the Oracle Tuning Packs
Understands database links
SQLT- SQLTXPLAIN
Execution – 3 Methods
XPLAIN Method - smaller output, does not understand bind variables
XTRACT Method - for when the SQL still resides in memory or in the Automatic Workload Repository AWR. Need SQL_ID or HASH_VALUE.
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
SQLT- SQLTXPLAIN
DEMO 4 - XPLAIN
Input: Single SQL
• # cd sqlt
• # sqlplus sh/sh
• SQL> @run/sqltxplain.sql ../TJ_Test1.sql
SQLT- SQLTXPLAIN
DEMO 5 - XTRACT
Input: SQL_ID or HASH_VALUE• -- Check TOAD for SQL_ID or HASH_VALUE or
• -- Check trace file
•
• cd sqlt
• sqlplus sh/sh
• SQL> @run/sqltxtract.sql 2751883218
•
• hv=2751883218 ad='92da13d4' sqlid='5y7bskyk0ctyk‘
• @run/sqltxtract.sql 2751883218 Or
• @run/sqltxtract.sql 5y7bskyk0ctyk
SQLT- SQLTXPLAIN
DEMO 6 - XECUTE
Input: Single SQL statement• cd sqlt
• sqlplus sh/sh
• SQL> @run/sqltxecute.sql ../TJ_Test1.sql
Oracle Active Report- Real-Time SQL Monitoring
New in 11gR2
EM function via DBMS_SQLTUNE
Extract session/SQL information and presents infomation in GUI/Adobe Flash
Needs internet connection
Good for database support. Able to capture and encapsulate all the information in one HTML report.
dbms_sqltune.report_sql_detaildbms_sqltune.report_sql_monitor.
Oracle Active Report- Real-Time SQL Monitoring
DEMO 7• cd “Active Report”
• sqlplus tjambu/tjambu
• SQL> @report_sql_monitor.sql
• SQL> @report_sql_detail.sql
Other Tools - TOAD
TOAD functionalities
Explain Plan customisation
Explain Plan comparison
Trace file browser
Tkprof utility
Summary There are different approaches to SQL tuning
We covered some less known tools
Which to choose depends on your particular situation
Do try out some of the newer tools
For feedback & discussion: [email protected]
xxxxxxx
XXX
Xxx
XXX
XXX
1. Texas Memory Systems , http://www.superssd.com/whitepapers.htm
http://www.texmemsys.com/files/whitepaper_opera.pdf
2. Anand Tech,http://anandtech.com/storage/showdoc.aspx?i=3631 http://www.anandtech.com/storage/showdoc.aspx?i=3531&p=1
3. StorageSearch.com/SolidData, http://www.storagesearch.com/soliddata-art2-comparisons.pdf
References & Acknowledgement
Session: 715 Title: Understanding Solid State Drives (SSD)
Technology for Databases,Presenter: Tony Jambu
For feedback & discussion: [email protected]
Please fill in the evaluation form.
Q.What did we do to reduce the End of Fin year processing from 2days to 4 hours?
ANSWER
Select Star Mailing listhttp://groups.yahoo.com/group/Select_Star/
or email [email protected]