You are on page 1of 47

Oracle10g: Wait Interface

Improvements

Kirtikumar Deshpande

Hotsos Symposium 2005

1
Agenda
 Brief history of Oracle Wait Interface (OWI)

 What’s new in Oracle10g Release 1

 OWI views in Oracle10g Release 1

 Extended SQL Tracing

Q &A

2
Brief History of OWI
 Introduced in Oracle 7.0.12

 Four V$ views:
– V$SYSTEM_EVENT
– V$SESSION_EVENT
– V$SESSION_WAIT
– V$EVENT_NAME

 Extended SQL Trace / Debug Event 10046


– Trace level 8
– Trace level 12
3
Brief History of OWI
 Number of events tracked
– Oracle 7.0.12 less then 100
– Oracle 7.3.4 little over 100
– Oracle8i 8.1.7.4 over 200
– Oracle9i 9.2.0.4 around 400

 Changes to V$SESSION_EVENT View


– Oracle8: MAX_WAIT
– Oracle9i: TIME_WAITED_MICRO
4
What’s new in Oracle10g
Release 1
 Automatic Data Gathering

 Introduction of Wait Classes

 Enhanced existing wait event views

 Total Number of events tracked - 811 (10g R1 HP-UX 11.11)

 Over a dozen views report wait event information

 Improved E2E Extended SQL Tracing


5
Automatic Data Gathering
 AWR (Automatic Workload Repository)
– Collects cumulative and differential (delta) statistics at the
database level
– Collects metric statistics: rate of change in the cumulative
statistics
– Default: Freq - 1 Hour Retention - 7 Day
 ASH (Active Session History)
– Active sessions are sampled every second
 Time Model
– Tracks time spent in internal operations (parse, execute, I/O)
– Used in Self Tuning decisions
6
Introduction of Wait Classes
 Enables high-level analysis of Waits

 Classification
based on solution to correct
problematic wait events

 12 Wait Classes

 Defined in V$EVENT_NAME view

7
Enhanced V$EVENT_NAME View

Name Type Notes


-------------------- --------------- ---------------
EVENT# NUMBER
EVENT_ID NUMBER <<<< Oracle10g
NAME VARCHAR2(64)
PARAMETER1 VARCHAR2(64)
PARAMETER2 VARCHAR2(64)
PARAMETER3 VARCHAR2(64)
WAIT_CLASS_ID NUMBER <<<< Oracle10g
WAIT_CLASS# NUMBER <<<< Oracle10g
WAIT_CLASS VARCHAR2(64) <<<< Oracle10g

8
V$EVENT_NAME

EVENT# EVENT_ID NAME WAIT_CLASS# WAIT_CLASS


------ ---------- ------------------------ ----------- ------------
273 549236675 log file sequential read 9 System I/O
274 215477332 log file single write 9 System I/O
290 2652584166 db file sequential read 8 User I/O
291 506183215 db file scattered read 8 User I/O
292 1307477558 db file single write 8 User I/O
293 1620694733 db file parallel write 9 System I/O
294 834992820 db file parallel read 8 User I/O

9
Wait Classes & Nbr of Events
CLASS NBR_EVENTS
--------------- ----------
Administrative 42
Application 11
Cluster 45
Commit 1
Concurrency 17
Configuration 21
Idle 59
Network 25
Other 557
Scheduler 2
System I/O 19
User I/O 12
10
10g R1 HP-UX 11.11
Wait Classes - Examples
 Administrative (DBA tasks affecting others)
– Buffer pool resize
– Offline rollback segment
– Index rebuilds
 Application
– Row level locks or explicit locks
 Commit
– Redo log write confirmation
 Concurrency
– Buffer busy waits
– Library cache latch
11
Wait Classes - Examples
 Configuration
– Sizing for log buffer, log files, SGA components
– Contention for ST enqueue
 Network
– More data to/from database link/client
– Remote archive destination
 User I/O
– Database file reads, single writes,
– Direct path reads and writes
– BFILE reads

12
Wait Classes - Examples
 System I/O
– Redo log writes
– Archiving redo logs
– Control file writes
 Idle
– Indicates that session is inactive, waiting for
more work

13
Enhanced OWI Views
 New Columns:
– V$SYSTEM_EVENT
 EVENT_ID NUMBER

– V$SESSION_EVENT
 EVENT_ID NUMBER

– V$SESSION_WAIT
 WAIT_CLASS_ID NUMBER
 WAIT_CLASS# NUMBER
 WAIT_CLASS VARCHAR2(64)

14
Enhanced V$SESSION View
 Includes following columns from V$SESSION_WAIT
SEQ# NUMBER
EVENT# NUMBER
EVENT VARCHAR2(64)
P1TEXT VARCHAR2(64)
P1 NUMBER
P1RAW RAW(8)
P2TEXT VARCHAR2(64)
P2 NUMBER
P2RAW RAW(8)
P3TEXT VARCHAR2(64)
P3 NUMBER
P3RAW RAW(8)
WAIT_CLASS_ID NUMBER
WAIT_CLASS# NUMBER
WAIT_CLASS VARCHAR2(64)
WAIT_TIME NUMBER
SECONDS_IN_WAIT NUMBER
15
STATE VARCHAR2(19)
Enhanced V$SESSION View
 No need to join V$SESSION_WAIT to V$SESSION

 No need to query V$SESSION_WAIT view

SQL> select sid, username, event, wait_class

2 seconds_in_wait "SIW", state,


3 row_wait_obj# "RWO#",
4 row_wait_file# "RWF#"
5 from v$session
6 where seconds_in_wait !=0
16
7 and username is not null;
Enhanced V$SESSION View
SID USERNAME EVENT WAIT_CLASS SIW STATE RWO# RWF#
--- -------- ----------------------------- ----------- --- ----------------- ---- ----
43 SYSTEM db file scattered read User I/O 2 WAITED SHORT TIME 8980 5

38 KIRTI enq: TX - row lock contention Application 30 WAITING 8965 5

41 KIRTI SQL*Net message from client Idle 128 WAITING -1 0

In this example:
– RWO# shows the object number the session is accessing
– RWF# shows the absolute file number the session is accessing
– Event for SID 38 shows the type of Enqueue the session is waiting for

17
Number of Wait Events
 Over 800 wait events

 enqueue broken into 184 wait events


– No need to decipher P1, P2 values

 latch free broken into 28 wait events


– No need to decipher P1, P2 values

10g R1 HP-UX 11.11 18


New V$ Views with Wait data
 V$ACTIVE_SESSION_HISTORY
 V$EVENTMETRIC
 V$EVENT_HISTOGRAM
 V$SERVICEMETRIC_HISTORY
 V$SERVICE_EVENT
 V$SERVICE_WAIT_CLASS
 V$SESSION_WAIT_CLASS
 V$SESSION_WAIT_HISTORY
 V$SYSMETRIC_HISTORY
 V$SYSTEM_EVENT
 V$SYSTEM_WAIT_CLASS
 V$WAITCLASSMETRIC
 V$WAITCLASSMETRIC_HISTORY 19
New DBA Views with Wait Data
 DBA_HIST_EVENT_NAME
 DBA_HIST_SYSTEM_EVENT
 DBA_HIST_BG_EVENT_SUMMARY
 DBA_HIST_WAITCLASSMET_SUMMARY
 DBA_HIST_SERVICE_WAIT_CLASS
 DBA_HIST_ACTIVE_SESS_HISTORY

20
V$SESSION_WAIT_HISTORY
 Shows 10 most recent waits for the session
 No need to repetitively query V$SESSION_WAIT view

SID NUMBER
SEQ# NUMBER  1 to 10 (latest  oldest)
EVENT# NUMBER
EVENT VARCHAR2(64)
P1TEXT VARCHAR2(64)
P1 NUMBER
P2TEXT VARCHAR2(64)
P2 NUMBER
P3TEXT VARCHAR2(64)
P3 NUMBER
WAIT_TIME NUMBER  0 = waiting @snapshot time

WAIT_COUNT NUMBER 21
V$SESSION_WAIT_HISTORY

SID SEQ# EVENT P1 P2 P3 W_TM W_COUNT


--- ---- --------------------------- ---------- ---- ---- ----- -------
40 1 log file sync 962 0 0 0 1
40 2 SQL*Net message from client 1650815232 1 0 8721 1
40 3 SQL*Net message to client 1650815232 1 0 0 1
40 4 db file scattered read 5 225 4 0 1
40 5 db file scattered read 5 217 8 0 1
40 6 db file scattered read 5 209 8 0 1
40 7 db file scattered read 5 201 8 0 1
40 8 db file scattered read 5 193 8 1 1
40 9 db file scattered read 5 185 8 0 1
40 10 SQL*Net message to client 1650815232 1 0 0 1

10 rows selected.
22
V$EVENT_HISTOGRAM
 Histogram of
– Number of waits, maximum wait, wait time for each
event

 Predefined buckets, or time intervals


– < 1 ms, < 2 ms, < 4 ms, < 8 ms, < 16 ms ….
– >= 2²² ms

 TIMED_STATISTICS must be TRUE


23
V$EVENT_HISTOGRAM
Name Type
----------------- ------------
EVENT# NUMBER
EVENT VARCHAR2(64)
WAIT_TIME_MILLI NUMBER
WAIT_COUNT NUMBER

What’s missing?

24
V$EVENT_HISTOGRAM
EVENT# EVENT WAIT_TIME_MILLI WAIT_COUNT
------- ----------------------- --------------- ----------
294 db file sequential read 1 29453
294 db file sequential read 2 7319
294 db file sequential read 4 749
294 db file sequential read 8 904
294 db file sequential read 16 3395
294 db file sequential read 32 2167
294 db file sequential read 64 270
294 db file sequential read 128 56
294 db file sequential read 256 16
294 db file sequential read 512 9
295 db file scattered read 1 13397
295 db file scattered read 2 2202
295 db file scattered read 4 881
295 db file scattered read 8 822
295 db file scattered read 16 672
295 db file scattered read 32 523
295 db file scattered read 64 228 25
V$FILE_HISTOGRAM
FILE# SINGLEBLKRDTIM_MILLI SINGLEBLKRDS
---------- -------------------- ------------
5 1 5608
5 2 401
5 4 96
5 8 41
5 16 53
5 32 23
5 64 10
5 128 3
5 256 5
5 512 1

10 rows selected.
26
V$TEMP_HISTOGRAM
FILE# SINGLEBLKRDTIM_MILLI SINGLEBLKRDS
---------- -------------------- ------------
1 1 26
1 2 1
1 4 0
1 8 0
1 16 0
1 32 2

6 rows selected.

27
V$SYSTEM_WAIT_CLASS
 Instance level waits by Wait Class

 High-level wait information

 Sample information over time to track


Wait Classes of interest

28
V$SYSTEM_WAIT_CLASS
Name Type
-------------------- -----------
WAIT_CLASS_ID NUMBER
WAIT_CLASS# NUMBER
WAIT_CLASS VARCHAR2(64)
TOTAL_WAITS NUMBER
TIME_WAITED NUMBER

29
V$SYSTEM_WAIT_CLASS
WAIT_CLASS_ID WC# WAIT_CLASS TOTAL_WAITS TIME_WAITED
------------- ---- ---------------- ----------- -----------
3875070507 4 Concurrency 270 1596
3290255840 2 Configuration 378 1222
4217450380 1 Application 3680 321401
1893977003 0 Other 10394 65063
3386400367 5 Commit 28164 17657
1740759767 8 User I/O 72340 22764
2000153315 7 Network 79141 200
4108307767 9 System I/O 206748 174050
2723168908 6 Idle 1156193 364114196

9 rows selected.

What Classes are missing? Why? 30


V$SESSION_WAIT_CLASS
 Session level waits by Wait Class

 Somewhat High-level wait information

 Helps identify area(s) of concern


– Query by SID
– Query by WAIT_CLASS# or WAIT_CLASS_ID
– Use V$SESSION_EVENT to drill down

31
V$SESSION_WAIT_CLASS
Name Type
------------------- -------------
SID NUMBER
SERIAL# NUMBER
WAIT_CLASS_ID NUMBER
WAIT_CLASS# NUMBER
WAIT_CLASS VARCHAR2(64)
TOTAL_WAITS NUMBER
TIME_WAITED NUMBER

32
V$SESSION_WAIT_CLASS
 Sample output for WAIT_CLASS# = 8

SID SERIAL# WAIT_CLASS_ID WC# WAIT_CLASS TOTAL_WAITS TIME_WAITED


----- ------- ------------- --- ------------ ----------- -----------
42 3399 1740759767 8 User I/O 5605 397
43 643 1740759767 8 User I/O 35 70
47 1 1740759767 8 User I/O 1 0
49 1 1740759767 8 User I/O 333 297
53 1 1740759767 8 User I/O 98 126
54 1 1740759767 8 User I/O 5 5
55 1 1740759767 8 User I/O 809 816
56 1 1740759767 8 User I/O 190 25
57 1 1740759767 8 User I/O 10 1
58 1 1740759767 8 User I/O 6 3

10 rows selected.

33
V$SESSION_WAIT_CLASS
 Sample output for SID = 42

SID SERIAL# WAIT_CLASS_ID WC# WAIT_CLASS TOTAL_WAITS TIME_WAITED


----- ------- ------------- --- ------------ ----------- -----------
42 3399 1893977003 0 Other 1 0
42 3399 4217450380 1 Application 5 0
42 3399 3386400367 5 Commit 1 0
42 3399 2723168908 6 Idle 46116 234575
42 3399 2000153315 7 Network 46118 39
42 3399 1740759767 8 User I/O 5605 397
42 3399 4108307767 9 System I/O 3 0

7 rows selected.

34
V$ACTIVE_SESSION_HISTORY
 Shows Sampled Active Session Activity, including waits

 Sample frequency typically 1 second

 Active Session : Session w/ Waits not in Idle Wait Class

 Data stored in a circular buffer for 30 minutes

 Busy system may not show all the data

 AWR flushes the data to disk


– Viewable via DBA_HIST_ACTIVE_SESS_HISTORY 35
V$ACTIVE_SESSION_HISTORY
SAMPLE_ID NUMBER EVENT# NUMBER
SAMPLE_TIME TIMESTAMP(3) SEQ# NUMBER
*SESSION_ID NUMBER P1 NUMBER
*SESSION_SERIAL# NUMBER
P2 NUMBER
*USER_ID NUMBER
SQL_ID VARCHAR2(13) P3 NUMBER
SQL_CHILD_NUMBER NUMBER WAIT_TIME NUMBER
SQL_PLAN_HASH_VALUE NUMBER TIME_WAITED NUMBER
SQL_OPCODE NUMBER CURRENT_OBJ# NUMBER
SERVICE_HASH NUMBER
CURRENT_FILE# NUMBER
SESSION_TYPE VARCHAR2(10)
SESSION_STATE VARCHAR2(7) CURRENT_BLOCK# NUMBER
QC_SESSION_ID NUMBER PROGRAM VARCHAR2(48)
QC_INSTANCE_ID NUMBER MODULE VARCHAR2(48)
EVENT VARCHAR2(64) ACTION VARCHAR2(32)
EVENT_ID NUMBER
CLIENT_ID VARCHAR2(64)
36
V$SESS_TIME_MODEL
 Shows accumulated time model statistics
at session level

Name Type
----------- -----------------------
SID NUMBER
STAT_ID NUMBER
STAT_NAME VARCHAR2(64)
VALUE NUMBER

37
V$SESS_TIME_MODEL
SID STAT_NAME VALUE
--- ---------------------------------------- ----------
40 DB time 19376451
40 DB CPU 11492220
40 background elapsed time 0
40 background cpu time 0
40 sequence load elapsed time 0
40 parse time elapsed 62228
40 hard parse elapsed time 51538
40 sql execute elapsed time 19291646
40 connection management call elapsed time 36309
40 failed parse elapsed time 0
40 failed parse (out of shared memory) elap 0
40 hard parse (sharing criteria) elapsed ti 0
40 hard parse (bind mismatch) elapsed time 0
40 PL/SQL execution elapsed time 1508
40 inbound PL/SQL rpc elapsed time 0
40 PL/SQL compilation elapsed time 0
40 Java execution elapsed time 0

17 rows selected 38
E2E Extended SQL Tracing
 Trace Event 10046 with level 8, 12
 End to End Application Tracing by
– SID, SERIAL#
– Service Name
– Application Module
– Application Action
– Client Identifier
 DBMS_MONITOR Package Procedures
 Utility – trcsess
39
Tracing for SID, SERIAL#
 EXEC DBMS_MONITOR.SESSION_TRACE_ENABLE –
( session_id => 40, -
serial_num => 98, -
waits => true, -
binds => true );

 EXEC DBMS_MONITOR.SESSION_TRACE_DISABLE –
( session_id => 40, -
serial_num => 98 );

40
Tracing for Service, Module, Action
 Service Name must be set
– Init.ora parameter: SERVICE_NAMES
– TNSNAMES.ora parameter: SERVICE_NAME
– V$SESSION shows SERVICE_NAME

 Defaults:
– SYS$BACKGROUND (for all Oracle BG processes)
– SYS$USERS (for all User processes)

 DBMS_SERVICE package procedures


– CREATE_SERVICE
– DELETE_SERVICE
– DISCONNECT_SESSION
– START_SERVICE
– STOP_SERVICE
41
Tracing for Service, Module, Action
 Module Name must be set in the Application code
– OCI Attribute OCI_ATTR_MODULE
– DBMS_APPLICATION_INFO.SET_MODULE

 Action name must be set in the Application code


– OCI Attribute OCI_ATTR_ACTION
– DBMS_APPLICATION_INFO.SET_ACTION

 Default
– Module
 ‘SQL*Plus’ for connections via SQL*Plus
 Client program name
– Action
 None
42
Tracing for Service, Module, Action
 EXEC DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE –
( service_name => ‘APPS1’, -
module_name => ‘GLEDGER’, -
action_name => ‘DEBIT_ENTRY’, -
waits => true, -
binds => true, -
instance_name => null );

 EXEC DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE –
( service_name => ‘APPS1’, -
module_name => ‘GLEDGER’, -
action_name => ‘DEBIT_ENTRY’, -
waits => true, -
binds => true, -
instance_name => null );

43
Tracing for Client Identifier
 Client Identifier must be set by the Application
– OCI attribute OCI_ATTR_CLIENT_INFO
– DBMS_APPLICATION_INFO.SET_CLIENT_INFO
– DBMS_SESSION.SET_IDENTIFIER
– V$SESSION shows CLIENT_IDENTIFIER

 EXEC DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE -
( client_id => ‘KirtiD’, -
waits => true, -
binds => true );

 EXEC DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE -
( client_id => ‘KirtiD’);
44
Utility – trcsess
 Consolidates trace information into one output file from
multiple trace files

 The output file can be processed by TKPROF

 It is a shell script running a Java Application

 Options:
– Session Id
– Client Id
– Service
– Module
– Action 45
Utility – trcsess
 Syntax:

trcsess [output = file_name]


[session = SID.SERIAL# ]
[client_id = ‘client identifier’]
[service = ‘service name’ ]
[module = ‘module name’ ]
[action = ‘action name’ ]
[input_file_1 input_file2 …]

46
Oracle10g: Wait Interface
Improvements

Q&A

47

You might also like