24
(Obscure) Tools of the Trade for Tuning Oracle SQLs [email protected] Tony Jambu Melbourne, Australia

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

Embed Size (px)

DESCRIPTION

 

Citation preview

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

(Obscure) Tools of the Trade

for Tuning Oracle SQLs

[email protected]

Tony JambuMelbourne, Australia

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

Agenda• Tuning Methodology

• Generating Explain Plan & Tracing

• TRCSESS

• DBMS_XPLAN

• SQL*Plus and Autotrace

• TRCANLZR - Trace Analyzer

• SQLT - SQLTXPLAIN

• Oracle Active Report

• Other Tools

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

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

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

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

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

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

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

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‘.

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

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%’;

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

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

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

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!

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

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)

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

TRCA - TRACE ANALYZER

DEMO 3

Only need one SQL file to run from client

• cd trca/run• sqlplus sh/sh• @trcanlzr.sql TraceFiles.lis

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

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

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

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

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

SQLT- SQLTXPLAIN

DEMO 4 - XPLAIN

Input: Single SQL

• # cd sqlt

• # sqlplus sh/sh

• SQL> @run/sqltxplain.sql ../TJ_Test1.sql

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

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

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

SQLT- SQLTXPLAIN

DEMO 6 - XECUTE

Input: Single SQL statement• cd sqlt

• sqlplus sh/sh

• SQL> @run/sqltxecute.sql ../TJ_Test1.sql

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

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.

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

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

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

Other Tools - TOAD

TOAD functionalities

Explain Plan customisation

Explain Plan comparison

Trace file browser

Tkprof utility

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

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]

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

xxxxxxx

XXX

Xxx

XXX

XXX

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

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

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

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]

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