Advanced Diagnostics Revisited

advertisement
Advanced
Diagnostics
Revisited
Julian Dyke
Independent Consultant
UKOUG Conference 2014
1
© 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







3
© 2014 Julian Dyke
Trace
Parameters
Features and Hints
Execution Plans
Events
ORADEBUG
ALTER Statements
juliandyke.com
Trace
4
© 2014 Julian Dyke
juliandyke.com
Trace
V$DIAG_INFO



Introduced in Oracle 11.1
Session-specific view reporting various diagnostic parameters
Column Name
Data Type
INST_ID
NUMBER
NAME
VARCHAR2(64)
VALUE
VARCHAR2(512)
CON_ID
NUMBER
Current trace file can be determined using:
SELECT value FROM v$diag_info
WHERE name = 'Default Trace File';
VALUE
/u01/app/oracle/diag/rdbms/target/TARGET/trace/TARGET_ora_5556.trc
5
© 2014 Julian Dyke
juliandyke.com
Trace
TRACEFILE_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

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":
ALTER SESSION SET tracefile_identifier = 'TEST';

Subsequent trace will be written to:
/u01/app/oracle/diag/rdbms/target/TARGET/trace/TARGET_ora_5556_TEST.trc

TRACEFILE_IDENTIFIER can also be set using ORADEBUG:
ORADEBUG SETTRACEFILEID TEST
6
© 2014 Julian Dyke
juliandyke.com
Trace
DBMS_SYSTEM.KSDWRT Procedure

To write to trace files and/or alert log use:
DBMS_SYSTEM.KSDWRT
(
DEST NUMBER,
TST VARCHAR2
);

-- 1 = Trace File, 2 = Alert Log
-- Message
For example:
BEGIN
DBMS_SYSTEM.KSDWRT (1, ‘Output to trace file’);
DBMS_SYSTEM.KSDWRT (2, ‘Output to alert log’);
END;
7
© 2014 Julian Dyke
juliandyke.com
Trace
DBMS_MONITOR - Overview



8
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
© 2014 Julian Dyke
juliandyke.com
Trace
DBMS_MONITOR - PLAN_STAT column
9

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
© 2014 Julian Dyke
juliandyke.com
Parameters
10
© 2014 Julian Dyke
juliandyke.com
Parameters
V$PARAMETER

Column Name
Data Type
Column Name
Data Type
NUM
NUMBER
IS_INSTANCE_MODIFIABLE
VARCHAR2(5)
NAME
VARCHAR2(80)
ISMODIFIED
VARCHAR2(10)
TYPE
NUMBER
ISADJUSTED
VARCHAR2(5)
VALUE
VARCHAR2(4000)
ISDEPRECATED
VARCHAR2(5)
DISPLAY_VALUE
VARCHAR2(4000)
ISBASIC
VARCHAR2(5)
DEFAULT_VALUE
VARCHAR2(255)
DESCRIPTION
VARCHAR2(256)
ISDEFAULT
VARCHAR2(9)
UPDATE_COMMENT
VARCHAR2(256)
ISSES_MODIFIABLE
VARCHAR2(5)
HASH
NUMBER
ISSYS_MODIFIABLE
VARCHAR2(9)
CON_ID
NUMBER
ISPDB_MODIFIABLE
VARCHAR2(5)

11
V$PARAMETER includes supported parameters
CON_ID - new in Oracle 12.1 -> Container ID
 ISPDB_MODIFIABLE is also new in 12.1
© 2014 Julian Dyke
juliandyke.com
Parameters
V$PARAMETER

V$PARAMETER includes supported parameters
 Based on X$KSPPI - includes all parameters
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;

12
V$PARAMETER includes non-default values for unsupported parameters
© 2014 Julian Dyke
juliandyke.com
Parameters
Unsupported parameters

V$PARAMETER only reports non-default values for unsupported parameters

To dump values for all parameters
 including default parameters for unsupported parameters:
SELECT
i.ksppinm||';'||sv.ksppstvl
FROM x$ksppi i, x$ksppsv sv
WHERE i.indx = sv.indx
ORDER BY i.ksppinm;
13
© 2014 Julian Dyke
juliandyke.com
Parameters
V$PARAMETER_VALID_VALUES

V$PARAMETER_VALID_VALUES - supported parameters
 Based on X$KSPVLD_VALUES - all parameters
Version
Column Name
Data Type
NUM
NUMBER
NAME
VARCHAR2(64)
ORDINAL
NUMBER
VALUE
VARCHAR2(255)
ISDEFAULT
VARCHAR2(64)
CON_ID
NUMBER
Supported
Unsupported
Total
11.2.0.3
14
11.2.0.4
73
91
164
12.1.0.1
75
112
187
78
124
202
12.1.0.2
© 2014 Julian Dyke
juliandyke.com
Parameters
V$PARAMETER_VALID_VALUES

For example:
SELECT
value_kspvld_values AS "Value",
isdefault_kspvld_values AS "Default"
FROM x$kspvld_values
WHERE name_kspvld_values = '_serial_direct_read'
ORDER BY ordinal_kspvld_values;
Value
15
© 2014 Julian Dyke
Default
ALWAYS
FALSE
AUTO
FALSE
NEVER
FALSE
TRUE
FALSE
FALSE
FALSE
juliandyke.com
Features
and
Hints
16
© 2014 Julian Dyke
juliandyke.com
Features and Hints
V$SQL_FEATURE


Based on X$QKSFM
 Includes features and fixes
Column Name
Data Type
SQL_FEATURE
VARCHAR2(64)
DESCRIPTION
VARCHAR2(64)
PROPERTY
NUMBER
Fixes can be identified from DESCRIPTION column
WHERE description LIKE 'Fix%'

Individual fixes can be enabled and disabled. For example:
ALTER SESSION SET "_fix_control"='6776808:off';
17
© 2014 Julian Dyke
juliandyke.com
Features and Hints
V$SQL_FEATURE

Version counts are:
Version0
18
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 Hints
V$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:
SELECT lpad ( ' ' , level * 2 ,' ' ) || sql_feature
FROM v$sql_feature_hierarchy
CONNECT BY PRIOR sql_feature = parent_id
START WITH parent_id = 'QKSFM_ALL';
....
QKSFM_TRANSFORMATION
QKSFM_CBQT
QKSFM_CVM
QKSFM_DIST_PLCMT
QKSFM_JOINFAC
QKSFM_JPPD
QKSFM_PLACE_GROUP_BY
QKSFM_PULL_PRED
....
19
© 2014 Julian Dyke
juliandyke.com
Features and Hints
V$SQL_HINT


20
Based on X$QKSHT
 Currently no concept of unsupported hints
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)
Version
# Hints
11.2.0.3
273
11.2.0.4
277
12.1.0.1
314
12.1.0.2
332
INVERSE column
 Describes the opposite hint e.g.: PUSH_PRED and NO_PUSH_PRED
© 2014 Julian Dyke
juliandyke.com
Features and Hints
V$SQL_HINT

VERSION column
 Describes version in which hint was introduced:
Version
21
# New Hints
Version
# New Hints
8.0.0
14
10.2.0.4
2
8.1.0
50
10.2.0.5
4
8.1.5
18
11.1.0.6
32
8.1.6
4
11.1.0.7
5
8.1.7
2
11.2.0.1
19
9.0.0
26
11.2.0.2
6
9.2.0
13
11.2.0.3
6
10.1.0.3
42
11.2.0.4
2
10.2.0.1
35
12.1.0.1
37
10.2.0.2
4
12.1.0.2
18
10.2.0.3
3
© 2014 Julian Dyke
juliandyke.com
Execution
Plans
22
© 2014 Julian Dyke
juliandyke.com
Execution Plans
DBMS_XPLAN - Overview

Introduced in Oracle 9.2

Enhanced in subsequent releases

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:
SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR);
23
© 2014 Julian Dyke
juliandyke.com
Execution Plans
DBMS_XPLAN - FORMAT Column

All DISPLAY subroutines include a FORMAT column which can be:




24
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
© 2014 Julian Dyke
juliandyke.com
Execution Plans
DBMS_XPLAN - FORMAT Column Options
25

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
© 2014 Julian Dyke
juliandyke.com
Execution Plans
DBMS_XPLAN - Additional Statistics

For DISPLAY_CURSOR and DISPLAY_SQLSET, additional data can be output
using the following keywords:




26
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
© 2014 Julian Dyke
juliandyke.com
Execution Plans
Operations and Options

27
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
© 2014 Julian Dyke
juliandyke.com
Events
28
© 2014 Julian Dyke
juliandyke.com
Event 10046
Levels

Event 10046 has additional levels in recent versions
Level
29
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 execution
plan_stat = 'all_executions'
11.1 and
above
32 As level 1 without any execution plans
plan_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 10046
Bind Variables

Event 10046 level 4 trace only captures the first bind variable in array
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..3
INSERT INTO driver VALUES (d(j).key,d(j).name);
FORALL j IN 4..6
INSERT INTO driver VALUES (d(j).key,d(j).name);
END;
30
© 2014 Julian Dyke
juliandyke.com
Event 10046
Bind Variables

Trace will only contain bind variable values for two rows:
BINDS #139676743602632:
Bind#0
...
value="LHAM"
Bind#1
...
value="Lewis Hamilton"
Note this issue has
consequences for load
generation / simulation tools
such as HammerDB and
LoadRunner which base their
input on 10046 trace.
...
BINDS #139676743602632:
Bind#0
...
value="FALO"
Bind#1
...
value="Fernando Alonso"

31
Trace only includes first row of each array insert
 Remaining rows are not traced
© 2014 Julian Dyke
juliandyke.com
Event 10053
Optimizer Decisions

To trace optimizer decisions use enable event 10053:
Level

32
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
33

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
© 2014 Julian Dyke
juliandyke.com
Event 10053
DBMS_SQLDIAG


DUMP_TRACE procedure parameters are:
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'
);
34
© 2014 Julian Dyke
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)
juliandyke.com
ORADEBUG
35
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Introduction

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)

Requires SYSDBA privilege

Options vary for each release

To list available options use:
SQL> ORADEBUG HELP
36
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Process Specification

There are four ways of specifying a process in ORADEBUG:

Using current process:
SQL> ORADEBUG SETMYPID

Using Oracle PID (V$PROCESS.PID)
SQL> ORADEBUG SETORAPID <pid>

Using operating system PID (V$PROCESS.SPID)
SQL> ORADEBUG SETOSPID <spid>

Using the Oracle process name:
SQL> ORADEBUG SETORAPNAME <pname>

For example:
SQL> ORADEBUG SETORAPNAME PMON
37
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Useful Commands

To display the current trace file name use:
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

To set the TRACEFILE_IDENTIFER parameter:
SQL> ORADEBUG SETTRACEFILEID <suffix>

To dump the currently executing statement (SQL or PL/SQL)
SQL> ORADEBUG CURRENT_SQL
38
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Dumps

Dumps vary for each release:

To list available dumps:
SQL> ORADEBUG DUMPLIST

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]
39
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Process Statistics

To dump process statistics use ORADEBUG PROCSTAT. For example:
SQL> ORADEBUG SETORAPNAME PMON
SQL> ORADEBUG PROCSTAT
----- Dump of Process Statistics ----User time used = 65
System time used = 30
Maximum resident set size = 28452
Integral shared text size = 0
Integral unshared data size = 0
Integral unshared stack size = 0
Page reclaims = 7480
Page faults = 7
Swaps = 0
Block input operations = 1472
Block output operations = 32
Socket messages sent = 0
Socket messages received = 0
Signals received = 0
Voluntary context switches = 2555
Involuntary context switches = 387
40
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Components

ORADEBUG includes internal documentation for
 Components
 Events
SQL> ORADEBUG DOC
Internal Documentation
EVENT
COMPONENT
Help on events (syntax, event list, ...)
[<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
Parallel_Execution
41
List all components or describe <comp_name>
© 2014 Julian Dyke
SQL Execution (qer, qes, kx, qee)
Parallel Execution (qerpx, qertq, kxfr, kxfx, kxfq, kxfp)
juliandyke.com
ORADEBUG
Components

42
Components are grouped into eight libraries:
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
ORADEBUG
Components

For example given the extract below from ORADEBUG DOC COMPONENT:
Components in library RDBMS:
SQL_Compiler
SQL_Parser
SQL_Semantic
SQL_Optimizer
SQL_Transform
SQL_MVRW
SQL_Vmerge
SQL_Virtual
SQL_APA
SQL_Costing

The following are all valid:
SQL> ORADEBUG
SQL> ORADEBUG
SQL> ORADEBUG
SQL> ORADEBUG
SQL> ORADEBUG
43
SQL Compiler ((null))
SQL Parser (qcs)
SQL Semantic Analysis (kkm)
SQL Optimizer ((null))
SQL Transformation (kkq, vop, nso)
SQL Materialized View Rewrite ((null))
SQL View Merging (kkqvm)
SQL Virtual Column (qksvc, kkfi)
SQL Access Path Analysis (apa)
SQL Cost-based Analysis (kko, kke)
DOC RDBMS
DOC SQL_Compiler
DOC SQL_Optimizer
DOC SQL_Transform
DOC SQL_Vmerge
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events

The full event syntax is described in ORADEBUG:
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>[, ]
44
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events

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:
SQL> ORADEBUG DOC EVENT NAME
SQL> ORADEBUG DOC EVENT SCOPE
SQL> ORADEBUG DOC EVENT FILTER
SQL> ORADEBUG DOC EVENT ACTION
45
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - Name
46

Event names are optional:
 Can be specified for some libraries

For example for the RDBMS library:
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
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - Scope

Scope is the SQL scope for RDBMS events

Defined using SQL[ ]

Syntax is
[SQL: sql_id <string> ]

For example:
[SQL: 3s1yukp05bzg6]

Multiple SQL_IDs can be specified using | as a separator
[SQL: 3s1yukp05bzg6 | aca4xvmz0rzup]
47
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - Filter

Filters include:
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';
48
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - Filter

pgadep is the PGA depth (dep=N) in trace file.

Can take the following values:
 exactDepth
 lessThan
 greaterThan

For example:
{pgadep: exactdepth 0}
49

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
ORADEBUG
Events - Action
50

Actions exist for each library (except PLSQL)

For the RDBMS library most actions correspond to ORADEBUG DUMP
commands from older versions including:
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
ORADEBUG
Events - SQL_TRACE


SQL_TRACE is an synonym for event 10046 and can be set using:
 ORADEBUG
 ALTER SYSTEM
 ALTER SESSION
The ORADEBUG syntax is:
SQL> ORADEBUG DOC EVENT NAME SQL_TRACE
sql_trace: event for sql trace
Usage
sql_trace
wait
bind
plan_stat
level

51
< false | true >,
< false | true >,
< never | first_execution | all_executions | adaptive >,
<ub4>
The default level is 1
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - SQL_TRACE

For example:
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
52
© 2014 Julian Dyke
juliandyke.com
ORADEBUG
Events - Examples

Numeric events can be set using ORADEBUG. Default level is 1
ORADEBUG EVENT 10053
ORADEBUG EVENT 10053 LEVEL 1
ORADEBUG EVENT 10053 OFF

The original syntax still works in Oracle 11g/12c
ORADEBUG EVENT 10053 TRACE NAME CONTEXT FOREVER, LEVEL 1
ORADEBUG EVENT 10053 TRACE NAME CONTEXT OFF
53
© 2014 Julian Dyke
juliandyke.com
ALTER
Statements
54
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
SQL_TRACE

In all versions SQL_TRACE can be enabled using ALTER SESSION/SYSTEM

Examples shown for ALTER SESSION:
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';
55
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Numeric Events

Numeric events can still be set using ALTER SESSION / ALTER SYSTEM
SQL> ALTER SESSION SET EVENTS '10235';
SQL> ALTER SESSION SET EVENTS '10235 level 1';
SQL> ALTER SESSION SET EVENTS '10235 off';

The original syntax still works in Oracle 11g/12c
SQL> ALTER SESSION SET EVENTS '10235 trace name context forever, level 1';
SQL> ALTER SESSION SET EVENTS '10235 trace name context off';
56
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
SQL_TRACE - Filter

Trace can be restricted to a specific SQL ID by specifying a filter:
SQL> ALTER SESSION SET EVENTS
'sql_trace [sql: sql_id=3s1yukp05bzg6] bind=true, wait=true';

Multiple SQL IDs can be specified using the | symbol as a separator
SQL> ALTER SESSION SET EVENTS
'sql_trace [sql: sql_id=3s1yukp05bzg6|aca4xvmz0rzup] bind=true, wait=true';
57
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
TRACE - Components

Trace can be restricted to a specific components e.g.
SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*]';

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';

Individual components can also be filtered e.g.:
SQL> ALTER SESSION SET EVENTS
'trace[SQL_Optimizer.*][sql:3bnxc7htmf2ad]';
58
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Flushing Caches

To flush the buffer cache use:
ALTER SYSTEM FLUSH BUFFER_CACHE;

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:
ALTER SYSTEM FLUSH SHARED_POOL;

59
Pinned objects will not be flushed
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Block Dumps

To dump a database block in Oracle 8.0 or above:
ALTER SYSTEM DUMP DATAFILE <absolute_file_number>
BLOCK <block_number>;

To dump a range of database blocks:
ALTER SYSTEM DUMP DATAFILE <absolute_file_number>
BLOCK MIN <minimum_block_number>
BLOCK MAX <maximum_block_number>;

To dump a block from a datafile in a closed database:
ALTER SYSTEM DUMP DATAFILE '<file_name>'
BLOCK <block_number>;
60
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Block Dumps

In Oracle 12c ASSM bitmap blocks cannot be dumped by default
 Block is considered to be encrypted

Work around is to set
ALTER SESSION SET "_sga_clear_dump" = TRUE;

X$KSPPI description for this parameter is:
Allow dumping encrypted blocks in clear for debugging

61
Acknowledgements to Jonathan Lewis and Riyaj Shamsudeen for the above
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Redo Log Dumps

To identify the current redo log use:
SELECT member FROM v$logfile
WHERE group# =
(
SELECT group# FROM v$log
WHERE status = 'CURRENT'
);

To dump the contents of a redo log use:
ALTER SYSTEM DUMP LOGFILE '<logfilename>';

62
Also works for archived log files
© 2014 Julian Dyke
juliandyke.com
ALTER Statements
Redo 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;

63
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:
info@juliandyke.com
© 2014 Julian Dyke
juliandyke.com
Download