The Art and Science of Tracing

Similar documents
Art and Craft of Tracing

Toad as a SQL Tuning Tool. With Dan Hotka - Oracle ACE Director

Data Tracking: On the Hunt for Information About Your System

Oracle 1Z Oracle Database 11g Performance Tuning.

Resolving Latch Contention

Oracle Performance Tuning. Overview of performance tuning strategies

Tibero SQL Operations Plan Guide

Identifying Performance Problems in a Multitenant Environment

Should You Drop Indexes on Exadata?

How to find and fix your. application performance problem. Cary Millsap Method R Corporation and Accenture Enkitec Group

RAC for Beginners. Arup Nanda Longtime Oracle DBA (and a beginner, always)

Using Active Session History for Performance Tuning: Advanced Topics in Performance Diagnostics

RACifying Multitenant

Latches Demystified. What is a Latch. Longtime Oracle DBA. Arup Nanda. From Glossary in Oracle Manuals:

Configuring the Oracle Network Environment. Copyright 2009, Oracle. All rights reserved.

BACK TO THE BASICS AN OVERVIEW OF ORACLE TOOLS FOR TUNING Michael R. Ault- Burleson Consulting

Quo Vadis SQLTXPLAIN

Essential (free) Tools for DBA!

Oracle Database 11g: SQL Tuning Workshop

Exadata for Oracle DBAs. Arup Nanda Longtime Oracle DBA (and now DMA)

Arup Nanda Longtime Oracle DBA (and now DMA)

1z0-064.exam.57q. Number: 1z0-064 Passing Score: 800 Time Limit: 120 min File Version: 1. Oracle 1z0-064

Networking for the Cloud DBA. Arup Nanda Longtime Oracle DBA And Explorer of New Things

Managing an Oracle Instance

Tuning SQL without the Tuning Pack. John Larkin JP Morgan Chase

Database Administration and Management

Location Agnostic Data

Performance Problems

How Can I Tune it if I Can t Change the Code

April 22-26, 2012 Mandalay Bay Convention Center Las Vegas, Nevada, USA. How Oracle Locking Works Session 889 Arup Nanda Longtime Oracle DBA

Instrumentation An Essential Ingredient for Performance Tuning

using PL/SQL and APEX

Minimizing the Concurrency Footprint of Transactions. Mark W. Farnham Rightsizing, Inc.

Multitenant Databases. Arup Nanda Longtime Oracle DBA

Python for Oracle. Oracle Database Great for Data Store. Critical for Business Operations. Performance? Run in laptop? But how do you share it?

Oracle SQL Tuning for Developers Workshop Student Guide - Volume I

APEX Performance Analyse

Lab 2: Installation of Oracle XE & SOA11g

Oracle 9i Application Development and Tuning

Oracle 1Z0-054 Exam Questions and Answers (PDF) Oracle 1Z0-054 Exam Questions 1Z0-054 BrainDumps

Infor LN Performance, Tracing, and Tuning Guide for Oracle

Oracle Database 10g The Self-Managing Database

Sqlplus To Create The Plan_table In Your Schema

Microservices using Python and Oracle. Arup Nanda Longtime Oracle DBA And Explorer of New Things

Oracle Architectural Components

Oracle EXAM - 1Z Oracle Database 11g: Performance Tuning. Buy Full Product.

Amazing Free Tools for Oracle DBAs. Matheus Boesing

IT100: Oracle Administration

Set Current Schema Command Oracle Sql Developer Alter Session

Installing and Configuring Oracle 10g Express Edition. for use with the ETM System

AMON User's Guide. Author: Andrej Simon Creation date: 11-Mar-2009 Last changed: 11-Aug-2010 AMON Version: 0.32

Join Methods. Franck Pachot CERN

Projects. Corporate Trainer s Profile. CMM (Capability Maturity Model) level Project Standard:- TECHNOLOGIES

Tablespace Usage By Schema In Oracle 11g Query To Check Temp

<Insert Picture Here> Looking at Performance - What s new in MySQL Workbench 6.2

Manage Change With Confidence: Upgrading to Oracle Database 11g with Oracle Real Application Testing

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Including Dynamic Images in Your Report

MyOra 6.0. SQL Tool for Oracle. User Guide

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database 11g: Program with PL/ SQL. Version: Demo

1z0-062.exam.215q 1z0-062 Oracle Database 12c: Installation and Administration

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

Apparo Fast Edit. Database configuration for the Apparo repository and others 1 / 20

Oracle - Oracle Database: Program with PL/SQL Ed 2

Oracle ILM Assistant Installation Guide Version 1.4

Real World Database Auditing. Stephen Kost Integrigy Corporation Session # 602

Anthony AWR report INTERPRETATION PART I

The Oracle SQLT Utility. By Kevin Gilpin, Rolta TUSC Wednesday March 14, 2012

Oracle PLSQL Training Syllabus

Arup Nanda VP, Data Services Priceline.com

Tuna Helper Proven Process for SQL Tuning. Dean Richards Senior DBA, Confio Software

ORACLE APPLICATIONS OS FOR DBAs SCRIPTS INTERVIEW QA. ASMSNMP user in ASM 11g (user creation/password

Using Oracle STATSPACK to assist with Application Performance Tuning

Oracle Application Express Schema Design Guidelines Presenter: Flavio Casetta, Yocoya.com

Oracle Application Express

Under the Hoods of Cache Fusion, GES, GRD and GCS

Optimize Oracle Business Intelligence Analytics with Oracle 12c In-Memory Database option

RECO CKPT SMON ARCH PMON RMAN DBWR

W HITE PAPER. VERITAS DBMS Technical Brief USING DBMS_SESSION AND DBMS_APPPLICATION_INFO BUILT-IN PACKAGES

Ensuring Optimal Performance. Vivek Sharma. 3 rd November 2012 Sangam 2012

Advanced Oracle Troubleshooting Live Session

Exam Name: Oracle Database 11g: Performance Tuning

Oracle Database 12c Anger Management for DBAs. Hans Forbrich Forbrich Consulting Ltd.

Upgrade Oracle Applications from to R12.1.1

Hacking Oracle's Memory About Internals & Troubleshooting

Oracle Database: Program with PL/SQL

Under the Hoods of Cache Fusion, GES, GRD and GCS

Resolving Child Cursor Issues Resulting In Mutex Waits

Oracle Sql Describe Schema Query To Find Table

Oracle Database: Program with PL/SQL Ed 2

TECHNOLOGY: Security Encrypting Tablespaces

Oracle Database 11g: SQL Tuning Workshop. Student Guide

Using Automatic Workload Repository for Database Tuning: Tips for Expert DBAs. Kurt Engeleiter Product Manager

IBM DB2 Query Patroller. Administration Guide. Version 7 SC

Oracle Database 11g: New Features for Oracle 9i DBAs

Oracle Database 12c R2: Program with PL/SQL Ed 2 Duration: 5 Days

A Practitioner's Guide to Optimizing Response Time. Optimizing. Oracle Performance. Cary Millsap with Jeff Holt

How to instrument your code easy and effectively

Conditionally control code flow (loops, control structures). Create stored procedures and functions.

Optimizer Plan Stability

Transcription:

The Art and Science of Tracing Session 971 Arup Nanda Longtime Oracle DBA Blog: arup.blogspot.com Twitter: @ArupNanda Facebook.com/ArupKNanda REMINDER Check in on the COLLABORATE mobile app

Agenda My session or application is slow, or not acceptable. Can you find out why? What is tracing Types of tracing Tracing in a current session Tools to analyze tracefiles Tracing a different session Tracing for future sessions Client Identifier and Client ID Tracing in RAC Consolidating tracefiles

What is Tracing? Execution plan tracing Enables inner workings of the session Queries executed Including recursive queries Details captured Execution plans Time spent Rows affected Parses, etc. Other type of trace: 10053 (CBO decision)

Simple Tracing All relevant information SQL> alter session set sql_trace = true; Must have alter session privilege Creates a tracefile in 10g user_dump_dest directory 11g ADR: <OracleBase>\diag\rdbms\<DBName>\<OracleSID>\trace Named <OracleSID>_ora_<spid>.trc Put a phrase in the name SQL> alter session set tracefile_identifier = arup; Named <OracleSID>_ora_<spid>_ARUP.trc

Analyze the Tracefile Oracle provided tool TKPROF $ tkprof ann1_ora_8420.trc ann1_ora_8420.out If you want execution plans: $ tkprof ann1_ora_8420.trc ann1_ora_8420.out explain=sh/sh If you want recursive SQLs $ tkprof ann1_ora_8420.trc ann1_ora_8420.out sys=yes The insert statements $ tkprof ann1_ora_8420.trc ann1_ora_8420.out insert=tki.sql All the statements $ tkprof ann1_ora_8420.trc ann1_ora_8420.out record=tkr.sql

tkprof Usage: tkprof tracefile outputfile [explain= ] [table= ] [print= ] [insert= ] [sys= ] [sort= ] table=schema.tablename Use 'schema.tablename' with 'explain=' option. explain=user/password Connect to ORACLE and issue EXPLAIN PLAN. print=integer List only the first 'integer' SQL statements. aggregate=yes no insert=filename List SQL statements and data inside INSERT statements. sys=no TKPROF does not list SQL statements run as user SYS. record=filename Record non-recursive statements found in the trace file. waits=yes no Record summary for any wait events found in the trace file. sort=option Set of zero or more of the following sort options: prscnt number of times parse was called prscpu cpu time parsing prsela elapsed time parsing prsdsk number of disk reads during parse prsqry number of buffers for consistent read during parse...

Extended Tracing Activity logging aka 10046 trace Enable it by alter session set events '10046 trace name context forever, level 8'; Levels 2 = the regular SQL trace 4 = puts the bind variables 8 = puts the wait information 12 = binds and waits 0 = turns off tracing

Extended Trace Example cursor Time from an epoch PARSING IN CURSOR #138513160 len=42 dep=0 uid=105 oct=3 lid=105 tim=95263807329 hv=4245958598 ad='7ff85847068' sqlid='0anpyjzyj8by6' select * from profits where cust_id = 5587 END OF STMT PARSE #138513160:c=0,e=53447,p=0,cr=2,cu=0,mis=1,r=0,dep=0,og=1,plh=4294955472,tim=95263807328 EXEC #138513160:c=0,e=438,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=4294955472,tim=95263807887 FETCH #138513160:c=0,e=966,p=0,cr=192,cu=0,mis=0,r=1,dep=0,og=1,plh=4294955472,tim=95263808954 FETCH #138513160:c=0,e=364,p=0,cr=81,cu=0,mis=0,r=15,dep=0,og=1,plh=4294955472,tim=95263809697 Number of rows

Analyzing Extended Traces Tkprof works too; but no extended information is shown Other options Trace Analyzer (Free. From My Oracle Support) Hotsos Profiler (paid) TVD$XTAT (Free. http://antognini.ch/downloads/tvdxtat_40beta9.zip)

Trace Analyzer A much better tool to analyze trace files. Refer to MetaLink Doc 224270.1 for download and instructions on use A small zip file, with bunch of directories Connect as SYS and run tacreate.sql to create the Trace Analyzer schema (TRCANLZR) Run it cd trca/run sqlplus trcanlzr/trcanlzr @trcanlzr <tracefile name in udump dir>

Output Value passed to trcanlzr.sql: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TRACE_FILENAME: D111D1_ora_9205.trc... analyzing D111D1_ora_9205.trc Trace Analyzer completed. Review first trcanlzr_error.log file for possible fatal errors. Review next trcanlzr_22881.log for parsing messages and totals.... copying now generated files into local directory TKPROF: Release 11.1.0.7.0 - Production on Wed Oct 28 11:45:05 2009 Copyright (c) 1982, 2007, Oracle. All rights reserved. adding: trcanlzr_22881_c.html (deflated 90%) adding: trcanlzr_22881_c.log (deflated 82%) adding: trcanlzr_22881_c.txt (deflated 84%) adding: trcanlzr_22881.tkprof (deflated 85%) adding: trcanlzr_error.log (deflated 72%) test of trcanlzr_22881.zip OK These files are produced in the local directory... trcanlzr_22881.zip has been created TRCANLZR completed.

Trace Analyzer It generates The log file of the run. Scan for errors. The tkprof output of the trace file The analysis in text format The analysis in html format

Enabling Trace in a Remote Session Find out the SID and Serial# Option 1 dbms_system.set_sql_trace_in_session (sid=>1, serial#=>1, sql_trace=>true); Set sql_trace to FALSE to stop Option 2 dbms_system.set_ev(si=>1, se=>1, ev=>10046, le=>8, nm=>' '); Set le to 0 to stop Option 3 dbms_support.start_trace_in_session (sid=>1, serial=>1, waits=>true, binds=>false); The package needs to be created $OH/rdbms/admin/dbmssupp.sql

ORADEBUG Oradebug (undocumented) Login as SYSDBA For the current session SQL> oradebug setmypid; For a different session. Get the OS PID SQL> oradebug setospid 1; SQL> oradebug event 10046 trace name context forever, level 8; To get the current tracefile name SQL> oradebug tracefile_name; To turn off tracing SQL> oradebug event 10046 trace name context off;

DBMS_MONITOR New in 10g begin dbms_monitor.session_trace_enable ( session_id =>1, serial_num =>1, waits =>true, binds =>true); Leave these to trace current session end; Execute session_trace_disable ( ) to disable

Individual SQL Statements To trace individual SQL Statements Get SQL_ID alter session set events 'trace[rdbms.sql_optimizer.*][sql: 0anpyjzyj8by6]'; Run the app Disable trace alter session set events 'trace[rdbms.sql_optimizer.*] off'; To get the SQL Trace only alter session set events 'sql_trace[sql: 0anpyjzyj8by6]'; Turn off alter session set events 'sql_trace off';

Connection Pools and RAC

The Connection Pool Effect Most applications use connection pool A pool of connections connected to the database When the demand on the connection from the pool grows, the pool creates new database sessions When the demand lessens, the sessions are disconnected The SID is not known Connection Pool Session1 Session2 Session3 DB

Enabling Tracing in Future Sessions Service Names start tracing when any session connected with that service name will be traced begin dbms_monitor.serv_mod_act_trace_enable ( service_name => 'APP', ); end; action_name waits => true, binds => true => dbms_monitor.all_actions, Warning: This is case sensitive; so app and APP are different. This will trace any session connected with service_name APP Even future sessions!

What s Special About RAC Multiple Instances multiple hosts The tracefiles are on different hosts Application connect through a connection pool Tracefile generated here Connection Pool Session1 Session2 Session3 Node1 Node2 Tracefile generated here

Multiple Tracefiles Tracefiles are generated for each Oracle session So, a single user s action can potentially go to many sessions many tracefiles Workaround: create only one session in the connection pool Connection Pool Session1 Node1 Node2 All tracefile generated here

Mixed Activities But that does not solve the problem The single Oracle session will service activities of many users So the tracefile will have activities of all users; not just the user you are interested in. User A User B Connection Pool Session1 Node1 Node2 A single tracefile is generated here for all users

Consolidation of Tracefiles The trcsess utility comes handy in that case It combines all tracefiles into one! trcsess output=alltraces.trc service=app *.trc It creates the tracefile alltraces.trc from all the tracefiles in that directory where activities by all sessions connected with the app service Now you can treat this new tracefile as a regular tracefile. $ tkprof alltraces.trc alltraces.out sys=no

Differentiating Among Apps

Client ID Set the Client ID Begin dbms_session.set_identifier('client1'); End; Check the Client ID select SYS_CONTEXT('userenv', 'client_identifier') from dual; For the session select client_identifier from v$session where username = 'SH';

Trace the Client ID Sessions Enable dbms_monitor.client_id_trace_enable ( client_id => CLIENT1', waits => true, binds => false ); Disable dbms_monitor.client_id_trace_disable ( client_id => CLIENT1' );

Module and Action Set Module dbms_application_info.set_module( module_name => 'MODULE1', action_name => 'ACTION1' ); Set subsequent actions dbms_application_info.set_action ('ACTION2'); dbms_application_info.set_action ('ACTION3');

Trace Module and Action Enable dbms_monitor.serv_mod_act_trace_enable( service_name=> APP', module_name=> MODULE1, action_name=> ACTION1', waits=>true, binds=>true ); Disable dbms_monitor.serv_mod_act_trace_disable( service_name=>'app', module_name=>'module1', action_name=>'action1');

TRCSESS The utility has many options trcsess [output=<output file name >] [session=<session ID>] [clientid=<clientid>] [service=<service name>] [action=<action name>] [module=<module name>] <trace file names> output=<output file name> output destination default being standard output. session=<session Id> session to be traced. Session id is a combination of SID and Serial# e.g. 8.13. clientid=<clientid> clientid to be traced. service=<service name> service to be traced. action=<action name> action to be traced. module=<module name> module to be traced.

Summary Two types of tracing Simple Extended, aka 10046 Several ways to invoke tracing Can start tracing on a different session Can set the tracing to trigger if one or more matches: Service Module Action Can analyze Tkprof Trace Analyzer Other Tools

Thank You! Session 971 Blog: arup.blogspot.com Twitter: @arupnanda Facebook.com/ArupKNanda