-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathash_event_count_topN_new.sql
61 lines (55 loc) · 2.05 KB
/
ash_event_count_topN_new.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
REM
REM Script: ash_event_count_topN_new.sql
REM Author: Quanwen Zhao
REM Dated: Apr 25, 2018
REM
REM Purpose:
REM This sql script usually statistics Top-N event counts,
REM and when it runs you can only input 3 parameters - start_time you want to appoint,
REM end_time and num that is Top ROWNUM.
REM
REM Modified: May 08, 2018 - adding the justify center to the column "session_state", "blocking_session" and "blocking_session_serial#"
REM for running nicely; at the same time, also adding some interactive and friendly prompts when inputing 3
REM parameters.
REM May 09, 2018 - replace all of keywords (whatever SQL*Plus or SQL exclusive use) with uppercase.
REM
SET LINESIZE 400
SET PAGESIZE 300
SET VERIFY OFF
COLUMN event FORMAT a40
COLUMN wait_class FORMAT a15
COLUMN session_state HEADING "session|state" FORMAT a15 JUSTIFY center
COLUMN blocking_session HEADING "blocking|session" FORMAT 99999999 JUSTIFY center
COLUMN blocking_session_serial# HEADING "blocking|session|serial#" FORMAT 99999999 JUSTIFY center
PROMPT
PROMPT Enter begin time ([YYYY-MM-DD HH24:MI:SS]):
PROMPT Examples: 2018-03-13 11:20:00
PROMPT
PROMPT Enter end time ([YYYY-MM-DD HH24:MI:SS]):
PROMPT Examples: 2018-03-13 11:30:00
PROMPT
PROMPT Enter nums of Top-N ROWNUM:
PROMPT Examples: 15, 25 or 35 ...
PROMPT
SELECT *
FROM
( SELECT event
, wait_class
, session_state
, blocking_session
, blocking_session_serial#
, count(*)
FROM v$active_session_history
WHERE sample_time BETWEEN to_date('&start_time','yyyy-mm-dd hh24:mi:ss')
AND to_date('&end_time','yyyy-mm-dd hh24:mi:ss')
GROUP BY event
, wait_class
, session_state
, blocking_session
, blocking_session_serial#
ORDER BY count(*) DESC
, event
)
WHERE rownum <= &num
;
SET VERIFY ON