forked from fatdba/Oracle-Database-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ash_last_x_mins.sql
126 lines (121 loc) · 2.67 KB
/
ash_last_x_mins.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@plusenv
undef for_the_last_x_min
col pct format 99.9 head '%'
col cnt format 99999 head 'Ses|Cnt'
col oname format a60 head 'Object - Subobject'
col event format a38 head 'Wait Event / On CPU' trunc
col objid format 99999999 head 'Obj Id'
-- on cpu vs waiting --
with state_total as
(select count(*) evtot from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and session_state is not null
)
,sess_state as
(
select count(*) cnt, session_state
from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
group by session_state
)
select cnt
,(cnt/evtot)*100 pct
,session_state
from state_total
,sess_state
order by pct
/
-- by wait event --
with event_total as
(
select count(*) evtot from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and event is not null
)
,event_grp as
(
select cnt, event
from
(
select count(*) cnt, event
from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and event is not null
group by event
order by count(*) desc
)
where rownum <=15
)
select cnt
,(cnt/evtot)*100 pct
,event
from event_total
,event_grp
order by pct
/
-- on cpu : break down by sqlid --
with cpu_total as
(select count(*) cputot from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and session_state = 'ON CPU'
)
,sqlid_cpu as
(
select cnt, sql_id, current_obj#
from
(
select count(*) cnt, sql_id, current_obj#
from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and session_state = 'ON CPU'
group by sql_id, current_obj#
order by count(*) desc
)
where rownum <=15
)
select cnt
,(cnt/cputot)*100 pct
,'ON CPU' event
,sql_id
,current_obj# objid
,o.object_name||decode(subobject_name,null,' ',' - ')||subobject_name oname
from cpu_total
,sqlid_cpu g
,dba_objects o
where g.current_obj# = o.object_id (+)
order by pct
/
-- by wait event + sqlid + obj --
with event_total as
(select count(*) evtot from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and event is not null
and current_obj# >= 0
)
,event_grp as
(
select cnt, event, sql_id, current_obj#
from
(
select count(*) cnt, event, sql_id, current_obj#
from v$active_session_history
where sample_time > sysdate-&&for_the_last_x_min/1440
and event is not null
and current_obj# >= 0
group by event, sql_id, current_obj#
order by count(*) desc
)
where rownum <=15
)
select cnt
,(cnt/evtot)*100 pct
,event
,sql_id
,current_obj# objid
,o.object_name||decode(subobject_name,null,' ',' - ')||subobject_name oname
from event_total
,event_grp g
,dba_objects o
where g.current_obj# = o.object_id (+)
order by pct
/