Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SQL TUNING 101

504 views

Published on

Presentation for the Oracle Code

Published in: Technology
  • Be the first to comment

  • Be the first to like this

SQL TUNING 101

  1. 1. SQL TUNING 101 Alex Zaballa
  2. 2. Copyright © 2016 Accenture All rights reserved. | 2 Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa https://www.linkedin.com/in/alexzaballa 275 and counting…
  3. 3. Copyright © 2016 Accenture All rights reserved. | 3 Worked for 3 years in Brazil as a Clipper/Delphi Developer (15 years old) 1997-1999 Worked for 7 years in Brazil as an Oracle Developer 2000 - 2007 Worked for 8 years in Angola as an Oracle DBA for the Ministry of Finance. 2007 - 2015
  4. 4. Copyright © 2016 Accenture All rights reserved. | 4
  5. 5. Copyright © 2016 Accenture All rights reserved. | 5 3 Membership Tiers • Oracle ACE Director • Oracle ACE • Oracle ACE Associate bit.ly/OracleACEProgram 500+ Technical Experts Helping Peers Globally Connect: Nominate yourself or someone you know: acenomination.oracle.com @oracleace Facebook.com/oracleaces oracle-ace_ww@oracle.com
  6. 6. Copyright © 2016 Accenture All rights reserved. | 6 SQL TUNING 101 Before start….
  7. 7. Copyright © 2016 Accenture All rights reserved. | 7 ORACLE DATABASE MULTILINGUAL ENGINE – BETA 12.2 Initial beta with JavaScript Stored Procedures http://www.oracle.com/technetwork/database/multiling ual-engine/overview/index.html
  8. 8. Copyright © 2016 Accenture All rights reserved. | 8 ORACLE DATABASE MULTILINGUAL ENGINE – BETA 12.2
  9. 9. Copyright © 2016 Accenture All rights reserved. | 9 ORACLE DATABASE MULTILINGUAL ENGINE – BETA 12.2
  10. 10. Copyright © 2016 Accenture All rights reserved. | 10 ORACLE DATABASE MULTILINGUAL ENGINE – BETA 12.2 http://www.oracle.com/technetwork/pt/articles/database- performance/odb-12-2-multilingual-4394909-ptb.html
  11. 11. Copyright © 2016 Accenture All rights reserved. | 11 https://livesql.oracle.com
  12. 12. Copyright © 2016 Accenture All rights reserved. | 12
  13. 13. Copyright © 2016 Accenture All rights reserved. | 13 OVERVIEW Database Tuning Vs SQL Tuning
  14. 14. Copyright © 2016 Accenture All rights reserved. | 14 OVERVIEW Developers vs SQL
  15. 15. Copyright © 2016 Accenture All rights reserved. | 15 TOM KYTE
  16. 16. Copyright © 2016 Accenture All rights reserved. | 16 SQL TUNING 101 Let’s begin….
  17. 17. Copyright © 2016 Accenture All rights reserved. | 17 SQL TUNING 101 The application is running slow today! Nothing has changed!
  18. 18. Copyright © 2016 Accenture All rights reserved. | 18 YES, SOMETHING HAS CHANGED • Database upgraded • Statistics gathered (automatic?) • Schema changed • Database parameter changed • Application changed • Operating system (OS) and hardware changed • Data volume changed • More active users
  19. 19. Copyright © 2016 Accenture All rights reserved. | 19 HOW TO START TROUBLESHOOTING? One SQL? All the database? ASH and AWR **Requires Oracle Diagnostics Pack
  20. 20. Copyright © 2016 Accenture All rights reserved. | 20 SQL TUNING Proactive
  21. 21. Copyright © 2016 Accenture All rights reserved. | 21 SQL TUNING Reactive
  22. 22. Copyright © 2016 Accenture All rights reserved. | 22 PROACTIVE – TOOLS
  23. 23. Copyright © 2016 Accenture All rights reserved. | 23 EDB360 - TOP SQLS
  24. 24. Copyright © 2016 Accenture All rights reserved. | 24 EDB360 - TOP EVENTS
  25. 25. Copyright © 2016 Accenture All rights reserved. | 25 EDB360 DEMO
  26. 26. Copyright © 2016 Accenture All rights reserved. | 26 AWR REPORT • SQL ordered by Elapsed Time • SQL ordered by CPU Time • SQL ordered by User I/O Wait Time • SQL ordered by Gets • SQL ordered by Reads • SQL ordered by Physical Reads (UnOptimized) • SQL ordered by Executions • SQL ordered by Parse Calls • SQL ordered by Sharable Memory • SQL ordered by Version Count • SQL ordered by Cluster Wait Time
  27. 27. Copyright © 2016 Accenture All rights reserved. | 27 AWR REPORT DEMO
  28. 28. Copyright © 2016 Accenture All rights reserved. | 28 REACTIVE - TOOLS
  29. 29. Copyright © 2016 Accenture All rights reserved. | 29 SQLT (SQLTXPLAIN) DIAGNOSTIC TOOL (DOC ID 215187.1) • Pros: Supported by Oracle • Cons: Requires Installation
  30. 30. Copyright © 2016 Accenture All rights reserved. | 30 SQLT (SQLTXPLAIN) DIAGNOSTIC TOOL (DOC ID 215187.1)
  31. 31. Copyright © 2016 Accenture All rights reserved. | 31 SQLD360 • Pros: No Installation • Cons: Might miss some information under rare circumstances
  32. 32. Copyright © 2016 Accenture All rights reserved. | 32 SQLTXPLAIN VS SQLD360 https://mauro-pagano.com/2017/04/29/sqltxplain-vs-sqld360-differences-and-similarities/
  33. 33. Copyright © 2016 Accenture All rights reserved. | 33 SQLD360 – HOW TO USE • Download the free tool: https://github.com/mauropagano/sqld360/ • Execution: SQL> sqld360.sql <sql_id> [N|D|T]
  34. 34. Copyright © 2016 Accenture All rights reserved. | 34 SQLD360
  35. 35. Copyright © 2016 Accenture All rights reserved. | 35 SQLD360
  36. 36. Copyright © 2016 Accenture All rights reserved. | 36 SQLD360
  37. 37. Copyright © 2016 Accenture All rights reserved. | 37 SQLD360
  38. 38. Copyright © 2016 Accenture All rights reserved. | 38 SQLD360 DEMO
  39. 39. Copyright © 2016 Accenture All rights reserved. | 39 SQLD360 If you want to know more: https://mauro-pagano.com/category/sqld360/
  40. 40. Copyright © 2016 Accenture All rights reserved. | 40 EXPLAIN PLAN How about Explain Plan?
  41. 41. Copyright © 2016 Accenture All rights reserved. | 41 EXPLAIN PLAN Explain Plain lies!
  42. 42. Copyright © 2016 Accenture All rights reserved. | 42 EXPLAIN PLAN It does not actually execute the SQL statement. Runtime factors can influence choice of plan: • Dynamic Sampling • Bind Variable Peeking • Adaptive Features
  43. 43. Copyright © 2016 Accenture All rights reserved. | 43 NOW WHAT? • DBMS_XPLAN.DISPLAY_CURSOR • V$SQL_PLAN%
  44. 44. Copyright © 2016 Accenture All rights reserved. | 44 DBMS_XPLAN.DISPLAY_CURSOR • SQL_ID • CURSOR_CHILD_NO (default 0) • FORMAT TYPICAL = DEFAULT ALL = TYPICAL + QB + PROJECTION + ALIAS + REMOTE ADVANCED = ALL + OUTLINE + BINDS ALLSTATS = IOSTATS + MEMSTATS (all executions) ALLSTATS LAST (last execution) ADAPTIVE (12c)
  45. 45. Copyright © 2016 Accenture All rights reserved. | DBMS_XPLAN
  46. 46. Copyright © 2016 Accenture All rights reserved. | DBMS_XPLAN Display plan for the last SQL executed: select * from table(dbms_xplan.display_cursor());
  47. 47. Copyright © 2016 Accenture All rights reserved. | DBMS_XPLAN Display plan for one specific SQL • Get SQL_ID:
  48. 48. Copyright © 2016 Accenture All rights reserved. | SQL_ID - 18C
  49. 49. Copyright © 2016 Accenture All rights reserved. | DBMS_XPLAN
  50. 50. Copyright © 2016 Accenture All rights reserved. | 50 DBMS_XPLAN DEMO
  51. 51. Copyright © 2016 Accenture All rights reserved. | DBMS_XPLAN Child Number ?
  52. 52. Copyright © 2016 Accenture All rights reserved. | 52 DBMS_XPLAN DEMO
  53. 53. Copyright © 2016 Accenture All rights reserved. |https://blogs.oracle.com/optimizer/entry/how_do_i_know_if /*+ gather_plan_statistics */ or Alter session set statistics_level = ALL ESTIMATE VS ACTUAL
  54. 54. Copyright © 2016 Accenture All rights reserved. | 54 ESTIMATE VS ACTUAL DEMO
  55. 55. Copyright © 2016 Accenture All rights reserved. | SQL MONITOR • Introduced in Oracle Database 11g. • Automatically started when a SQL statement either runs in parallel or has consumed at least 5 seconds of combined CPU and I/O. • Hint /*+ MONITOR */
  56. 56. Copyright © 2016 Accenture All rights reserved. | SQL MONITOR • Oracle Enterprise Manager • EM Database Express (12c) • SQL Developer • Command Line **Part of the Oracle Tuning Pack
  57. 57. Copyright © 2016 Accenture All rights reserved. | SQL MONITOR select dbms_sqltune.report_sql_monitor( sql_id => 'gjabwvvr07w09', report_level=>'ALL', type => 'ACTIVE') from dual;
  58. 58. Copyright © 2016 Accenture All rights reserved. | SQL MONITOR
  59. 59. Copyright © 2016 Accenture All rights reserved. | SQL MONITOR
  60. 60. Copyright © 2016 Accenture All rights reserved. | 60 DEMO SQL MONITOR
  61. 61. Copyright © 2016 Accenture All rights reserved. | 61 COST OF AN INDEX
  62. 62. Copyright © 2016 Accenture All rights reserved. | FULL TABLE SCAN https://www.slideshare.net/MauroPagano3/full-table-scan-friend-or-foe
  63. 63. Copyright © 2016 Accenture All rights reserved. | FULL TABLE SCAN https://www.slideshare.net/MauroPagano3/full-table-scan-friend-or-foe
  64. 64. Copyright © 2016 Accenture All rights reserved. | FULL TABLE SCAN https://richardfoote.wordpress.com/2008/05/12/index-scan-or-full-table-scan-the-magic-number-magic-dance/
  65. 65. Copyright © 2016 Accenture All rights reserved. | FULL TABLE SCAN • Clustering Factor --> How well ordered the rows in the table are in relation to the index. • Selectivity of the query • Number of table blocks • Effective multiblock read count • Relative cost of single vs. multiblock I/Os • Parallelism • Etc
  66. 66. Copyright © 2016 Accenture All rights reserved. | FULL TABLE SCAN https://www.slideshare.net/MauroPagano3/full-table-scan-friend-or-foe
  67. 67. Copyright © 2016 Accenture All rights reserved. | 67 • Not always good • Not always bad FULL TABLE SCAN
  68. 68. Copyright © 2016 Accenture All rights reserved. | 68 ANALYZING TABLES
  69. 69. Copyright © 2016 Accenture All rights reserved. | 69 ANALYZING TABLES https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4005.htm
  70. 70. Copyright © 2016 Accenture All rights reserved. | 70 ROW-BY-ROW PROCESSING https://blog.jooq.org/2018/04/19/the-performance-difference-between-sql-row-by-row-updating-batch-updating-and-bulk-updating/
  71. 71. Copyright © 2016 Accenture All rights reserved. | 71 ROW-BY-ROW
  72. 72. Copyright © 2016 Accenture All rights reserved. | 72 ROW-BY-ROW
  73. 73. Copyright © 2016 Accenture All rights reserved. | 73 PL/SQL FORALL
  74. 74. Copyright © 2016 Accenture All rights reserved. | 74 ONE UPDATE
  75. 75. Copyright © 2016 Accenture All rights reserved. | EVENT 10053
  76. 76. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 ALTER SESSION SET EVENTS '10053 trace name context forever, level 1'; SELECT * FROM EMP WHERE ENAME = 'SCOTT'; ALTER SESSION SET EVENTS '10053 trace name context off';
  77. 77. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Level 1 or Level 2? 1. Parameters used by the optimizer (level 1 only) 2. Index statistics (level 1 only) 3. Column statistics 4. Single Access Paths 5. Join Costs 6. Table Joins Considered 7. Join Methods Considered (NL/MS/HA)
  78. 78. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 For another session: SYS.DBMS_SYSTEM.SET_EV (SID,SERIAL ,10053,1) Disable: SYS.DBMS_SYSTEM.SET_EV (SID,SERIAL ,10053,0)
  79. 79. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 11G R1 ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*][sql:my_sql_id]'; ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*] off';
  80. 80. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 11G R2 – 18c dbms_sqldiag.dump_trace( p_sql_id=>’92c3fw9svc3rc’, p_child_number=>0, p_component=>'Compiler', p_file_id=>’MY_Trace_File'); ** Doesn’t require you to re-execute the statement.
  81. 81. Copyright © 2016 Accenture All rights reserved. | EVENT 10053
  82. 82. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 ALTER SESSION SET EVENTS '10053 trace name context forever, level 1'; SELECT * FROM tb_master p WHERE EXISTS (SELECT 1 FROM tb_detail f WHERE f.id_master=p.id); ALTER SESSION SET EVENTS '10053 trace name context off';
  83. 83. Copyright © 2016 Accenture All rights reserved. | EVENT 10053
  84. 84. Copyright © 2016 Accenture All rights reserved. | EVENT 10053
  85. 85. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 QUERY BLOCK – 2 parts
  86. 86. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Parallelism - Disabled
  87. 87. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Subtitles
  88. 88. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Database Parameters
  89. 89. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 System Statistics
  90. 90. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 No statistics for these tables
  91. 91. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Dynamic Sampling
  92. 92. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Full Table Scan – No Index
  93. 93. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Original: Final: Final Query
  94. 94. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Final Plan
  95. 95. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Example 2
  96. 96. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Let’s run this one
  97. 97. Copyright © 2016 Accenture All rights reserved. | EVENT 10053 Original: Final:
  98. 98. Copyright © 2016 Accenture All rights reserved. | 98 Query Transformations EVENT 10053
  99. 99. Copyright © 2016 Accenture All rights reserved. | OR EXPANSION Original: SELECT * FROM emp WHERE job = 'CLERK' OR deptno = 10; Changed: SELECT * FROM emp WHERE job = 'CLERK’ UNION ALL SELECT * FROM emp WHERE deptno = 10 AND job <> 'CLERK';
  100. 100. Copyright © 2016 Accenture All rights reserved. | SUBQUERY UNNESTING Original: SELECT * FROM accounts WHERE custno IN (SELECT custno FROM customers); Changed: SELECT accounts.* FROM accounts, customers WHERE accounts.custno = customers.custno;
  101. 101. Copyright © 2016 Accenture All rights reserved. | VIEW MERGING Original: CREATE VIEW emp_10 AS SELECT empno, ename, job, sal, comm, deptno FROM emp WHERE deptno = 10; SELECT empno FROM emp_10 WHERE empno > 7800; Changed: SELECT empno FROM emp WHERE deptno = 10 AND empno > 7800;
  102. 102. Copyright © 2016 Accenture All rights reserved. | PREDICATE PUSHING Original: CREATE VIEW two_emp_tables AS SELECT empno, ename, job, sal, comm, deptno FROM emp1 UNION SELECT empno, ename, job, sal, comm, deptno FROM emp2; SELECT ename FROM two_emp_tables WHERE deptno = 20;
  103. 103. Copyright © 2016 Accenture All rights reserved. | PREDICATE PUSHING Changed: SELECT ename FROM ( SELECT empno, ename, job,sal, comm, deptno FROM emp1 WHERE deptno = 20 UNION SELECT empno, ename, job,sal, comm, deptno FROM emp2 WHERE deptno = 20 );
  104. 104. Copyright © 2016 Accenture All rights reserved. | TRANSITIVITY Original: SELECT * FROM emp, dept WHERE emp.deptno = 20 AND emp.deptno = dept.deptno; Changed: SELECT * FROM emp, dept WHERE emp.deptno = 20 AND emp.deptno = dept.deptno AND dept.deptno = 20;
  105. 105. Copyright © 2016 Accenture All rights reserved. | 105 COUNT(1) VS COUNT(*) What is the difference between count(1) and count(*) ?
  106. 106. Copyright © 2016 Accenture All rights reserved. | 106 COUNT(1) VS COUNT(*) Nothing
  107. 107. Copyright © 2016 Accenture All rights reserved. | 107 COUNT(1) VS COUNT(*)
  108. 108. Copyright © 2016 Accenture All rights reserved. | MORE ABOUT THE EVENT 10053
  109. 109. Copyright © 2016 Accenture All rights reserved. |
  110. 110. Copyright © 2016 Accenture All rights reserved. | Oracle Database 12.1 OPTIMIZER_ADAPTIVE_FEATURES Default TRUE ADAPTIVE FEATURES
  111. 111. Copyright © 2016 Accenture All rights reserved. | Oracle Database 12.2 introduces the new split- up adaptive parameters: • OPTIMIZER_ADAPTIVE_PLANS • OPTIMITER_ADAPTIVE_STATISTICS ADAPTIVE FEATURES
  112. 112. Copyright © 2016 Accenture All rights reserved. | On Oracle Database 12.1 this can be achieved by installing two patches. ADAPTIVE FEATURES
  113. 113. Copyright © 2016 Accenture All rights reserved. | The patch for bug# 22652097 introduces the two parameters OPTIMIZER_ADAPTIVE_PLANS and OPTIMIZER_ADAPTIVE_STATISTICS, and in addition removes the parameter OPTIMIZER_ADAPTIVE_FEATURES. The patch for bug# 21171382 disables the automatic creation of extended statistics unless the optimizer preference AUTO_STATS_EXTENSIONS is set to ON. ADAPTIVE FEATURES
  114. 114. Copyright © 2016 Accenture All rights reserved. | https://blogs.oracle.com/optimizer/entry/improvement_of_auto_sampling_statistics_gathering_feature_in_oracle_database_11g estimate_percent => dbms_stats.auto_sample_size STATISTICS
  115. 115. Copyright © 2016 Accenture All rights reserved. | Should I use? HINTS
  116. 116. Copyright © 2016 Accenture All rights reserved. | Query running on M7: 180 Minutes Query after db clone  P8+Storage ? • Time: 29 hours Query running on M7 after SQL tuning: 17 minutes SQL TUNING ON EXADATA
  117. 117. Copyright © 2016 Accenture All rights reserved. | SQL TUNING ON EXADATA
  118. 118. Copyright © 2016 Accenture All rights reserved. |
  119. 119. Copyright © 2016 Accenture All rights reserved. | Set table preferences: begin dbms_stats.set_table_prefs ( ownname => 'SCOTT', tabname => 'EMP', pname => 'PUBLISH', pvalue => 'FALSE' ); end; Collect the statistics. PENDING STATISTICS
  120. 120. Copyright © 2016 Accenture All rights reserved. | select num_rows, to_char(last_analyzed,'dd/mm/rrrr hh24:mi:ss’) from all_tab_pending_stats where table_name = 'EMP'; PENDING STATISTICS
  121. 121. Copyright © 2016 Accenture All rights reserved. | alter session set optimizer_use_pending_statistics = true; Test your queries. PENDING STATISTICS
  122. 122. Copyright © 2016 Accenture All rights reserved. | If it’s ok: dbms_stats.publish_pending_stats('SCOTT', 'EMP’); or: dbms_stats.delete_pending_stats(’SCOTT',’EMP'); PENDING STATISTICS
  123. 123. Copyright © 2016 Accenture All rights reserved. | Check the retention: select DBMS_STATS.GET_STATS_HISTORY_RETENTION from dual; Default is 31 days. RESTORE STATISTICS FROM HISTORY
  124. 124. Copyright © 2016 Accenture All rights reserved. | Statistics available for the table: SELECT OWNER, TABLE_NAME, STATS_UPDATE_TIME FROM dba_tab_stats_history WHERE table_name='MY_TABLE'; RESTORE STATISTICS FROM HISTORY
  125. 125. Copyright © 2016 Accenture All rights reserved. | Begin dbms_stats.restore_table_stats( 'SCOTT', 'EMP', ‘08-NOV-16 11.38.05.015640 AM +08:00’); End; RESTORE STATISTICS FROM HISTORY
  126. 126. Copyright © 2016 Accenture All rights reserved. | begin dbms_stats.CREATE_STAT_TABLE( ownname=>user , stattab=>'MY_STATS_TABLE' ); end; begin dbms_stats.export_schema_stats( ownname=>user , stattab=>'MY_STATS_TABLE' , statid=>'CURRENT_STATS' ); end; EXPORT AND IMPORT SCHEMA STATISTICS
  127. 127. Copyright © 2016 Accenture All rights reserved. | EXPDP / IMPDP begin dbms_stats.import_schema_stats( ownname=>user , stattab=>'MY_STATS_TABLE' , statid=>'CURRENT_STATS' ); End; EXPORT AND IMPORT SCHEMA STATISTICS
  128. 128. Copyright © 2016 Accenture All rights reserved. | Incremental statistics for partitioned tables: dbms_stats.set_table_prefs(null,'SALES','INCREMENTAL','TRUE') INCREMENTAL STATISTICS
  129. 129. Copyright © 2016 Accenture All rights reserved. | INCREMENTAL STATISTICS
  130. 130. Copyright © 2016 Accenture All rights reserved. | CREATE INDEX index_name ON table_name(column_name) INVISIBLE; ALTER INDEX index_name INVISIBLE; ALTER INDEX index_name VISIBLE; INVISIBLE INDEXES
  131. 131. Copyright © 2016 Accenture All rights reserved. | ALTER SESSION SET OPTIMIZER_USE_INVISIBLE_INDEXES=TRUE; INVISIBLE INDEXES
  132. 132. Copyright © 2016 Accenture All rights reserved. | ALTER SESSION SET sql_trace=TRUE; ALTER SESSION SET sql_trace=FALSE; EXEC DBMS_SESSION.set_sql_trace(sql_trace => TRUE); EXEC DBMS_SESSION.set_sql_trace(sql_trace => FALSE); ALTER SESSION SET EVENTS '10046 trace name context forever, level 12'; ALTER SESSION SET EVENTS '10046 trace name context off'; EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>0000, serial#=>0000, sql_trace=>TRUE); EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>0000, serial#=>0000, sql_trace=>FALSE); SQL TRACE, 10046, TRCSESS AND TKPROF
  133. 133. Copyright © 2016 Accenture All rights reserved. | CONN sys/password AS SYSDBA; ORADEBUG SETMYPID; ORADEBUG SETOSPID 0000; ORADEBUG SETORAPID 000000; ORADEBUG EVENT 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12; ORADEBUG EVENT 10046 TRACE NAME CONTEXT OFF; SQL TRACE, 10046, TRCSESS AND TKPROF
  134. 134. Copyright © 2016 Accenture All rights reserved. | EXEC DBMS_SUPPORT.start_trace(waits=>TRUE, binds=>TRUE); EXEC DBMS_SUPPORT.stop_trace; EXEC DBMS_SUPPORT.start_trace_in_session(sid=>0000, serial=>000000, waits=>TRUE, binds=>TRUE); EXEC DBMS_SUPPORT.stop_trace_in_session(sid=>0000, serial=>000000); SQL TRACE, 10046, TRCSESS AND TKPROF
  135. 135. Copyright © 2016 Accenture All rights reserved. | 10g: DBMS_MONITOR.session_trace_enable(waits=>TRUE, binds=>FALSE); DBMS_MONITOR.session_trace_enable(session_id =>0000, serial_num=>000000, waits=>TRUE, binds=>TRUE); DBMS_MONITOR.client_id_trace_enable(client_id=>'my_client', waits=>TRUE, binds=>TRUE); DBMS_MONITOR.serv_mod_act_trace_enable(service_name=>'my_srv', module_name=>'my_test', action_name=>'calculating', waits=>TRUE, binds=>TRUE); SQL TRACE, 10046, TRCSESS AND TKPROF
  136. 136. Copyright © 2016 Accenture All rights reserved. | ALTER SESSION SET TRACEFILE_IDENTIFIER = "MY_TRC_FILE"; SQL TRACE, 10046, TRCSESS AND TKPROF
  137. 137. Copyright © 2016 Accenture All rights reserved. | SELECT p.tracefile FROM v$session s JOIN v$process p ON s.paddr = p.addr WHERE s.sid = MY_SID; SQL TRACE, 10046, TRCSESS AND TKPROF
  138. 138. Copyright © 2016 Accenture All rights reserved. | 12.2 v$diag_trace_file v$diag_trace_file_contents SQL TRACE, 10046, TRCSESS AND TKPROF
  139. 139. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  140. 140. Copyright © 2016 Accenture All rights reserved. | ALTER SESSION SET EVENTS '10046 trace name context forever, level 12'; SELECT * FROM tb_pai p WHERE EXISTS (SELECT 1 FROM tb_filho f WHERE f.id_pai=p.id); ALTER SESSION SET EVENTS '10046 trace name context off'; EVENT 10046
  141. 141. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  142. 142. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  143. 143. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  144. 144. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  145. 145. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  146. 146. Copyright © 2016 Accenture All rights reserved. | EVENT 10046
  147. 147. Copyright © 2016 Accenture All rights reserved. | • TKPROF • TRCSESS • Trace Analyzer TRCANLZR (TRCA) • Method R Tools SQL TRACE, 10046, TRCSESS AND TKPROF
  148. 148. Copyright © 2016 Accenture All rights reserved. | SQL TRACE, 10046, TRCSESS AND TKPROF
  149. 149. Copyright © 2016 Accenture All rights reserved. |http://www.oraclenerd.com/2011/02/sql-developer-mr-trace.html SQL TRACE, 10046, TRCSESS AND TKPROF
  150. 150. Copyright © 2016 Accenture All rights reserved. | 150 SQLCL http://www.oracle.com/technetwork/developer-tools/sqlcl/downloads/index.html
  151. 151. Copyright © 2016 Accenture All rights reserved. | 151 QUESTIONS?
  152. 152. Copyright © 2016 Accenture All rights reserved. | 152 Thank You Slides Available: http://www.slideshare.net/

×