forked from gwenshap/Oracle-DBA-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASH2.sql
151 lines (112 loc) · 4.81 KB
/
ASH2.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- how much history do we have:
select min(sample_time) from V$ACTIVE_SESSION_HISTORY
-- top events
select event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time> sysdate-1/24
and user_id>0
group by event
order by count(*) desc;
-- top sql
select sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time> sysdate-1/24
and user_id>0
group by sql_id
order by count(*) desc;
-- see specific samples
select sample_time,user_id,sql_id,event from DBA_HIST_ACTIVE_SESS_HISTORY
where 1=1
--and sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time> sysdate-1/24
--and user_id>0
--and session_id=371
order by sample_time;
-- look for hot buffers
select p1,p2,p3,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi')
and user_id>0
and event='buffer busy waits'
group by p1,p2,p3
order by count(*)
SELECT SEGMENT_NAME, SEGMENT_TYPE FROM DBA_EXTENTS
WHERE FILE_ID = 1 AND 231928 BETWEEN BLOCK_ID AND
BLOCK_ID + BLOCKS - 1;
-- top SQL waiting for a specific events
select sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> sysdate-1/24
and user_id>0
and event is null
group by sql_id
order by count(*)
-- top programs waiting for a specific events
select program,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi')
and user_id>0
and event='buffer busy waits'
group by program
order by count(*)
-- top users waiting for a specific events
select user_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi')
and user_id>0
and event='buffer busy waits'
group by user_id
order by count(*) 2 3 4 5 6 7 ;
-- Everyone waiting for specific event
select sample_time,user_id,sql_id,event,p1,blocking_session from V$ACTIVE_SESSION_HISTORY
where event like 'library%'
-- Who is waiting for specific event the most:
select SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*) from V$ACTIVE_SESSION_HISTORY
where event like 'log file sync'
group by SESSION_ID,user_id,sql_id,round(sample_time,'hh')
order by count(*) desc
select event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time< to_date('03-MAR-11 16:00','dd-mon-yy hh24:mi')
and user_id>0
group by event
order by count(*) desc
select to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi'),count(*) from DBA_HIST_ACTIVE_SESS_HISTORY
where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi')
and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi')
and user_id=209
and event='buffer busy waits'
group by to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi')
order by count(*)
select sql_id,count(*) from V$ACTIVE_SESSION_HISTORY
where sample_time> to_date('08-FEB-10 13:00','dd-mon-yy hh24:mi')
and sample_time< to_date('08-FEB-10 16:00','dd-mon-yy hh24:mi')
and user_id>0
group by sql_id
order by count(*) desc
select * from dba_views where view_name like 'DBA_HIST%'
select sh.sample_time,sh.SESSION_ID,user_id,sh.sql_id,event,p1,blocking_session,PROGRAM,sql_text
from DBA_HIST_ACTIVE_SESS_HISTORY sh
left outer join DBA_HIST_SQLTEXT sq on sq.sql_id=sh.sql_id
where 1=1
and sample_time> to_date('08-FEB-10 00:00','dd-mon-yy hh24:mi')
and sample_time< to_date('08-FEB-10 23:00','dd-mon-yy hh24:mi')
and user_id=61
--and sql_id='809u1jtt54kfy'
order by sample_time
select trunc(sample_time),
sum(case when INSTANCE_NUMBER=1 then 1 else 0 end) inst1,
sum(case when INSTANCE_NUMBER=2 then 1 else 0 end) inst2
from DBA_HIST_ACTIVE_SESS_HISTORY sh
where 1=1
and user_id=61
group by trunc(sample_time)
order by trunc(sample_time)
select * from DBA_HIST_SQLTEXT where sql_id='d15cdr0zt3vtp';
where dbms_lob.instr(sql_text, 'GLOBAL',1,1) > 0
desc DBA_HIST_ACTIVE_SESS_HISTORY
EXEC DBMS_MONITOR.session_trace_enable(session_id =>1234, serial_num=>1234, waits=>TRUE, binds=>FALSE);
select sample_time,user_id,sql_id,event,p1,blocking_session from V$ACTIVE_SESSION_HISTORY
where event like 'library%'
select * from v$active_session_history where session_id=306
6969666696
select SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*) from V$ACTIVE_SESSION_HISTORY
where event like 'log file sync'
group by SESSION_ID,user_id,sql_id,round(sample_time,'hh')
order by count(*) desc
select * from dba_users; 61