In this section of the practice, you will use the session wait event views to investigate into hung or
very slowly sessions. The target is to have further understanding on using the wait events in
performance troubleshooting. You will also learn how to use Oracle documentation to look up the
meaning of a wait event.
15. Open two new Putty sessions, and in each of them, invoke SQL*Plus and login as metals
sqlplus metals/metalsdb
16. Run the following query in each session. The second run should hang.
UPDATE EMP SET SALARY=SALARY WHERE EMP_NO=104;
17. In the sysdba session, display the SID and the current event of the hung session.
In our scenario, we expect the hung session to be in WAITING state. If it is not, find another way to identify the session.
Note: this section is not about studying the event 'enq: TX - row lock contention'. This event will be covered in more details later in the course.
SELECT SID, EVENT
FROM V$SESSION
WHERE STATE='WAITING' AND USERNAME ='METALS' AND WAIT_CLASS<>'Idle';
18. Display the wait event information of the hung session from the V$SESSION and from the
V$SESSION_EVENT. Run the queries multiple times and observe the increments in waiting time.
Observe that when the status is WAITING, the WAIT_TIME is zero and the SECONDS_IN_WAIT displays the waiting time.
col SESSION_WAITS format a100
SELECT 'SID: '|| SID||
CHR(10)||'USERNAME: '|| USERNAME||
CHR(10)||'STATE: '|| STATE||
CHR(10)||'EVENT: '|| EVENT||
CHR(10)||'WAIT_TIME: '|| WAIT_TIME||
CHR(10)||'SECONDS_IN_WAIT: '|| SECONDS_IN_WAIT||
CHR(10)||'WAIT_CLASS: '|| WAIT_CLASS||
CHR(10)||'P1TEXT: '|| P1TEXT||
CHR(10)||'P1: '|| P1||
CHR(10)||'P2TEXT: '|| P2TEXT||
CHR(10)||'P2: '|| P2 ||
CHR(10)||'P3TEXT: '|| P3TEXT||
CHR(10)||'P3: ' || P3 AS SESSION_WAITS
FROM V$SESSION
WHERE USERNAME='METALS' AND EVENT LIKE 'enq: TX%'
ORDER BY WAIT_TIME;
Practice 3 - Viewing Instance Activities and Wait Events Page | 8
Oracle Database Performance Tuning, a course by Ahmed Baraka
col EVENT for a30
SELECT E.EVENT,
TO_CHAR(ROUND(E.TIME_WAITED/100),'999,999,999') TIME_SECONDS
FROM V$SESSION_EVENT E, V$SESSION S
WHERE E.SID=S.SID AND S.USERNAME='metals' AND E.EVENT LIKE 'enq: TX%'
ORDER BY TIME_WAITED;
19. Retrieve information about the wait event from the V$SESSION_WAIT_HISTORY.
V$SESSION_WAIT_HISTORY view retrieves into the last 10 wait events in the current sessions.
Observe that the wait event is not registered in this view. As you will see soon, wait events are
registered in this view only after they expire.
SELECT COUNT(*) FROM V$SESSION_WAIT_HISTORY
WHERE EVENT LIKE 'enq: TX%';
The query from V$SESSION returns the wait event parameter values but their meanings may not be
clear to us. Let’s look up the wait event in the documentation.
20. In Oracle reference documentation, go to appendix C and look for what phrase “enq: TX - row
lock contention”.
If you do not have a copy of Oracle 12c R2 reference documentation You will see a
description of the wait event parameters.
Note: not all wait events are documented.
21. From the blocking session, rollback the transaction.
rollback;
22. Display the wait events from the V$SESSION for all the metals sessions.
Observe that the enqueue wait event does not appear any more in the V$SESSION view because the session is not currently waiting for the event.
col EVENT format a40
col WAIT_CLASS format a10
SELECT SID, EVENT, WAIT_CLASS
FROM V$SESSION
WHERE USERNAME='METALS';
Practice 3 - Viewing Instance Activities and Wait Events
Oracle Database Performance Tuning, a course by Ahmed Baraka
23. Display the wait events from the V$SESSION_EVENT for all the metals sessions.
Observe that the view reports the wait event that has been waited by the session.
SELECT E.EVENT,
TO_CHAR(ROUND(E.TIME_WAITED/100),'999,999,999') TIME_SECONDS
FROM V$SESSION_EVENT E, V$SESSION S
WHERE E.SID=S.SID AND S.USERNAME='METALS' AND E.EVENT LIKE 'enq: TX%' ORDER BY TIME_WAITED;
24. Retrieve information about the wait event that has just expired from the
V$SESSION_WAIT_HISTORY.
After the wait is expired, it is reported by the view.
col SESSION_WAITS format a100
SELECT 'SID: '|| SID||
CHR(10)||'EVENT: '|| EVENT||
CHR(10)||'WAIT_TIME: '|| WAIT_TIME||
CHR(10)||'P1TEXT: '|| P1TEXT||
CHR(10)||'P1: '|| P1||
CHR(10)||'P2TEXT: '|| P2TEXT||
CHR(10)||'P2: '|| P2 ||
CHR(10)||'P3TEXT: '|| P3TEXT||
CHR(10)||'P3: ' || P3 AS SESSION_WAITS
FROM V$SESSION_WAIT_HISTORY
WHERE EVENT LIKE 'enq: TX%'
ORDER BY WAIT_TIME;
25. Exit from the metals sessions
26. Verify that the wait events cannot be reported from V$SESSION_WAIT_HISTORY after the sessions
are disconnected.
Of course, they will not be seen in V$SESSION and V$SESSION_EVENT as well.
SELECT COUNT(*) FROM V$SESSION_WAIT_HISTORY WHERE EVENT LIKE 'enq: TX%';
27. To cleanup, exit from all the opened Putty sessions.
Practice 3 - Viewing Instance Activities and Wait Events
Summary
• V$SYSSTAT and V$SESSTAT views are used to retrieve instance activity statistics at the instance
level and at the session level respectively.
• V$MYSTAT is used to retrieve instance activity statistics on the current session.
• V$SYSTEM_EVENT, V$SESSION_EVENT views are used to retrieve wait event statistics at the
instance level (since instance last startup) and at the session level (for current sessions).
• The wait event statistics are gone from the V$SESSION_EVENT when the sessions are
disconnected.
No comments:
Post a Comment