SELECT SID,
event,
total_waits,
total_timeouts,
time_waited,
average_wait,
max_wait,
time_waited_micro / 1000000
FROM v$session_event
ORDER BY SID, time_waited DESC
SELECT event,
SUM(wait_time + time_waited) total_wait_time
FROM v$active_session_history
GROUP BY event
ORDER BY total_wait_time DESC;
--To find out the users who experienced the most waits we can use below SQL.
SELECT [Link],
[Link],
SUM(a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a,
v$session s
WHERE a.session_id=[Link]
GROUP BY [Link],
[Link]
ORDER BY total_wait_time DESC;
--To find out the objects with the most waits we can use below SQL.
SELECT a.current_obj#,
d.object_name,
d.object_type,
[Link],
SUM(a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a,
dba_objects d
WHERE a.current_obj# = d.object_id
GROUP BY a.current_obj#,
d.object_name,
d.object_type,
[Link]
ORDER BY total_wait_time;
--we can identify the SQL statements that have been waiting the most with below
query.
SELECT a.user_id,
[Link],
s.sql_text,
SUM(a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a,
v$sqlarea s,
dba_users u
WHERE a.sql_id = s.sql_id
AND a.user_id = u.user_id
GROUP BY a.user_id,
s.sql_text,
[Link];
------------------------------------
--select top wait for instance
select
[Link]#,SQL_EXEC_ID,[Link],[Link]#,username,[Link],v.p1,v.p2,v.p3,sql_hash_value,s
ql_id,SQL_CHILD_NUMBER,s.seconds_in_wait
from v$session_wait v, v$session s where [Link] not like '%message%' and
[Link]=[Link]
and username is not null
order by sql_id;
--
select [Link] pu, [Link] su,[Link] stat,[Link] prog,[Link]
machine,[Link] ssid,
[Link]# sser, lpad([Link],7) spid, substr(sa.sql_text,1,2000) txt,
ltrim(to_char(floor(s.last_call_et/3600 ),'09')) ||':'
|| ltrim(to_char(floor(mod(s.last_call_et,3600)/60),'09')) ||':'
|| ltrim(to_char(mod(s.last_call_et,60),'09')) RUNT
from v$process p, v$session s, v$sqlarea sa
where [Link] = [Link] and [Link] is not null
and s.sql_address=[Link](+) and s.sql_hash_value=sa.hash_value(+)
--and spid != 3782
--and sa.sql_text like '%order by runt'
and [Link]<> 'ACTIVE' -- and [Link] in (3033,3022)
order by runt desc