SlideShare a Scribd company logo
How a Developer Can Troubleshoot
a SQL Performing Poorly on a
Production DB
Carlos Sierra
• Oracle Performance and SQL Tuning
• Consultant/Developer/DBA
• eDB360 and eAdam
• SQLT and SQLHC
• Exadata
Carlos Sierra
Enkitec (c) 2014 2
Motivation
• Developers might need to do SQL Tuning
• Diagnostics Collection is key for SQL Tuning
• Developers have limited access to DB server
– OEM is usually off limits
• Developers need reliable SQL Tuning tools
• Developers need to learn about these tools
11/4/2014 Enkitec © 3
Common SQL Troubleshooting Steps
1. Implement proper code instrumentation
2. Find application SQL performing poorly
3. Gather diagnostics on SQL of concern
4. Determine root cause of poor performance
5. Fix root cause
11/4/2014 Enkitec © 4
Code Instrumentation
• Data elements available
– Service
– Client Identifier
– Client Info
– Module
– Action
• Data type and size: VARCHAR2(64)
11/4/2014 Enkitec © 5
Query Session Values
11/4/2014 Enkitec © 6
Service (1)
• Database logical name(s) set per instance
• GV$SYSTEM_PARAMETER2 “service_names”
11/4/2014 Enkitec © 7
Service (2)
• Service SYS$BACKGROUND
– Background Processes
• Service SYS$USERS
– Default when session is not associated to Service
• Package DBMS_SERVICE
– Start, stop, create, delete, modify, disconnect
11/4/2014 Enkitec © 8
PL/SQL Instrumentation APIs
• DBMS_SESSION.SET_IDENTIFIER
– Sets CLIENT_IDENTIFIER
• DBMS_APPLICATION_INFO.SET_CLIENT_INFO
– Sets CLIENT_INFO
• DBMS_APPLICATION_INFO.SET_MODULE
– Sets MODULE and ACTION
11/4/2014 Enkitec © 9
API usage Example for PL/SQL
• Set before application code
• Reset after application code and error
handling
11/4/2014 Enkitec © 10
Query V$ to finding SQL
• GV$SESSION
– Session Status
– Service, Module, Action, Client, User
• GV$SQL
– SQL Text
– Elapsed Time
11/4/2014 Enkitec © 11
Active SQL Statements
11/4/2014 Enkitec © 12
Some “safe” Diagnostics Tools
• SQL Trace and TKPROF
• Execution Plan and DBMS_XPLAN
• planx.sql, sqlmon.sql and sqlash.sql
• snapper.sql
• SQLHC and SQLTXPLAIN
11/4/2014 Enkitec © 13
Tracing Methods
• ALTER SESSION
– SQL_TRACE parameter
– Event 10046
• DBMS_SESSION
• DBMS_MONITOR (preferred)
• ORADEBUG
– Event 10046
11/4/2014 Enkitec © 14
SQL_TRACE Syntax
• ALTER SESSION SET SQL_TRACE = TRUE;
• ALTER SESSION SET SQL_TRACE = FALSE;
• Own Session
11/4/2014 Enkitec © 15
Event 10046 Syntax
• ALTER SESSION SET EVENTS '10046 TRACE
NAME CONTEXT FOREVER, LEVEL N';
• ALTER SESSION SET EVENTS '10046 TRACE
NAME CONTEXT OFF';
• Own Session
11/4/2014 Enkitec © 16
Event 10046 Levels
• 1: Performance metrics and Execution Plan metrics
– 10g: Execution Plan metrics for all executions
– 11g: Execution Plan metrics for 1st execution
• 4: Binds
• 8: Waits
• 16: Execution Plan metrics for each execution (11.1+)
• 64: Execution Plan metrics for 1st then each with DB
Time > 1min (11.2.0.2+)
11/4/2014 Enkitec © 17
Event 10046 Level Examples
• Execution Plan metrics + Binds + Waits
– Level 4 + 8 = 12
• 11.1+: Execution Plan metrics for 1st execution
• 10g: Execution Plan metrics for all executions
• Binds + Waits + 1st Exec + >1m Execs
– Level 4 + 8 + 64 = 76
• 11.2.0.2+
11/4/2014 Enkitec © 18
DBMS_SESSION APIs
• SESSION_TRACE_ENABLE
– waits (TRUE|FALSE)
– binds (FALSE|TRUE)
– plan_stat (FIRST_EXECUTION|ALL_EXECUTIONS)
• SESSION_TRACE_DISABLE
• Own Session
11/4/2014 Enkitec © 19
DBMS_MONITOR APIs
• Enable SQL Trace
– SERV_MOD_ACT_TRACE_ENABLE
– CLIENT_ID_TRACE_ENABLE
– SESSION_TRACE_ENABLE
• ENABLE and DISABLE versions
• TRACE and STAT versions
11/4/2014 Enkitec © 20
SERV_MOD_ACT_TRACE_ENABLE
• service_name (required)
• module_name (optional)
• action_name (optional)
• waits (TRUE|FALSE)
• binds (FALSE|TRUE)
• plan_stat (FIRST_EXECUTION|ALL_EXECUTIONS)
11/4/2014 Enkitec © 21
CLIENT_ID_TRACE_ENABLE
• client_id (required)
• waits (TRUE|FALSE)
• binds (FALSE|TRUE)
• plan_stat
– FIRST_EXECUTION|ALL_EXECUTIONS
11/4/2014 Enkitec © 22
SESSION_TRACE_ENABLE
• session_id (if null then own else sid)
• serial_num (if null then use sid only)
• waits (TRUE|FALSE)
• binds (FALSE|TRUE)
• plan_stat
– FIRST_EXECUTION|ALL_EXECUTIONS
11/4/2014 Enkitec © 23
Some related Views
• Active Tracing
– DBA_ENABLED_TRACES
• Collected Statistics
– V$SERV_MOD_ACT_STATS
– V$CLIENT_STATS
– V$SESSTAT
11/4/2014 Enkitec © 24
Trace Location
• 11g
– V$DIAG_INFO
– Name = 'Diag Trace'
• 10g
– V$PARAMETER2
– Name = 'user_dump_dest'
11/4/2014 Enkitec © 25
TKPROF Syntax
• tkprof tracefile outputfile [sort=option]
• sort=prsela fchela exeela
11/4/2014 Enkitec © 26
TKPROF Sample
11/4/2014 Enkitec © 27
TKPROF Execution Plan Sample
11/4/2014 Enkitec © 28
DBMS_XPLAN Table Functions
• DISPLAY
• DISPLAY_AWR
• DISPLAY_CURSOR
• DISPLAY_PLAN
• DISPLAY_SQL_PLAN_BASELINE
• DISPLAY_SQLSET
11/4/2014 Enkitec © 29
DBMS_XPLAN.DISPLAY_CURSOR
• sql_id (default: last executed session cursor)
• cursor_child_no (default: 0)
• format (default: typical)
– allstats (io and mem stats for all executions)
– allstats last (ditto for last execution)
– advanced (includes outline) both undocumented
11/4/2014 Enkitec © 30
11/4/2014 Enkitec © 31
11/4/2014 Enkitec © 32
11/4/2014 Enkitec © 33
11/4/2014 Enkitec © 34
planx.sql
• Installs nothing
• 10g and 11g
• Parameters
– Oracle Diagnostics Pack License? Y | N
– SQL_ID
• Free
11/4/2014 Enkitec © 35
planx.sql Execution Plan
• DBMS_XPLAN.DISPLAY
– GV$SQL_PLAN_STATISTICS_ALL
– ADVANCED ALLSTATS LAST
• DBMS_XPLAN.DISPLAY_AWR
– ADVANCED
11/4/2014 Enkitec © 36
planx.sql Views (1)
• GV$SQLSTATS (extended retention)
• GV$SQLSTATS_PLAN_HASH
• GV$SQL
• GV$ACTIVE_SESSION_HISTORY
11/4/2014 Enkitec © 37
planx.sql Views (2)
• DBA_HIST_SQLSTAT
• DBA_HIST_SQL_PLAN
• DBA_HIST_ACTIVE_SESS_HISTORY
11/4/2014 Enkitec © 38
planx.sql Views (3)
• DBA_TABLES
• DBA_INDEXES
• DBA_TAB_COLS
• DBA_IND_COLS
11/4/2014 Enkitec © 39
11/4/2014 Enkitec © 40
11/4/2014 Enkitec © 41
11/4/2014 Enkitec © 42
11/4/2014 Enkitec © 43
sqlmon.sql
• Installs nothing
• 10g and 11g
• Parameters
– Oracle Tuning Pack (required) License? Y | N
– SQL_ID
• Free
11/4/2014 Enkitec © 44
sqlmon.sql Output
• SQL Monitor Reports
– HTML
– Text
– List
– Detail
11/4/2014 Enkitec © 45
11/4/2014 Enkitec © 46
11/4/2014 Enkitec © 47
SQL Monitor Execution Plan
11/4/2014 Enkitec © 48
sqlash.sql
• Installs nothing
• 10g and 11g
• Parameters
– Oracle Diagnostics Pack (required) License? Y | N
– SQL_ID
• Free
11/4/2014 Enkitec © 49
sqlash.sql Output
• ASH Reports for one SQL
– Format
• HTML
• Text
– Source
• Memory
• AWR
11/4/2014 Enkitec © 50
11/4/2014 Enkitec © 51
Snapper
• Session Centric
• Installs nothing
• 10g and 11g
• 4 Parameters
• Does not require Diagnostics or Tuning Pack
• Free
Enkitec © 2014 52
Snapper Syntax
• Scope (‘all’ includes ASH and Stats)
• seconds_in_snap (30 is common)
• snap_count (between 1 and 5 are common)
• sid (session id)
• Execution Sample
– @snapper.sql all 30 1 50
11/4/2014 Enkitec © 53
11/4/2014 Enkitec © 54
SQLHC 1366133.1
• Installs nothing
• 10g and 11g
• Parameters
– Oracle Pack License? T | D | N
– SQL_ID
• Free (requires MOS account)
11/4/2014 Enkitec © 55
11/4/2014 Enkitec © 56
SQLTXPLAIN (SQLT) 215187.1
• Installs two schemas and many objects
• 10g and 11g
• Methods
– SQLT XTRACT (inputs SQL_ID)
– SQLT XECUTE (inputs SQL Text)
• Free (requires MOS account)
11/4/2014 Enkitec © 57
11/4/2014 Enkitec © 58
Summary
1. Implement proper code instrumentation
2. Find application SQL performing poorly
3. Gather diagnostics on SQL of concern
4. Determine root cause of poor performance
5. Fix root cause
11/4/2014 Enkitec © 59
References
• Oracle Documentation
• http://blog.tanelpoder.com/files/scripts/snap
per.sql
• http://carlos-sierra.net/ (look for cscripts)
• SQL Health-Check (SQLHC): MOS 1366133.1
• SQLXPLAIN (SQLT): MOS 215187.1
11/4/2014 Enkitec © 60
Contact Information
• carlos.sierra@enkitec.com
• carlos-sierra.net
• @csierra_usa
Enkitec (c) 2014 61

More Related Content

What's hot (20)

Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014
John Beresniewicz
 
AWR and ASH Deep Dive
AWR and ASH Deep DiveAWR and ASH Deep Dive
AWR and ASH Deep Dive
Kellyn Pot'Vin-Gorman
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Carlos Sierra
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention Troubleshooting
Tanel Poder
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
Mauro Pagano
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Carlos Sierra
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Tanel Poder
 
ASH and AWR on DB12c
ASH and AWR on DB12cASH and AWR on DB12c
ASH and AWR on DB12c
Kellyn Pot'Vin-Gorman
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Carlos Sierra
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
Carlos Sierra
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
Carlos Sierra
 
AWR & ASH Analysis
AWR & ASH AnalysisAWR & ASH Analysis
AWR & ASH Analysis
aioughydchapter
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
Mauro Pagano
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automation
Carlos Sierra
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12c
Tanel Poder
 
SQLd360
SQLd360SQLd360
SQLd360
Mauro Pagano
 
Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014
John Beresniewicz
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Carlos Sierra
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention Troubleshooting
Tanel Poder
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
Mauro Pagano
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Carlos Sierra
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Tanel Poder
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Carlos Sierra
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
Carlos Sierra
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
Mauro Pagano
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automation
Carlos Sierra
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12c
Tanel Poder
 

Similar to How a Developer can Troubleshoot a SQL performing poorly on a Production DB (20)

Free oracle performance tools
Free oracle performance toolsFree oracle performance tools
Free oracle performance tools
Rogerio Bacchi Eguchi
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
Carlos Sierra
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
Carlos Sierra
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
Pini Dibask
 
SQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsSQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVs
Franklin Yamamoto
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdfsqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
TricantinoLopezPerez
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases fasterAdvanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
SolarWinds
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
Pini Dibask
 
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Carlos Sierra
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdfO_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query TuningMicrosoft SQL Server Query Tuning
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
SQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden childSQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden child
Carlos Sierra
 
Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
jucaab
 
SQL TUNING 101
SQL TUNING 101SQL TUNING 101
SQL TUNING 101
Alex Zaballa
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
jucaab
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
Navneet Upneja
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
Carlos Sierra
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
Carlos Sierra
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
Pini Dibask
 
SQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsSQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVs
Franklin Yamamoto
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases fasterAdvanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
SolarWinds
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
Pini Dibask
 
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Carlos Sierra
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdfO_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
Mao Geng
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query TuningMicrosoft SQL Server Query Tuning
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
SQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden childSQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden child
Carlos Sierra
 
Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
jucaab
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
jucaab
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
Navneet Upneja
 

Recently uploaded (20)

Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Rebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core FoundationRebuilding Cadabra Studio: AI as Our Core Foundation
Rebuilding Cadabra Studio: AI as Our Core Foundation
Cadabra Studio
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines OperationsHow Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 

How a Developer can Troubleshoot a SQL performing poorly on a Production DB

  • 1. How a Developer Can Troubleshoot a SQL Performing Poorly on a Production DB Carlos Sierra
  • 2. • Oracle Performance and SQL Tuning • Consultant/Developer/DBA • eDB360 and eAdam • SQLT and SQLHC • Exadata Carlos Sierra Enkitec (c) 2014 2
  • 3. Motivation • Developers might need to do SQL Tuning • Diagnostics Collection is key for SQL Tuning • Developers have limited access to DB server – OEM is usually off limits • Developers need reliable SQL Tuning tools • Developers need to learn about these tools 11/4/2014 Enkitec © 3
  • 4. Common SQL Troubleshooting Steps 1. Implement proper code instrumentation 2. Find application SQL performing poorly 3. Gather diagnostics on SQL of concern 4. Determine root cause of poor performance 5. Fix root cause 11/4/2014 Enkitec © 4
  • 5. Code Instrumentation • Data elements available – Service – Client Identifier – Client Info – Module – Action • Data type and size: VARCHAR2(64) 11/4/2014 Enkitec © 5
  • 7. Service (1) • Database logical name(s) set per instance • GV$SYSTEM_PARAMETER2 “service_names” 11/4/2014 Enkitec © 7
  • 8. Service (2) • Service SYS$BACKGROUND – Background Processes • Service SYS$USERS – Default when session is not associated to Service • Package DBMS_SERVICE – Start, stop, create, delete, modify, disconnect 11/4/2014 Enkitec © 8
  • 9. PL/SQL Instrumentation APIs • DBMS_SESSION.SET_IDENTIFIER – Sets CLIENT_IDENTIFIER • DBMS_APPLICATION_INFO.SET_CLIENT_INFO – Sets CLIENT_INFO • DBMS_APPLICATION_INFO.SET_MODULE – Sets MODULE and ACTION 11/4/2014 Enkitec © 9
  • 10. API usage Example for PL/SQL • Set before application code • Reset after application code and error handling 11/4/2014 Enkitec © 10
  • 11. Query V$ to finding SQL • GV$SESSION – Session Status – Service, Module, Action, Client, User • GV$SQL – SQL Text – Elapsed Time 11/4/2014 Enkitec © 11
  • 13. Some “safe” Diagnostics Tools • SQL Trace and TKPROF • Execution Plan and DBMS_XPLAN • planx.sql, sqlmon.sql and sqlash.sql • snapper.sql • SQLHC and SQLTXPLAIN 11/4/2014 Enkitec © 13
  • 14. Tracing Methods • ALTER SESSION – SQL_TRACE parameter – Event 10046 • DBMS_SESSION • DBMS_MONITOR (preferred) • ORADEBUG – Event 10046 11/4/2014 Enkitec © 14
  • 15. SQL_TRACE Syntax • ALTER SESSION SET SQL_TRACE = TRUE; • ALTER SESSION SET SQL_TRACE = FALSE; • Own Session 11/4/2014 Enkitec © 15
  • 16. Event 10046 Syntax • ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT FOREVER, LEVEL N'; • ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT OFF'; • Own Session 11/4/2014 Enkitec © 16
  • 17. Event 10046 Levels • 1: Performance metrics and Execution Plan metrics – 10g: Execution Plan metrics for all executions – 11g: Execution Plan metrics for 1st execution • 4: Binds • 8: Waits • 16: Execution Plan metrics for each execution (11.1+) • 64: Execution Plan metrics for 1st then each with DB Time > 1min (11.2.0.2+) 11/4/2014 Enkitec © 17
  • 18. Event 10046 Level Examples • Execution Plan metrics + Binds + Waits – Level 4 + 8 = 12 • 11.1+: Execution Plan metrics for 1st execution • 10g: Execution Plan metrics for all executions • Binds + Waits + 1st Exec + >1m Execs – Level 4 + 8 + 64 = 76 • 11.2.0.2+ 11/4/2014 Enkitec © 18
  • 19. DBMS_SESSION APIs • SESSION_TRACE_ENABLE – waits (TRUE|FALSE) – binds (FALSE|TRUE) – plan_stat (FIRST_EXECUTION|ALL_EXECUTIONS) • SESSION_TRACE_DISABLE • Own Session 11/4/2014 Enkitec © 19
  • 20. DBMS_MONITOR APIs • Enable SQL Trace – SERV_MOD_ACT_TRACE_ENABLE – CLIENT_ID_TRACE_ENABLE – SESSION_TRACE_ENABLE • ENABLE and DISABLE versions • TRACE and STAT versions 11/4/2014 Enkitec © 20
  • 21. SERV_MOD_ACT_TRACE_ENABLE • service_name (required) • module_name (optional) • action_name (optional) • waits (TRUE|FALSE) • binds (FALSE|TRUE) • plan_stat (FIRST_EXECUTION|ALL_EXECUTIONS) 11/4/2014 Enkitec © 21
  • 22. CLIENT_ID_TRACE_ENABLE • client_id (required) • waits (TRUE|FALSE) • binds (FALSE|TRUE) • plan_stat – FIRST_EXECUTION|ALL_EXECUTIONS 11/4/2014 Enkitec © 22
  • 23. SESSION_TRACE_ENABLE • session_id (if null then own else sid) • serial_num (if null then use sid only) • waits (TRUE|FALSE) • binds (FALSE|TRUE) • plan_stat – FIRST_EXECUTION|ALL_EXECUTIONS 11/4/2014 Enkitec © 23
  • 24. Some related Views • Active Tracing – DBA_ENABLED_TRACES • Collected Statistics – V$SERV_MOD_ACT_STATS – V$CLIENT_STATS – V$SESSTAT 11/4/2014 Enkitec © 24
  • 25. Trace Location • 11g – V$DIAG_INFO – Name = 'Diag Trace' • 10g – V$PARAMETER2 – Name = 'user_dump_dest' 11/4/2014 Enkitec © 25
  • 26. TKPROF Syntax • tkprof tracefile outputfile [sort=option] • sort=prsela fchela exeela 11/4/2014 Enkitec © 26
  • 28. TKPROF Execution Plan Sample 11/4/2014 Enkitec © 28
  • 29. DBMS_XPLAN Table Functions • DISPLAY • DISPLAY_AWR • DISPLAY_CURSOR • DISPLAY_PLAN • DISPLAY_SQL_PLAN_BASELINE • DISPLAY_SQLSET 11/4/2014 Enkitec © 29
  • 30. DBMS_XPLAN.DISPLAY_CURSOR • sql_id (default: last executed session cursor) • cursor_child_no (default: 0) • format (default: typical) – allstats (io and mem stats for all executions) – allstats last (ditto for last execution) – advanced (includes outline) both undocumented 11/4/2014 Enkitec © 30
  • 35. planx.sql • Installs nothing • 10g and 11g • Parameters – Oracle Diagnostics Pack License? Y | N – SQL_ID • Free 11/4/2014 Enkitec © 35
  • 36. planx.sql Execution Plan • DBMS_XPLAN.DISPLAY – GV$SQL_PLAN_STATISTICS_ALL – ADVANCED ALLSTATS LAST • DBMS_XPLAN.DISPLAY_AWR – ADVANCED 11/4/2014 Enkitec © 36
  • 37. planx.sql Views (1) • GV$SQLSTATS (extended retention) • GV$SQLSTATS_PLAN_HASH • GV$SQL • GV$ACTIVE_SESSION_HISTORY 11/4/2014 Enkitec © 37
  • 38. planx.sql Views (2) • DBA_HIST_SQLSTAT • DBA_HIST_SQL_PLAN • DBA_HIST_ACTIVE_SESS_HISTORY 11/4/2014 Enkitec © 38
  • 39. planx.sql Views (3) • DBA_TABLES • DBA_INDEXES • DBA_TAB_COLS • DBA_IND_COLS 11/4/2014 Enkitec © 39
  • 44. sqlmon.sql • Installs nothing • 10g and 11g • Parameters – Oracle Tuning Pack (required) License? Y | N – SQL_ID • Free 11/4/2014 Enkitec © 44
  • 45. sqlmon.sql Output • SQL Monitor Reports – HTML – Text – List – Detail 11/4/2014 Enkitec © 45
  • 47. 11/4/2014 Enkitec © 47 SQL Monitor Execution Plan
  • 49. sqlash.sql • Installs nothing • 10g and 11g • Parameters – Oracle Diagnostics Pack (required) License? Y | N – SQL_ID • Free 11/4/2014 Enkitec © 49
  • 50. sqlash.sql Output • ASH Reports for one SQL – Format • HTML • Text – Source • Memory • AWR 11/4/2014 Enkitec © 50
  • 52. Snapper • Session Centric • Installs nothing • 10g and 11g • 4 Parameters • Does not require Diagnostics or Tuning Pack • Free Enkitec © 2014 52
  • 53. Snapper Syntax • Scope (‘all’ includes ASH and Stats) • seconds_in_snap (30 is common) • snap_count (between 1 and 5 are common) • sid (session id) • Execution Sample – @snapper.sql all 30 1 50 11/4/2014 Enkitec © 53
  • 55. SQLHC 1366133.1 • Installs nothing • 10g and 11g • Parameters – Oracle Pack License? T | D | N – SQL_ID • Free (requires MOS account) 11/4/2014 Enkitec © 55
  • 57. SQLTXPLAIN (SQLT) 215187.1 • Installs two schemas and many objects • 10g and 11g • Methods – SQLT XTRACT (inputs SQL_ID) – SQLT XECUTE (inputs SQL Text) • Free (requires MOS account) 11/4/2014 Enkitec © 57
  • 59. Summary 1. Implement proper code instrumentation 2. Find application SQL performing poorly 3. Gather diagnostics on SQL of concern 4. Determine root cause of poor performance 5. Fix root cause 11/4/2014 Enkitec © 59
  • 60. References • Oracle Documentation • http://blog.tanelpoder.com/files/scripts/snap per.sql • http://carlos-sierra.net/ (look for cscripts) • SQL Health-Check (SQLHC): MOS 1366133.1 • SQLXPLAIN (SQLT): MOS 215187.1 11/4/2014 Enkitec © 60
  • 61. Contact Information • [email protected] carlos-sierra.net • @csierra_usa Enkitec (c) 2014 61