Repository navigation
Expand file tree
/
Copy pathash-sqlid-event-window.sql
More file actions
71 lines (64 loc) · 1.74 KB
/
Copy pathash-sqlid-event-window.sql
File metadata and controls
71 lines (64 loc) · 1.74 KB
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
-- ash-sqlid-event-window.sql
-- Jared Still 2021 [email protected]
--
-- get all SQL running within a certain time each hour
-- in this case it is a 2 minutes window at the top of the hour
-- change the '-' to '+' to move the window around
col event format a40
set linesize 200 trimspool on
set pagesize 200
col pct_of_db_time format 999.99
break on inst_id on sql_id on session_id on session_serial# on sql_exec_id skip 1
with raw_data as (
select inst_id
, sql_exec_start
, sql_id
, session_id
, session_serial#
, sql_exec_id
,decode(session_state,'ON CPU','ON CPU',h.event) event
from gv$active_session_history h
where
sample_time between
trunc(sample_time,'hh24') - numtodsinterval(1,'minute')
and
trunc(sample_time,'hh24') + numtodsinterval(1,'minute')
and sql_id is not null
), summarized as(
select distinct inst_id, sql_exec_start, session_id, session_serial#, sql_exec_id, sql_id, event
,count(*)
over (
partition by inst_id, session_id, session_serial#, sql_exec_id, sql_exec_start, sql_id, event
order by inst_id, session_id, session_serial#,sql_id
) event_count
,count(*)
over (
partition by inst_id, session_id, session_serial#, sql_exec_id, sql_exec_start, sql_id
order by inst_id, session_id, session_serial#,sql_id
) event_sum
from raw_data
), rpt_data as (
select inst_id
, sql_exec_start
, sql_id
, session_id
, session_serial#
, sql_exec_id
, event
, event_count
, event_sum
--, event_count / event_sum * 100 pct_of_db_time
from summarized
)
select inst_id
, sql_id
, session_id
, session_serial#
, sql_exec_id
, event
, event_count
, event_sum
from rpt_data
where event_sum > 5
order by inst_id, sql_id, session_id, session_serial#, sql_exec_id, event_count
/