1 RAC Internals Julian Dyke Independent Consultant Web Version juliandyke.com © 2007 Julian Dyke.
1 © 2014 Julian Dyke juliandyke.com Advanced Diagnostics Revisited Julian Dyke Independent...
-
Upload
dominick-hampton -
Category
Documents
-
view
218 -
download
0
Transcript of 1 © 2014 Julian Dyke juliandyke.com Advanced Diagnostics Revisited Julian Dyke Independent...
1 © 2014 Julian Dyke juliandyke.com
AdvancedDiagnosticsRevisited
Julian Dyke
Independent Consultant
UKOUG Conference 2014
© 2014 Julian Dyke juliandyke.com
WARNING
Much of the content of this presentation is undocumented and
unsupported by Oracle
Check with Oracle support before using any of these features in a
production environment
2
© 2014 Julian Dyke juliandyke.com
Agenda
Trace Parameters Features and Hints Execution Plans Events ORADEBUG ALTER Statements
3
© 2014 Julian Dyke juliandyke.com4
Trace
© 2014 Julian Dyke juliandyke.com
TraceV$DIAG_INFO Introduced in Oracle 11.1 Session-specific view reporting various diagnostic parameters
5
VALUE
/u01/app/oracle/diag/rdbms/target/TARGET/trace/TARGET_ora_5556.trc
SELECT value FROM v$diag_infoWHERE name = 'Default Trace File';
Column Name Data Type
INST_ID NUMBER
NAME VARCHAR2(64)
VALUE VARCHAR2(512)
CON_ID NUMBER
Current trace file can be determined using:
© 2014 Julian Dyke juliandyke.com
TraceTRACEFILE_IDENTIFIER Parameter Introduced in Oracle 8.1.7 Appends specified suffix to trace file name Subsequent trace is immediately written to new file Can be updated unlimited number of times
6
/u01/app/oracle/diag/rdbms/target/TARGET/trace/TARGET_ora_5556_TEST.trc
ALTER SESSION SET tracefile_identifier = 'TEST';
For example if the current trace file name is:
/u01/app/oracle/diag/rdbms/target/TARGET/trace/TARGET_ora_5556_TEST.trc
If the TRACEFILE_IDENTIFIER is set to "TEST":
Subsequent trace will be written to:
ORADEBUG SETTRACEFILEID TEST
TRACEFILE_IDENTIFIER can also be set using ORADEBUG:
© 2014 Julian Dyke juliandyke.com
TraceDBMS_SYSTEM.KSDWRT Procedure To write to trace files and/or alert log use:
7
DBMS_SYSTEM.KSDWRT(
DEST NUMBER, -- 1 = Trace File, 2 = Alert LogTST VARCHAR2 -- Message
);
BEGINDBMS_SYSTEM.KSDWRT (1, ‘Output to trace file’);DBMS_SYSTEM.KSDWRT (2, ‘Output to alert log’);
END;
For example:
© 2014 Julian Dyke juliandyke.com
TraceDBMS_MONITOR - Overview Introduced in Oracle 10.1 Package to enable/disable trace and statistics Defined in $ORACLE_HOME/rdbms/admin/dbmsmntr.sql
Trace subroutines include: SESSION_TRACE_ENABLE / DISABLE DATABASE_TRACE_ENABLE / DISABLE CLIENT_ID_TRACE_ENABLE / DISABLE SERV_MOD_ACT_TRACE_ENABLE / DISABLE
Statistics subroutines include: CLIENT_ID_STAT_ENABLE / DISABLE SERV_MOD_ACT_STAT_ENABLE / DISABLE
Trace subroutines are equivalent to event 10046 level 8 Include wait events by default
8
© 2014 Julian Dyke juliandyke.com
TraceDBMS_MONITOR - PLAN_STAT column In Oracle 11.1 and above the following subroutines include the PLAN_STAT
column: SESSION_TRACE_ENABLE DATABASE_TRACE_ENABLE CLIENT_ID_TRACE_ENABLE SERV_MOD_ACT_TRACE_ENABLE
PLAN_STAT specifies the dump frequency for row source (STAT) statistics
Values can be: NEVER FIRST_EXECUTION (default) ALL_EXECUTIONS
Useful when individual statement executions are affected by data cardinality / selectivity
9
© 2014 Julian Dyke juliandyke.com10
Parameters
© 2014 Julian Dyke juliandyke.com
ParametersV$PARAMETER V$PARAMETER includes supported parameters
11
Column Name Data Type
NUM NUMBER
NAME VARCHAR2(80)
TYPE NUMBER
VALUE VARCHAR2(4000)
DISPLAY_VALUE VARCHAR2(4000)
DEFAULT_VALUE VARCHAR2(255)
ISDEFAULT VARCHAR2(9)
ISSES_MODIFIABLE VARCHAR2(5)
ISSYS_MODIFIABLE VARCHAR2(9)
ISPDB_MODIFIABLE VARCHAR2(5)
Column Name Data Type
IS_INSTANCE_MODIFIABLE VARCHAR2(5)
ISMODIFIED VARCHAR2(10)
ISADJUSTED VARCHAR2(5)
ISDEPRECATED VARCHAR2(5)
ISBASIC VARCHAR2(5)
DESCRIPTION VARCHAR2(256)
UPDATE_COMMENT VARCHAR2(256)
HASH NUMBER
CON_ID NUMBER
CON_ID - new in Oracle 12.1 -> Container ID ISPDB_MODIFIABLE is also new in 12.1
© 2014 Julian Dyke juliandyke.com
ParametersV$PARAMETER V$PARAMETER includes supported parameters
Based on X$KSPPI - includes all parameters
12
Version Supported Unsupported Total
11.2.0.3 348 2403 2751
11.2.0.4 352 2562 2914
12.1.0.1 367 2984 3351
12.1.0.2 381 3597 3978
To set an unsupported parameter use double quotes around name e.g.:
ALTER SESSION SET "_serial_direct_read" = NEVER;
V$PARAMETER includes non-default values for unsupported parameters
© 2014 Julian Dyke juliandyke.com
ParametersUnsupported parameters V$PARAMETER only reports non-default values for unsupported parameters
13
SELECT i.ksppinm||';'||sv.ksppstvl
FROM x$ksppi i, x$ksppsv svWHERE i.indx = sv.indxORDER BY i.ksppinm;
To dump values for all parameters including default parameters for unsupported parameters:
© 2014 Julian Dyke juliandyke.com
ParametersV$PARAMETER_VALID_VALUES V$PARAMETER_VALID_VALUES - supported parameters
Based on X$KSPVLD_VALUES - all parameters
14
Version Supported Unsupported Total
11.2.0.3
11.2.0.4 73 91 164
12.1.0.1 75 112 187
12.1.0.2 78 124 202
Column Name Data Type
NUM NUMBER
NAME VARCHAR2(64)
ORDINAL NUMBER
VALUE VARCHAR2(255)
ISDEFAULT VARCHAR2(64)
CON_ID NUMBER
© 2014 Julian Dyke juliandyke.com
ParametersV$PARAMETER_VALID_VALUES For example:
15
Value Default
ALWAYS FALSE
AUTO FALSE
NEVER FALSE
TRUE FALSE
FALSE FALSE
SELECT value_kspvld_values AS "Value",isdefault_kspvld_values AS "Default"
FROM x$kspvld_valuesWHERE name_kspvld_values = '_serial_direct_read'ORDER BY ordinal_kspvld_values;
© 2014 Julian Dyke juliandyke.com16
Featuresand
Hints
© 2014 Julian Dyke juliandyke.com
Features and HintsV$SQL_FEATURE Based on X$QKSFM
Includes features and fixes
17
Column Name Data Type
SQL_FEATURE VARCHAR2(64)
DESCRIPTION VARCHAR2(64)
PROPERTY NUMBER
Individual fixes can be enabled and disabled. For example:
Fixes can be identified from DESCRIPTION column
WHERE description LIKE 'Fix%'
ALTER SESSION SET "_fix_control"='6776808:off';
© 2014 Julian Dyke juliandyke.com
Features and HintsV$SQL_FEATURE Version counts are:
18
Version0 Feature Fix Total
11.2.0.3 94 654 748
11.2.0.4 98 846 944
12.1.0.1 110 885 996
12.1.0.2 115 1071 1186
© 2014 Julian Dyke juliandyke.com
Features and HintsV$SQL_FEATURE_HIERARCHY V$SQL_FEATURE describes the relationships between features
The root feature is QKSFM_ALL
The following query prints the hierarchy in a nested format:
19
SELECT lpad ( ' ' , level * 2 ,' ' ) || sql_featureFROM v$sql_feature_hierarchyCONNECT BY PRIOR sql_feature = parent_idSTART WITH parent_id = 'QKSFM_ALL';
....
QKSFM_TRANSFORMATIONQKSFM_CBQT
QKSFM_CVMQKSFM_DIST_PLCMTQKSFM_JOINFACQKSFM_JPPDQKSFM_PLACE_GROUP_BYQKSFM_PULL_PRED
....
© 2014 Julian Dyke juliandyke.com
Features and HintsV$SQL_HINT Based on X$QKSHT
Currently no concept of unsupported hints
20
Column Name Data Type
NAME VARCHAR2(64)
SQL_FEATURE VARCHAR2(64)
CLASS VARCHAR2(64)
INVERSE VARCHAR2(64)
TARGET_LEVEL NUMBER
PROPERTY NUMBER
VERSION VARCHAR2(25)
VERSION_OUTLINE VARCHAR2(25)
INVERSE column Describes the opposite hint e.g.: PUSH_PRED and NO_PUSH_PRED
Version # Hints
11.2.0.3 273
11.2.0.4 277
12.1.0.1 314
12.1.0.2 332
© 2014 Julian Dyke juliandyke.com
Features and HintsV$SQL_HINT VERSION column
Describes version in which hint was introduced:
21
Version # New Hints
8.0.0 14
8.1.0 50
8.1.5 18
8.1.6 4
8.1.7 2
9.0.0 26
9.2.0 13
10.1.0.3 42
10.2.0.1 35
10.2.0.2 4
10.2.0.3 3
Version # New Hints
10.2.0.4 2
10.2.0.5 4
11.1.0.6 32
11.1.0.7 5
11.2.0.1 19
11.2.0.2 6
11.2.0.3 6
11.2.0.4 2
12.1.0.1 37
12.1.0.2 18
© 2014 Julian Dyke juliandyke.com22
ExecutionPlans
© 2014 Julian Dyke juliandyke.com23
Execution PlansDBMS_XPLAN - Overview Introduced in Oracle 9.2
Enhanced in subsequent releases
SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR);
Defined in $ORACLE_HOME/rdbms/admin/dbmsxpln.sql
Useful subroutines include DISPLAY - display a plan from a PLAN_TABLE DISPLAY_AWR - display a plan from the AWR DISPLAY_CURSOR - display a plan from the library cache DISPLAY_PLAN – returns plan as a CLOB DISPLAY_SQLSET – displays a plan from a SQL tuning set DISPLAY_SQLPLAN_BASELIN E – displays a plan from SQL baseline
For example to display execution plan for statement most recently executed by the current session:
© 2014 Julian Dyke juliandyke.com
Execution PlansDBMS_XPLAN - FORMAT Column All DISPLAY subroutines include a FORMAT column which can be:
BASIC Minimum information Display operation ID, name and option
TYPICAL Default. Display operation ID, name and option, #rows, #bytes and optimizer
cost. Includes pruning, parallel and predicate information when applicable
ALL Maximum information As TYPICAL plus projection, alias and remote SQL if applicable
SERIAL Same as TYPICAL except parallel information is not displayed even if
statement executes in parallel
24
© 2014 Julian Dyke juliandyke.com
Execution PlansDBMS_XPLAN - FORMAT Column Options FORMAT column options can be fine-tuned using the following keywords:
ROWS - number of rows estimated by optimizer BYTES - number of bytes estimated by optimizer COST - optimizer cost information PARTITION - partition pruning information PARALLEL - parallel execution information PREDICATE - predicate section PROJECTION - projection section ALIAS - query block name / object alias REMOTE - distributed query information NOTE - note section
If keyword is prefixed by a minus sign then specified information is excluded BASIC ROWS - displays basic information plus number of rows ALL -PROJECTION -NOTE displays everything except the projection and
note sections
25
© 2014 Julian Dyke juliandyke.com
Execution PlansDBMS_XPLAN - Additional Statistics For DISPLAY_CURSOR and DISPLAY_SQLSET, additional data can be output
using the following keywords:
IOSTATS – shows IO statistics for all executions of the cursor MEMSTATS – displays memory management statistics including
execution mode of operator how much memory was used number of bytes spilled to disk
ALLSTATS – both IOSTATS and MEMSTATS LAST – only report statistics for last execution of cursor
IOSTATS, ALLSTATS and LAST require basic plan statistics which are collected by
setting STATISTICS_LEVEL parameter to ALL specifying GATHER_PLAN_STATISTICS hint
MEMSTATS requires PGA memory management to be enabled by: setting PGA_AGGREGATE_TARGET to non-zero value
26
© 2014 Julian Dyke juliandyke.com
Execution PlansOperations and Options AWR includes some interesting (static) views that describe execution plan
operations and options available in the installed database version
DBA_HIST_PLAN_OPERATION_NAME Contains a list of row source operations
DBA_HIST_PLAN_OPTION_NAME Contains a list of row source options
DBA_HIST_TOPLEVELCALL_NAME Contains a list of top level calls Used in DBA_HIST_ACTIVE_SESS_HISTORY
27
© 2014 Julian Dyke juliandyke.com28
Events
© 2014 Julian Dyke juliandyke.com
Event 10046Levels Event 10046 has additional levels in recent versions
29
Level Description Version
1 Trace includes SQL statement, response time, service time, execution statistics (#rows, #LIOs #PRs #PWs)In 10.2 and below execution plan written to trace file when associated cursor is closed. In 11.1 and above execution plan written to trace file after first execution of each cursor - plan_stat = 'first_execution'
All
4 As level 1 plus bind varables All
8 As level 1 plus wait times All
16 As level 1 plus execution plans for every executionplan_stat = 'all_executions'
11.1 and above
32 As level 1 without any execution plansplan_stat = 'never'
11.1 and above
64 As level 1 plus execution plans for any statement execution requiring more than 60 seconds of DB time
11.2.0.2 and above
© 2014 Julian Dyke juliandyke.com
Event 10046Bind Variables Event 10046 level 4 trace only captures the first bind variable in array
30
EXECUTE dbms_monitor.session_trace_enable (binds=>TRUE);
CREATE TABLE driver (key VARCHAR2(4), name VARCHAR2(30));
DECLARE TYPE driver_tab IS TABLE OF driver%ROWTYPE; d driver_tab := driver_tab ();BEGIN d.extend (6); d(1).key := 'LHAM'; d(1).name := 'Lewis Hamilton'; d(2).key := 'NROS'; d(2).name := 'Nico Rosberg'; d(3).key := 'SVET'; d(3).name := 'Sebastian Vettel'; d(4).key := 'FALO'; d(4).name := 'Fernando Alonso'; d(5).key := 'DRIC'; d(5).name := 'Daniel Ricciardo'; d(6).key := 'JBUT'; d(6).name := 'Jenson Button';
FORALL j IN 1..3INSERT INTO driver VALUES (d(j).key,d(j).name);
FORALL j IN 4..6INSERT INTO driver VALUES (d(j).key,d(j).name);
END;
© 2014 Julian Dyke juliandyke.com
Event 10046Bind Variables Trace will only contain bind variable values for two rows:
31
BINDS #139676743602632:Bind#0
...value="LHAM"
Bind#1...value="Lewis Hamilton"
...
BINDS #139676743602632:Bind#0
...value="FALO"
Bind#1...value="Fernando Alonso"
Trace only includes first row of each array insert Remaining rows are not traced
Note this issue has consequences for load generation / simulation tools such as HammerDB and LoadRunner which base their input on 10046 trace.
© 2014 Julian Dyke juliandyke.com
Event 10053Optimizer Decisions To trace optimizer decisions use enable event 10053:
32
Level Description Version
1 Print statistics and computations All
2 Print computations only All
Details are only written to trace when the statement is hard-parsed
© 2014 Julian Dyke juliandyke.com
Event 10053 DBMS_SQLDIAG Provides APIs to diagnose SQL statements.
Used by diagnostic modules: SQL_TESTCASE SQL_DIAGNOSTIC
Defined in $ORACLE_HOME/rdbms/admin/dbmsdiag.sql
Includes DUMP_TRACE procedure: Dumps 10053 trace (optimizer or compiler) trace for a specific SQL
statement Does not execute SQL statement to generate trace Compiler trace is a superset of optimizer trace
Includes kkf library calls Query block decisions Expressions
33
© 2014 Julian Dyke juliandyke.com
Event 10053 DBMS_SQLDIAG DUMP_TRACE procedure parameters are:
34
Name Description
p_sql_id Child cursor SQL_ID
p_child_number Child cursor number
p_component "Optimizer" or "Compiler"
p_file_id tracefile_identifier
For example:
dbms_sqldiag.dump_trace(
p_sql_id => '2y220pbrk573n',p_child_number => 0,p_component => 'Optimizer',p_file_id => 'OPTIMIZER'
);
Note that P_FILE_ID sets TRACEFILE_IDENTIFIER, but does not reset it at end of call so subsequent trace file be written to the new file. Alternatively NULL can be specified (the default)
© 2014 Julian Dyke juliandyke.com35
ORADEBUG
© 2014 Julian Dyke juliandyke.com
ORADEBUGIntroduction Undocumented debugging utility available
as a standalone utility on Unix (oradbx) as a standalone utility on VMS (orambx) within Server Manager (svrmgr) within SQL*Plus (8.1.5 and above)
36
SQL> ORADEBUG HELP
Requires SYSDBA privilege
Options vary for each release
To list available options use:
© 2014 Julian Dyke juliandyke.com
ORADEBUGProcess Specification There are four ways of specifying a process in ORADEBUG:
37
SQL> ORADEBUG SETMYPID
Using Oracle PID (V$PROCESS.PID)
Using the Oracle process name:
For example:
SQL> ORADEBUG SETORAPID <pid>
Using operating system PID (V$PROCESS.SPID)
SQL> ORADEBUG SETOSPID <spid>
SQL> ORADEBUG SETORAPNAME <pname>
SQL> ORADEBUG SETORAPNAME PMON
Using current process:
© 2014 Julian Dyke juliandyke.com
ORADEBUGUseful Commands To display the current trace file name use:
38
SQL> ORADEBUG TRACEFILE_NAME
To flush the current trace file use:
SQL> ORADEBUG FLUSH
To set the maximum size of the current trace file to UNLIMITED use:
SQL> ORADEBUG UNLIMIT
SQL> ORADEBUG SETTRACEFILEID <suffix>
To set the TRACEFILE_IDENTIFER parameter:
To dump the currently executing statement (SQL or PL/SQL)
SQL> ORADEBUG CURRENT_SQL
© 2014 Julian Dyke juliandyke.com
ORADEBUGDumps Dumps vary for each release:
39
SQL> ORADEBUG DUMPLIST
To list available dumps:
To perform an dump immediately use:
SQL> ORADEBUG DUMP <dump_name> <level> [address]
To perform a dump periodically use:
SQL> ORADEBUG PDUMP [interval=<interval>] [ndumps=<count> <dump_name> <level> [address]
© 2014 Julian Dyke juliandyke.com
ORADEBUGProcess Statistics To dump process statistics use ORADEBUG PROCSTAT. For example:
40
SQL> ORADEBUG SETORAPNAME PMONSQL> ORADEBUG PROCSTAT
----- Dump of Process Statistics -----User time used = 65System time used = 30Maximum resident set size = 28452Integral shared text size = 0Integral unshared data size = 0Integral unshared stack size = 0Page reclaims = 7480Page faults = 7Swaps = 0Block input operations = 1472Block output operations = 32Socket messages sent = 0Socket messages received = 0Signals received = 0Voluntary context switches = 2555Involuntary context switches = 387
© 2014 Julian Dyke juliandyke.com
ORADEBUGComponents ORADEBUG includes internal documentation for
Components Events
41
SQL> ORADEBUG DOC
Internal Documentation
EVENT Help on events (syntax, event list, ...)
COMPONENT [<comp_name>] List all components or describe <comp_name>
Components are arranged in nested hierarchies Each component has a unique name Do not need to specify parent(s) to uniquely identify component
Most component descriptions include the internal module name(s) e.g.:
SQL_Execution SQL Execution (qer, qes, kx, qee)
Parallel_Execution Parallel Execution (qerpx, qertq, kxfr, kxfx, kxfq, kxfp)
© 2014 Julian Dyke juliandyke.com
ORADEBUGComponents Components are grouped into eight libraries:
42
Library Description
ADVCMP Advanced Compression
CLIENT Client
DIAG Diagnostics
GENERIC Numeric Events
LIBCELL Exadata Cells
ORANET Networking
PLSQL PL/SQL
RDBMS RDBMS
© 2014 Julian Dyke juliandyke.com
ORADEBUGComponents For example given the extract below from ORADEBUG DOC COMPONENT:
43
Components in library RDBMS:
SQL_Compiler SQL Compiler ((null))SQL_Parser SQL Parser (qcs)SQL_Semantic SQL Semantic Analysis (kkm)SQL_Optimizer SQL Optimizer ((null))
SQL_Transform SQL Transformation (kkq, vop, nso)SQL_MVRW SQL Materialized View Rewrite ((null))SQL_Vmerge SQL View Merging (kkqvm)SQL_Virtual SQL Virtual Column (qksvc, kkfi)
SQL_APA SQL Access Path Analysis (apa)SQL_Costing SQL Cost-based Analysis (kko, kke)
SQL> ORADEBUG DOC RDBMSSQL> ORADEBUG DOC SQL_CompilerSQL> ORADEBUG DOC SQL_OptimizerSQL> ORADEBUG DOC SQL_TransformSQL> ORADEBUG DOC SQL_Vmerge
The following are all valid:
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents The full event syntax is described in ORADEBUG:
44
SQL> ORADEBUG DOC EVENT
<event_spec>::= '<event_id> [<event_scope>][<event_filter_list>][<event_parameters>][<action_list>][off]'
<event_id> ::= <event_name | number>[<target_parameters>]
<event_scope> ::= [<scope_name>: scope_parameters]
<event_filter> ::= {<filter_name>: filter_parameters}
<action> ::= <action_name>(action_parameters)
<*_parameters> ::= <parameter_name> = <value>[, ]
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents Each event specification is comprised of up to four parts:
Name Scope Filter Action
Not all of the above are always required Defaults apply for many permutations
More information is available in:
45
SQL> ORADEBUG DOC EVENT NAME
SQL> ORADEBUG DOC EVENT SCOPE
SQL> ORADEBUG DOC EVENT FILTER
SQL> ORADEBUG DOC EVENT ACTION
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Name Event names are optional:
Can be specified for some libraries
46
Name Description
alert_text event for textual alerts
trace_recursive force tracing of recursive SQL statements
clientid_overwrite overwrite client_identifier in client_info
sql_monitor force monitoring of SQL statements
sql_trace sql trace
pmon_startup startup of pmon process
background_startup startup of background processes
db_open_begin start of database open operation
For example for the RDBMS library:
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Scope Scope is the SQL scope for RDBMS events
Defined using SQL[ ]
Syntax is
47
[SQL: sql_id <string> ]
For example:
[SQL: 3s1yukp05bzg6]
Multiple SQL_IDs can be specified using | as a separator
[SQL: 3s1yukp05bzg6 | aca4xvmz0rzup]
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Filter Filters include:
48
Library Filter Description
DIAG occurence Fire events after specified number of occurrences
DIAG callstack Fire events when specified function is on stack
DIAG tag Fire events when specified tag is set
RDBMS process Fire events for specific process
RDBMS pgadep Fire when pgadep is within specified range
GENERIC errarg Fire events for specific error argument
Filters must be enclosed in curly brackets. For example pgadep below:
SQL> ALTER SESSION SET EVENTS
'sql_trace[SQL: 32cqz71gd8wy3] {pgadep: exactdepth 0}
plan_stat=all_executions,wait=true,bind=true';
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Filter pgadep is the PGA depth (dep=N) in trace file.
Can take the following values: exactDepth lessThan greaterThan
For example:
49
{pgadep: exactdepth 0}
For normal statement execution dep = 0 SQL statement execution
For PL/SQL execution dep = 0 PL/SQL execution dep = 1 SQL statement execution
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Action Actions exist for each library (except PLSQL)
For the RDBMS library most actions correspond to ORADEBUG DUMP commands from older versions including:
50
Dump Name Description
PROCESSSTATE Dump process state
SYSTEMSTATE Dump system state
HEAPDUMP Dump memory heap
GLOBAL_AREA Dump fixed global area(s)
BUFFERS Dump all buffers in buffer cache
SET_TSN_P1 Set tablespace # for buffer dump
BUFFER Dump all buffers for specific DBA
LIBRARY_CACHE Dump the library cache
CURSORDUMP Dump session cursors
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - SQL_TRACE
SQL_TRACE is an synonym for event 10046 and can be set using: ORADEBUG ALTER SYSTEM ALTER SESSION
51
SQL> ORADEBUG DOC EVENT NAME SQL_TRACE
sql_trace: event for sql trace
Usage
sql_trace wait < false | true >, bind < false | true >, plan_stat < never | first_execution | all_executions | adaptive >, level <ub4>
The ORADEBUG syntax is:
The default level is 1
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - SQL_TRACE For example:
52
ORADEBUG EVENT SQL_TRACE
ORADEBUG EVENT SQL_TRACE BIND=TRUE
ORADEBUG EVENT SQL_TRACE BIND=TRUE,WAIT=TRUE
ORADEBUG EVENT SQL_TRACE OFF
ORADEBUG EVENT SQL_TRACE PLAN_STAT=ALL_EXECUTIONS
ORADEBUG EVENT SQL_TRACE LEVEL=4
© 2014 Julian Dyke juliandyke.com
ORADEBUGEvents - Examples Numeric events can be set using ORADEBUG. Default level is 1
53
ORADEBUG EVENT 10053
ORADEBUG EVENT 10053 TRACE NAME CONTEXT FOREVER, LEVEL 1
ORADEBUG EVENT 10053 TRACE NAME CONTEXT OFF
ORADEBUG EVENT 10053 LEVEL 1
ORADEBUG EVENT 10053 OFF
The original syntax still works in Oracle 11g/12c
© 2014 Julian Dyke juliandyke.com54
ALTERStatements
© 2014 Julian Dyke juliandyke.com
ALTER StatementsSQL_TRACE In all versions SQL_TRACE can be enabled using ALTER SESSION/SYSTEM
Examples shown for ALTER SESSION:
55
SQL> ALTER SESSION SET SQL_TRACE=TRUE;
In Oracle 11.1 and above SQL_TRACE is an event:
SQL> ALTER SESSION SET EVENTS 'sql_trace wait=true';
SQL> ALTER SESSION SET EVENTS 'sql_trace bind=true';
SQL> ALTER SESSION SET EVENTS 'sql_trace bind=true, wait=true';
SQL> ALTER SESSION SET EVENTS 'sql_trace plan_stat=all_executions';
© 2014 Julian Dyke juliandyke.com
ALTER StatementsNumeric Events Numeric events can still be set using ALTER SESSION / ALTER SYSTEM
56
SQL> ALTER SESSION SET EVENTS '10235 level 1';
SQL> ALTER SESSION SET EVENTS '10235 off';
SQL> ALTER SESSION SET EVENTS '10235';
SQL> ALTER SESSION SET EVENTS '10235 trace name context forever, level 1';
SQL> ALTER SESSION SET EVENTS '10235 trace name context off';
The original syntax still works in Oracle 11g/12c
© 2014 Julian Dyke juliandyke.com
ALTER StatementsSQL_TRACE - Filter Trace can be restricted to a specific SQL ID by specifying a filter:
57
SQL> ALTER SESSION SET EVENTS 'sql_trace [sql: sql_id=3s1yukp05bzg6] bind=true, wait=true';
SQL> ALTER SESSION SET EVENTS 'sql_trace [sql: sql_id=3s1yukp05bzg6|aca4xvmz0rzup] bind=true, wait=true';
Multiple SQL IDs can be specified using the | symbol as a separator
© 2014 Julian Dyke juliandyke.com
ALTER Statements TRACE - Components Trace can be restricted to a specific components e.g.
58
SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*]';
SQL> ALTER SESSION SET EVENTS 'trace[SQL_Optimizer.*][sql:3bnxc7htmf2ad]';
Individual components can also be filtered e.g.:
The library name can optionally be omitted e.g.
SQL> ALTER SESSION SET EVENTS 'trace[SQL_Optimizer.*]';
Disable trace again using:
SQL> ALTER SESSION SET EVENTS 'trace[SQL_Optimizer.*] off';
© 2014 Julian Dyke juliandyke.com
ALTER StatementsFlushing Caches To flush the buffer cache use:
59
ALTER SYSTEM FLUSH BUFFER_CACHE;
ALTER SYSTEM FLUSH SHARED_POOL;
The buffer cache must be flushed to disk before attempting to dump blocks using the ALTER SYSTEM DUMP command
To flush the shared pool (library cache) use:
Pinned objects will not be flushed
© 2014 Julian Dyke juliandyke.com60
ALTER StatementsBlock Dumps To dump a database block in Oracle 8.0 or above:
ALTER SYSTEM DUMP DATAFILE <absolute_file_number>BLOCK <block_number>;
ALTER SYSTEM DUMP DATAFILE <absolute_file_number>BLOCK MIN <minimum_block_number>BLOCK MAX <maximum_block_number>;
To dump a range of database blocks:
To dump a block from a datafile in a closed database:
ALTER SYSTEM DUMP DATAFILE '<file_name>'BLOCK <block_number>;
© 2014 Julian Dyke juliandyke.com
ALTER StatementsBlock Dumps In Oracle 12c ASSM bitmap blocks cannot be dumped by default
Block is considered to be encrypted
Work around is to set
61
ALTER SESSION SET "_sga_clear_dump" = TRUE;
Acknowledgements to Jonathan Lewis and Riyaj Shamsudeen for the above
X$KSPPI description for this parameter is:
Allow dumping encrypted blocks in clear for debugging
© 2014 Julian Dyke juliandyke.com62
ALTER StatementsRedo Log Dumps To identify the current redo log use:
SELECT member FROM v$logfileWHERE group# = (
SELECT group# FROM v$logWHERE status = 'CURRENT'
);
To dump the contents of a redo log use:
ALTER SYSTEM DUMP LOGFILE '<logfilename>';
Also works for archived log files
© 2014 Julian Dyke juliandyke.com63
ALTER StatementsRedo Log Dumps Full syntax is:
ALTER SYSTEM DUMP LOGFILE 'FileName' SCN MIN MinimumSCN SCN MAX MaximumSCN TIME MIN MinimumTime TIME MAX MaximumTime LAYER Layer OPCODE Opcode DBA MIN FileNumber . BlockNumber DBA MAX FileNumber . BlockNumber RBA MIN LogFileSequenceNumber . BlockNumber RBA MAX LogFileSequenceNumber . BlockNumber;
See MOS Note 1031381.6 for further details
© 2014 Julian Dyke juliandyke.com
Thank You For Your Interest
Please send any questions or comments to: