SlideShare a Scribd company logo
1 of 61
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

Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Carlos Sierra
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningYogiji Creations
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explainedMauro Pagano
 
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
 
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
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuningGuy Harrison
 
Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)Tanel Poder
 
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 2Tanel Poder
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by exampleMauro Pagano
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cTanel Poder
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptChien Chung Shen
 
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 fundamentalsJohn Beresniewicz
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerAndrejs Vorobjovs
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Kyle Hailey
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Supportnkarag
 
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 beginnersCarlos Sierra
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder
 

What's hot (20)

Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 
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...
 
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...
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)Tanel Poder Oracle Scripts and Tools (2010)
Tanel Poder Oracle Scripts and Tools (2010)
 
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
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12c
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
 
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
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource Manager
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
 
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
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 

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

Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 ToolCarlos Sierra
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 ToolCarlos Sierra
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeEnkitec
 
20150110 my sql-performanceschema
20150110 my sql-performanceschema20150110 my sql-performanceschema
20150110 my sql-performanceschemaIvan Ma
 
MySQL Enterprise Portfolio
MySQL Enterprise PortfolioMySQL Enterprise Portfolio
MySQL Enterprise PortfolioAbel Flórez
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeEnkitec
 
Application High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateApplication High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateShane Borden
 
Getting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteGetting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteaioughydchapter
 
Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)pasalapudi123
 
Oracle SQL Developer for the DBA
Oracle SQL Developer for the DBAOracle SQL Developer for the DBA
Oracle SQL Developer for the DBAJeff Smith
 
IOUG at Coors Field ASH and AWR in EM12c!
IOUG at Coors Field ASH and AWR in EM12c!IOUG at Coors Field ASH and AWR in EM12c!
IOUG at Coors Field ASH and AWR in EM12c!Kellyn Pot'Vin-Gorman
 
SQL Tuning made easier with SQLTXPLAIN (SQLT)
SQL Tuning made easier with SQLTXPLAIN (SQLT)SQL Tuning made easier with SQLTXPLAIN (SQLT)
SQL Tuning made easier with SQLTXPLAIN (SQLT)Carlos Sierra
 
Using MySQL Enterprise Monitor for Continuous Performance Improvement
Using MySQL Enterprise Monitor for Continuous Performance ImprovementUsing MySQL Enterprise Monitor for Continuous Performance Improvement
Using MySQL Enterprise Monitor for Continuous Performance ImprovementMark Matthews
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMayank Prasad
 
Sql tuning tools of the trade
Sql tuning tools of the tradeSql tuning tools of the trade
Sql tuning tools of the tradeEnkitec
 
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMayank Prasad
 
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration Utility
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration UtilityOracle Warehouse Builder to Oracle Data Integrator 12c Migration Utility
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration UtilityNoel Sidebotham
 
Primavera P6 Tips and Tricks
Primavera P6 Tips and TricksPrimavera P6 Tips and Tricks
Primavera P6 Tips and Tricksp6academy
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Enkitec
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperJeff Smith
 

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

Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
20150110 my sql-performanceschema
20150110 my sql-performanceschema20150110 my sql-performanceschema
20150110 my sql-performanceschema
 
MySQL Enterprise Portfolio
MySQL Enterprise PortfolioMySQL Enterprise Portfolio
MySQL Enterprise Portfolio
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the Trade
 
Application High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateApplication High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGate
 
Getting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteGetting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suite
 
Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)
 
Oracle SQL Developer for the DBA
Oracle SQL Developer for the DBAOracle SQL Developer for the DBA
Oracle SQL Developer for the DBA
 
IOUG at Coors Field ASH and AWR in EM12c!
IOUG at Coors Field ASH and AWR in EM12c!IOUG at Coors Field ASH and AWR in EM12c!
IOUG at Coors Field ASH and AWR in EM12c!
 
SQL Tuning made easier with SQLTXPLAIN (SQLT)
SQL Tuning made easier with SQLTXPLAIN (SQLT)SQL Tuning made easier with SQLTXPLAIN (SQLT)
SQL Tuning made easier with SQLTXPLAIN (SQLT)
 
Using MySQL Enterprise Monitor for Continuous Performance Improvement
Using MySQL Enterprise Monitor for Continuous Performance ImprovementUsing MySQL Enterprise Monitor for Continuous Performance Improvement
Using MySQL Enterprise Monitor for Continuous Performance Improvement
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasia
 
Sql tuning tools of the trade
Sql tuning tools of the tradeSql tuning tools of the trade
Sql tuning tools of the trade
 
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
 
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration Utility
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration UtilityOracle Warehouse Builder to Oracle Data Integrator 12c Migration Utility
Oracle Warehouse Builder to Oracle Data Integrator 12c Migration Utility
 
Primavera P6 Tips and Tricks
Primavera P6 Tips and TricksPrimavera P6 Tips and Tricks
Primavera P6 Tips and Tricks
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)
 
All of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL DeveloperAll of the Performance Tuning Features in Oracle SQL Developer
All of the Performance Tuning Features in Oracle SQL Developer
 

Recently uploaded

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 

Recently uploaded (20)

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 

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 • carlos.sierra@enkitec.com • carlos-sierra.net • @csierra_usa Enkitec (c) 2014 61