Beruflich Dokumente
Kultur Dokumente
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
juliandyke.com
Trace Parameters
juliandyke.com
juliandyke.com
In Oracle 9.2 foreground process trace file names are in the following formats
Process Type ss92001_ora_1234.trc ss92001_p000_1234.trc Name Foreground Process Parallel execution slave
ss92001_j000_1234.trc
ss92001_d000_1234.trc ss92001_s000_1234.trc
These trace files are written to the USER_DUMP_DEST directory In Oracle 9.2 background process trace file names are in the format
ss92001_<process_name>_1234.trc
juliandyke.com
Events
There are four types of numeric events Immediate dumps Conditional dumps Trace dumps Change database behaviour Each event has 1 or more level which can be range e.g. 1 to 10 bitmask e.g. 0x01 0x02 0x04 0x08 0x10 etc flag e.g. 0 = off; 1 = on identifier e.g. object id, memory address, etc
juliandyke.com
Events
Alternatively use
ORADEBUG DBMS_SYSTEM.SETEV
juliandyke.com
Events
juliandyke.com
Events
juliandyke.com
Events
10
juliandyke.com
SQL Trace
0
1 4 8 12
Disabled
Same as ALTER SESSION SET sql_trace = TRUE Include bind information Include event wait statistics Include bind information and event wait statistics
11
juliandyke.com
Optimiser Decisions
To trace the computations performed by the CBO when optimising SQL statements use
ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL <level>';
Level
1 2
Description
Print statistics and computations Print computations only
See "A Look under the Hood of CBO : The 10053 Event" Wolfgang Breitling - www.centrexcc.com
12
juliandyke.com
Events
10391
13
juliandyke.com
Events
14
Events
15
juliandyke.com
-- Disable SQL trace with binds ALTER SESSION SET EVENTS '10046 trace name context off';
16
juliandyke.com
# Enable SQL*trace with binds event = '10046 trace name context forever, level 4';
The SQL_TRACE parameter cannot be modified directly using ALTER SYSTEM. Instead use
-- Enable SQL trace for instance ALTER SYSTEM SET EVENTS '10046 trace name context forever, level 1;
-- Disable SQL trace for instance ALTER SYSTEM SET EVENTS '10046 trace name context off';
17
juliandyke.com
18
juliandyke.com
ALTER SESSION SET EVENTS 'immediate trace name trace_buffer_on level <level>';
19
juliandyke.com
DBMS_SESSION
20
juliandyke.com
CREATE OR REPLACE TRIGGER us01_logoff BEFORE LOGOFF ON us01.SCHEMA BEGIN dbms_session.set_sql_trace (FALSE); END;
21
juliandyke.com
DBMS_SYSTEM
$ORACLE_HOME/rdbms/admin/dbmsutil.sql
22
juliandyke.com
DBMS_SYSTEM
SID and Serial number can be found in V$SESSION (SID and SERIAL#)
23
juliandyke.com
DBMS_SYSTEM
For example
EXECUTE DBMS_SYSTEM.SET_BOOL_PARAM_IN_SESSION (9, 27, 'hash_join_enabled', TRUE);
24
juliandyke.com
DBMS_SYSTEM
For example
EXECUTE DBMS_SYSTEM.SET_INT_PARAM_IN_SESSION (9, 27, 'sort_area_size', 131072);
25
juliandyke.com
DBMS_SYSTEM
-- SID -- Serial Number -- Event Number e.g. 10046 -- Level e.g. 1 -- Action Name can be ''
Disable using same SID, serial number and event with level 0
26
juliandyke.com
DBMS_SYSTEM
Example
BEGIN DBMS_SYSTEM.KSDWRT (1, Output to trace file); DBMS_SYSTEM.KSDWRT (2, Output to alert log); END; /
27
juliandyke.com
DBMS_SYSTEM
28
juliandyke.com
DBMS_SUPPORT
Available in Oracle 7.2 and above Requires dbmssupp.sql and prvtsupp.plb See Metalink Note 62294.1 Install using SYS AS SYSDBA
$ORACLE_HOME/rdbms/admin/dbmssupp.sql GRANT EXECUTE ON DBMS_SUPPORT TO <user>; CREATE PUBLIC SYNONYM dbms_support FOR sys.dbms_support;
29
juliandyke.com
DBMS_SUPPORT
To disable use
DBMS_SUPPORT.STOP_TRACE;
30
juliandyke.com
DBMS_SUPPORT
To disable use
DBMS_SUPPORT.STOP_TRACE_IN_SESSION ( SI NUMBER, -- SID SE NUMBER -- Serial Number (can be 0) );
31
juliandyke.com
DBMS_MONITOR
32
juliandyke.com
DBMS_MONITOR
Trace can be enabled using client identifiers To set a client identifier use
DBMS_SESSION.SET_IDENTIFIER ( CLIENT_ID VARCHAR2 );
-- Client ID
The client identifier for a specific session can be found by querying V$SESSION.CLIENT_IDENTIFIER
33
juliandyke.com
DBMS_MONITOR
Trace can be enabled using client identifiers To enable trace for a specific client use
DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE ( CLIENT_ID NUMBER, -- Client ID WAITS BOOLEAN, -- Include Waits BINDS BOOLEAN -- Include Binds );
34
juliandyke.com
DBMS_MONITOR
Trace can be enabled for a specific service service and module service, module and action To add a service in a RAC database use DBCA Enterprise Manager (Oracle 10.2 and above)
35
juliandyke.com
DBMS_MONITOR
To add a service in a single instance environment Set the SERVICE_NAMES parameter e.g.
service_names = 'LX101001, SERVICE1'
36
juliandyke.com
DBMS_MONITOR
-- Module
37
juliandyke.com
DBMS_MONITOR
If ACTION_NAME is not specified, entire module will be traced Tracing can be disabled using SERV_MOD_ACT_TRACE_DISABLE
38
juliandyke.com
DBMS_MONITOR
Statistics externalized in V$CLIENT_STATS Disable using DBMS_MONITOR.CLIENT_ID_STAT_DISABLE To enable statistics collection for a specific module/action
DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE ( SERVICE_NAME VARCHAR2, -- Service Name MODULE_NAME VARCHAR2, -- Module ACTION_NAME VARCHAR2 -- Action );
39
juliandyke.com
trcsess
Introduced in Oracle 10.1 Conditionally extracts trace data Merges trace files trcsess [output = <output_file_name>] [session = <session_id>] [clientid = <client_id>] [service = <service_name>] [module = <module_name>] [action = <action_name>] <trace_file_names>
where trace_file_names can be space separated list of file names or '*' wildcard service, action and module names are case sensitive
juliandyke.com
DBA_ENABLED_TRACES
41
Based on WRI$_TRACING_ENABLED
juliandyke.com
ORADEBUG
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)
42
juliandyke.com
ORADEBUG
43
juliandyke.com
ORADEBUG
To set the maximum size of the current trace file to UNLIMITED use
ORADEBUG UNLIMIT
44
juliandyke.com
ORADEBUG
To perform a dump
ORADEBUG DUMP <dumpname> <level>
45
juliandyke.com
ORADEBUG
While the process is suspended ORADEBUG can be used to dump perform memory/state dumps Can be also used to temporarily suspend long running processes
46
juliandyke.com
ORADEBUG
where level is
Level 1 2 3 Description Session Process System
47
juliandyke.com
ORADEBUG
To enable events in another process For foreground processes Oracle Process ID can be obtained from Session ID using
SELECT pid FROM v$process p, v$session s WHERE p.addr = s.paddr AND s.sid = <sid>;
48
juliandyke.com
ORADEBUG
For example
ORADEBUG DUMPVAR SGA kcbnhb
prints the number of buffer cache hash buckets The names of SGA variables can be found in X$KSMFSV.KSMFSNAM Variables in this view are suffixed with an underscore e.g. kcbnhb_
49
juliandyke.com
ORADEBUG
In some versions it is possible to dump the entire SGA to file Freeze the instance using
ORADEBUG FFBEGIN
50
juliandyke.com
Immediate Dumps
There are three ways of taking an immediate dump In the current session
ALTER SESSION SET EVENTS 'immediate trace name <dump> level <level>';
In ORADEBUG
ORADEBUG DUMP <dump> <level>
Using DBMS_SYSTEM
EXECUTE DBMS_SYSTEM.SET_EV (sid, serial#, 65535, <level>, '<dump'>);
51
juliandyke.com
Conditional Dumps
In ORADEBUG
ORADEBUG EVENT <error> trace name <dump> level <level> ORADEBUG SESSION_EVENT <error> trace name <dump> level <level>
52
juliandyke.com
Dumping Columns
To dump the internal representation of columns use the DUMP built-in function
DUMP (COLUMN_VALUE, FORMAT)
where FORMAT is
Format 8 10 16 17 Description Octal Decimal Hexadecimal Single Character
53
juliandyke.com
Dumping Columns
For example
SELECT DUMP (1001,16) FROM dual;
returns
Typ=2 Len=3: c2,b,2
returns
10000
54
juliandyke.com
To dump a database block in Oracle 7 File number / block number must be converted into a data block address
COLUMN decimalDBA new_value decimalDBA SELECT dbms_utility.make_data_block_address (&file,&block) decimalDBA FROM dual; ALTER SESSION SET EVENTS 'immediate trace name blockdump level &decimalDBA';
55
juliandyke.com
56
juliandyke.com
or
ALTER SYSTEM SWITCH LOGFILE;
57
juliandyke.com
Dumping an Index
where object_id is the object number of the index (in DBA_OBJECTS) Dumps branches leaves contents of leaf blocks
58
juliandyke.com
Dumping an Index
In Oracle 9.2 treedump may crash if index has been created by a primary/unique constraint e.g.
CREATE TABLE t1 (c01 NUMBER PRIMARY KEY);
CREATE TABLE t1 (c01 NUMBER); ALTER TABLE t1 ADD CONSTRAINT t1pk PRIMARY KEY (c01);
Occurs when IND$.PROPERTY > 256 Can be prevented by creating the index before creating the constraint
59
juliandyke.com
Dumping Undo/Rollback
60
juliandyke.com
61
juliandyke.com
Control Files
ALTER SESSION SET EVENTS 'immediate trace name controlf level 15';
File Headers
ALTER SESSION SET EVENTS 'immediate trace name file_hdrs level 7';
62
juliandyke.com
where level is
Level 1 Description Dump library cache statistics
2
3 4
63
juliandyke.com
where level is
Level
1 2 8
Description
Dump row cache statistics Include hash table histogram Include dump of object structures
64
juliandyke.com
where level is
Level
1 2
Description
Include PGA Include SGA
4
8
Include UGA
Include indirect memory dumps
65
juliandyke.com
66
juliandyke.com
ALTER SESSION SET EVENTS 'immediate trace name heapdump level <level>';
where level is
Description Level Description
Level
1 PGA summary
2 SGA summary 4 UGA summary 8 Current call (CGA) 16 User call (CGA) 32 Large pool (LGA)
67
juliandyke.com
Get address of subheap e.g. 0x8057eb78 Convert to decimal e.g. 2153245560 For a summary dump use
ALTER SESSION SET EVENTS 'immediate trace name heapdump_addr level 2153245560';
68
juliandyke.com
69
juliandyke.com
SGA Memory
SGA Memory can be accessed directly using X$KSMMEM Each row contains the four byte value at address ADDR in the SGA Always use the INDX column to access this table For example, to select first word in SGA use
SELECT ksmmmval FROM x$ksmmem WHERE indx = 0;
70
juliandyke.com
Dumping Buffers
Levels are
Levels Description
1 Buffer headers only 2 1 + block headers
3 2 + block contents
4 Buffer headers only 5 1 + block headers 6 2 + block contents 8 Buffer headers only 9 1 + block headers 10 2 + block contents
71
+ hash chain + hash chain + hash chain + hash chain + users/waiters + hash chain + users/waiters + hash chain + users/waiters
juliandyke.com
To dump all buffers currently in the cache for a specific block First identify the tablespace number for the block e.g for TS01
SELECT ts# FROM sys.ts$ WHERE name = 'TS01';
72
juliandyke.com
73
juliandyke.com
Appears to flush all buffer caches Only flushes unpinned buffers Moves all unpinned buffers to auxiliary replacement list
74
juliandyke.com
State Objects
State objects are structures in the SGA describing state of various database entities Common state objects include
# Description
2 Process
3 Call 4 Session 6 Enqueue 24 Buffer 34 DML Locks 38 Transaction 51 Library Object 52 Library Object Pin
61 Hash Table
75
juliandyke.com
A process state dump contains all the state objects for the process
ALTER SESSION SET EVENTS 'immediate trace name processstate level 10';
Amount of library cache dump output for state object dumps can be limited using event 10065
Level Description
1 Address of library object only 2 As 1 plus library object lock details 3 As 2 plus library object handle and library object
76
juliandyke.com
A system state dump contains a process state dump for each process
ALTER SESSION SET EVENTS 'immediate trace name systemstate level 10';
This prints a large amount of information Use HANG_ANALYZE for details on currently active processes
77
juliandyke.com
A hang analysis dump prints process state for active processes e.g. waiting, blocking or spinning
ALTER SESSION SET EVENTS 'immediate trace name hanganalyze level 5';
Available in 8.0.6, 8.1.6 and above Not available in 8.1.5 Contains system state level 1 process states error stacks Oracle recommends level 5
78
juliandyke.com
An error stack describes the current state of a process. Includes the current SQL statement and the process state for the process.
ALTER SESSION SET EVENTS 'immediate trace name errorstack level <level>';
Levels are
Level Description
0 Error stack only 1 Error stack and function call stack 2 As 1 plus the process state 3 As 2 plus the context area
79
juliandyke.com
Levels include
Level Description 1 Hash Table 2 Enqueue headers
3 Enqueue details
Levels include
Level Description 1 Latches
2 Include statistics
80
juliandyke.com
Dumping Granules
In Oracle 9.0.1 and above To dump the current state of all granules
ALTER SESSION SET EVENTS 'immediate trace name granulelist level <level>';
Levels include
Level Description 255 Null Granule 511 Home Granule 767 Shared Pool 1023 Large Pool 1279 Java Pool
81
juliandyke.com
Levels 1-14 give increasing amounts of detail In 8.1.7 and below this is called MTSSTATE To trace dispatcher behaviour
EVENT='10248 trace name context forever, level 10';
82
juliandyke.com
Tracing can be set for SQL*Net Client SQL*Net Server Listener TNSPING Utility Names NAMESCTL Utility
83
juliandyke.com
Intelligent Agent
Tracing can be set for Intelligent Agent Agent Job Subsystem AGENTCTL Utility Data Collection Event Subsystem See Metalink Note 177236.1
84
juliandyke.com
RAC
85
juliandyke.com
RAC
The g command prefix can also be used with LKDEBUG e.g for the default instance
ORADEBUG g DEF LKDEBUG s
86
juliandyke.com
RAC
To dump the current state of the global cache elements with block dumps
ALTER SESSION SET EVENTS 'immediate trace name locks level <level>';
87
juliandyke.com
RAC
To restrict the amount of information generated by this trace set _ksi_trace e.g to restrict trace to TM and TX locks set
_ksi_trace = 'TMTX';
88
juliandyke.com
RAC
Tracing can be set for GSD GSDCTL SRVCONFIG SRVCTL In Oracle 9.0.1 and 9.2 See Metalink Note 178683.1 In Oracle 10.1 and above Set the environment variable SRVM_TRACE to true
89
juliandyke.com
Any Questions?
Julian Dyke
Intel Solution Services 650 Wharfedale Road Winnersh Triangle Wokingham Berkshire RG41 5TP
julian.dyke@intel.com
90
juliandyke.com