Doug Burns

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Doug Burns

 Introduction
 Architecture
 Command Line Approach
 GUI Approach
 Conclusions and References

03/04/2013
 Real Time SQL Monitoring is the killer performance analysis
feature of Oracle 11g
 Majority of database performance problems turn out to be SQL
performance problems
 Easily understandable view of SQL performance
 Shows actual SQL statement processing steps, unlike EXPLAIN PLAN
▪ Or that damn ambulance button in TOAD, prior to version 11.5!
▪ See http://tinyurl.com/c66hubl and http://tinyurl.com/bq7agq7

 First introduced in 11.1 and improved in 11.2

 Today’s examples are from 11.2


03/04/2013
 Introduction
 Architecture
 Command Line Approach
 GUI Approach
 SQL Monitor in other tools
 Conclusions and References

03/04/2013
 An RDBMS instrumentation feature
 You do not have to use OEM or any other specific tool
 Built on existing instrumentation – e.g. Plan execution stats and ASH

 Requires the Tuning Pack for the database instance you're


monitoring
 Which implies both Enterprise Edition and Diagnostics Pack

 SQL Monitoring records information automatically for


 Statements that run for more than 5 seconds (simplification)
 Statements that use parallelism
 Statements that have a /*+ MONITOR */ hint (there’s a NO_MONITOR
hint too)

03/04/2013
 (G)V$SQL_MONITOR & (G)V$SQL_PLAN_MONITOR
 Up-front warning – “Use the GUI, don’t use V$SQL_MONITOR”
 If you don’t have the GUI … be careful about your queries and results

 Very useful information though


 User and Session Information
 Actual Rows Processed vs Estimated Cardinalities
 Stats – Executing / Done / Error
 Various Timings – Elapsed, Wait Classes
 Degree of Parallelism

 Uses lots of other views too


 V$SESSION_LONGOPS, V$ACTIVE_SESSION_HISTORY, V$SQL_PLAN etc.

03/04/2013
 Useful for identifying statements of interest, but as long as
you have enough information to clearly identify statement
you’re interested in, that’s all you really need for the next
part.

select status, sql_id, last_refresh_time,


sql_exec_start, sql_exec_id, inst_id,
sql_text
from gv$sql_monitor
order by last_refresh_time desc;

03/04/2013
 Introduction
 Architecture
 Command Line Approach
 GUI Approach
 Conclusions and References

03/04/2013
 This approach is great if you have no OEM access
 Implemented by the DBMS_SQLTUNE package
 Example of a DBMS_XPLAN.DISPLAY_CURSOR equivalent
 Will generate a plain text version of the report for the last SQL statement
executed if monitored. (Add a MONITOR hint if you need to)
set trimspool on
set trim on
set pages 0
set linesize 1000
set long 1000000
set longchunksize 1000000
select dbms_sqltune.report_sql_monitor(type=>'TEXT') from dual

spool example_1.txt
/
spool off

03/04/2013
 If you’ve identified the SQL_ID you’re interested in you have
several options

 Text report (previous slide) or maybe an HTML report?

set trimspool on
set trim on
set pages 0
set linesize 1000
set long 1000000
set longchunksize 1000000
select dbms_sqltune.report_sql_monitor(
sql_id=>'51cmd19nphmm7', type=>'HTML') from dual

spool example_2.html
/
spool off

03/04/2013
 This one rocks

set trimspool on
set trim on
set pages 0
set linesize 1000
set long 1000000
set longchunksize 1000000
select dbms_sqltune.report_sql_monitor(sql_id=>'51cmd19nphmm7',
type=>'ACTIVE')
from dual

spool example_3.htm
/
spool off

03/04/2013
 Flash!
 Connects to OTN to pull components
 Or can be stored locally and referenced via base_path parameter

 Can be saved, mailed to other users and they’ll be able to drill


down into the details too
 Tons of information on different tabs, including
 Timeline of the query including when various plan steps were actually
running.
 Actual rows processed as well as estimated cardinalities
 Lots of PX detail
 Graphical Execution Plan*
 Metrics*
 Temp space used*

03/04/2013
 Introduction
 Architecture
 Command Line Approach
 GUI Approach
 Conclusions and References

03/04/2013
 The best way to investigate statements running currently
 Available in OEM DB Control 11g, OEM Grid Control 10.2.0.5 and OEM
Cloud Control 12c for 11g targets
 Various access paths – look for SQL Monitoring

03/04/2013
03/04/2013
03/04/2013
03/04/2013
03/04/2013
03/04/2013
 Refresh Issues
 Stop Refresh button!

 Information Retention
 You'll be so excited and come to depend on RTSM
 Look at performance of a statement that ran yesterday
 Select 'Active in last' to 24 hours or ALL
 Statement still doesn't appear

 What is retention period


 AWR Retention? X
 ASH Buffers? X
 Something else ...

03/04/2013
Name Description Default

_sqlmon_max_plan Maximum number of plans that can be 20 per CPU


monitored.

_sqlmon_max_planlines Number of lines beyond which a plan can not 300


be monitored

_sqlmon_recycle_time Minimum time to wait (in seconds) before a 60


plan can be recycled

_sqlmon_threshold CPU/IO time (in seconds) before a statement 5 (0 would


is monitored disable SQL
Monitoring)

03/04/2013
 Bug Number 14117966
 If any of the slaves in a Parallel Query is Idle for a long period of time
(30 minutes)
 Even if others are Active
 Statement is marked as errored

 For extremely long-running statements (hours and hours)


 Data not available for first (x) hours

03/04/2013
 ACTIVE report in OEM Grid Control 10.2.0.5 is limited
compared to Command-Line report
 No Plan or Metrics tabs

 Included in OEM DB Control that comes with 11.2 databases


and OEM 12c

 Having identified statement in OEM, use command line


approach to generate ACTIVE report.
 Default report_level of ‘TYPICAL’ is fine

03/04/2013
 Introduction
 Architecture
 Command Line Approach
 GUI Approach
 Conclusions and References

03/04/2013
 EXPLAIN PLAN

 DBMS_XPLAN with proper predicates

 DBMS_XPLAIN with Plan Execution Statistics

 Real Time SQL Monitoring


 Monitor statements that are running or ran in the recent past
 Real activity
 Real row counts
 Parallel Details

03/04/2013
 ... once you use it, there's no going back

 Every person I've shown it to has loved it

 Not just for DBAs or OEM users


 Command line approach allows you to use any tool
 SQLDeveloper includes SQL Monitoring too
 Just remember that you need the appropriate licenses!

03/04/2013
 REPORT_SQL_MONITOR function specification
http://tinyurl.com/a9l7p5e

 REPORT_SQL_MONITOR_LIST function specification


http://tinyurl.com/agvgovr

 White Paper (2009)


http://tinyurl.com/azvjr7b

 Bug with Idle PQ Slaves


http://tinyurl.com/avxv856

03/04/2013
 OTN page about ACTIVE reports
 Several examples you can play around with
 More technical details not covered in this presentation
 FAQ section

http://tinyurl.com/9wwtncz

 Thanks
 Benoit Dageville (Formerly Oracle Corp.)
 John Beresniewicz (Oracle Corp)
 Lisa Dobson

03/04/2013
Doug Burns

You might also like