Friday, February 17, 2012

Do you have a wait problem?

SQL> select metric_name, value
2 from v$sysmetric
3 where metric_name in ('Database CPU Time Ratio',
4 'Database Wait Time Ratio') and
5 intsize_csec =
6 (select max(INTSIZE_CSEC) from V$SYSMETRIC);
METRIC_NAME VALUE
————————————------------ -----------
Database Wait Time Ratio 11.371689
Database CPU Time Ratio 87.831890

If the query shows a very high value for the Database Wait Time Ratio, or if the Database Wait Time Ratio is much greater than the Database CPU Time Ratio, the database is spending more time waiting than processing and you must dig deeper into the Oracle wait events to identify the specific wait events causing this.

top 5 database objects in use, along with the event associated with that database object, over the past 15 minutes

SELECT * FROM
(
SELECT o.object_name, o.object_type, s.event,
SUM(s.wait_time + s.time_waited) total_waited
FROM v$active_session_history s, dba_objects o
WHERE s.sample_time between sysdate - 1/24/4 and sysdate
AND s.current_obj# = o.object_id
GROUP BY o.object_name, o.object_type, s.event
ORDER BY 4 desc
WHERE rownum <= 5;

top 5 sessions that were using the most CPU resources [or waiting for resources] within the last 15 minutes

SELECT * FROM
(
SELECT s.username, s.module, s.sid, s.serial#, count(*)
FROM v$active_session_history h, v$session s
WHERE h.session_id = s.sid
AND h.session_serial# = s.serial#
AND session_state= 'ON CPU' AND
sample_time > sysdate - interval '15' minute
GROUP BY s.username, s.module, s.sid, s.serial#
ORDER BY count(*) desc
)
where rownum <= 5;

If you wanted to see the sessions that are waiting for
resources, you could issue the same query as previously, with a SESSION_STATE of WAITING