Wait Events DatabaseSpecialists
Wait Events DatabaseSpecialists
Session Objectives
Define wait events Discuss how to use the wait event interface Walk through four examples of how wait event information was used to troubleshoot production problems
Idle Events
Sometimes an Oracle process is not busy simply because it has nothing to do. In this case the process will be waiting on an event that we call an idle event. Idle events are usually not interesting from the tuning and troubleshooting perspective.
10
12
Timed Statistics
The wait event interface will not collect timing information unless timed statistics are enabled.
Enable timed statistics dynamically at the instance or session level:
ALTER SYSTEM SET timed_statistics = TRUE; ALTER SESSION SET timed_statistics = TRUE;
15
Columns In v$system_event
EVENT: The name of a wait event TOTAL_WAITS: Total number of times a process has waited for this event since instance startup TOTAL_TIMEOUTS: Total number of timeouts while waiting for this event since instance startup TIME_WAITED: Total time waited for this wait event by all processes since instance startup (in centiseconds) AVERAGE_WAIT: The average length of a wait for this event since instance startup (in centiseconds)
17
Columns In v$session_event
SID: The ID of a session (from v$session) EVENT: The name of a wait event TOTAL_WAITS: Total number of times this session has waited for this event TOTAL_TIMEOUTS: Total number of timeouts while this session has waited for this event TIME_WAITED: Total time waited for this event by this session (in centiseconds) AVERAGE_WAIT: The average length of a wait for this event in this session (in centiseconds) MAX_WAIT: The maximum amount of time the session had to wait for this event (in centiseconds)
20
Columns In v$event_name
EVENT#: An internal ID NAME: The name of a wait event PARAMETERn: The name of a parameter associated with the wait event
23
24
25
Columns In v$session_wait
SID: The ID of a session SEQ#: A number that increments by one on each new wait STATE: An indicator of the session status:
WAITING: The session is currently waiting, and details of the wait event are provided. WAITED KNOWN TIME: The session is not waiting, but information about the most recent wait is provided. WAITED SHORT TIME or WAITED UNKNOWN TIME: The session is not waiting, but partial information about the most recent wait is provided.
26
Value of N Effect
1
4 8 12
32
33
Execution Plan ---------------------------------------------------------0 SELECT STATEMENT Optimizer=CHOOSE 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (BY INDEX ROWID) OF 'CUSTOMER_INQUIRIES' 3 2 INDEX (RANGE SCAN) OF 'CUSTOMER_INQUIRIES_N2' (NON-UNIQUE)
The CUSTOMER_INQUIRIES_N2 index was a concatenated index with status_code as its first column. The status_date column was not indexed.
34
Research Results
The database server was CPU starved. The run queue length often exceeded twice the number of CPUs on the server. Using just the status_code column of the CUSTOMER_INQUIRIES_N2 index made for a very unselective index lookup. Over 90% of the rows in the table had a status code of 12. A full table scan against CUSTOMER_INQUIRIES appeared to run faster than using the index.
37
Problem Resolution
A query against v$session_event after the modified query ran in isolation yielded:
TOTAL TIME EVENT WAITS WAITED ------------------------------ ----- -----db file scattered read 460 13 db file sequential read 3 1 latch free 1 0 SQL*Net message to client 10 0 SQL*Net message from client 9 18317
38
45
48
Problem Resolution
Multiple programs were attempting to update the same rows in tables at the same time. Contention could be reduced by doing one or more of the following:
Running conflicting programs separately Reducing lock scope Reducing lock duration
49
Manipulating timed_statistics
The timed_statistics parameter can be changed at any time at the session level with the following commands:
ALTER SESSION SET timed_statistics = TRUE; ALTER SESSION SET timed_statistics = FALSE;
Manipulate timed_statistics to collect wait event times during certain specific points of processing for debugging purposes.
51
52
Research Results
The form was fetching 9245 rows of reference data during startup. All of this data was necessary; none could be eliminated. All data was fetched one row at a time.
54
Problem Resolution
The startup logic of the form was modified to fetch 100 rows at a time. This yielded the following information in v$session_event:
TOTAL TIME EVENT WAITS WAITED ------------------------------ ----- -----SQL*Net message to client 200 0 SQL*Net message from client 199 28
56
57
59
Research Results
The instance had been up for about seven days. The latch contention was in the shared pool and library cache, as evidenced by a query against v$latch_misses:
PARENT_NAME SUM(LONGHOLD_COUNT) ------------------------------ ------------------enqueue hash chains 614 enqueues 637 Checkpoint queue latch 790 session allocation 1131 messages 1328 session idle bit 2106 latch wait list 5977 modify parameter values 6242 cache buffers chains 9876 row cache objects 38899 cache buffers lru chain 125352 shared pool 4041451 library cache 4423229
60
Problem Resolution
Bigger is not always better!
Reducing the shared pool to 100 Mb provided plenty of space for sharable statements while reducing the effort required by Oracle to maintain the library cache LRU list. This reduced latch contention and boosted performance.
62
64
In Conclusion
The wait event interface gives you access to a detailed accounting of how Oracle processes spend their time. Wait events touch all aspects of the Oracle database server. The wait event interface will not always give you the answer to every performance problem, but it will just about always give you insights that guide you down the proper path to problem resolution.
65
66
Database Rx
dbrx.dbspecialists.com/guest
Provides secure, automated monitoring, alert notification, and analysis of your Oracle databases
67
Contact Information
Roger Schrag
Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA 94111 Tel: 415/344-0500 Email: [email protected] Web: www.dbspecialists.com
68