-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathawr_act_active_sessions.sql
125 lines (109 loc) · 3.39 KB
/
awr_act_active_sessions.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
--==============================================================================
-- GPI - Gunther Pippèrr
-- Desc: get the statistic information over a the active sessions of a DB user
--
--==============================================================================
prompt
prompt !!!!You need the Tuning Pack for this feature!!!!
prompt
set linesize 130 pagesize 300
define DB_USER_NAME='&1'
define SERVICE_NAME='%'
prompt
prompt Parameter 1 = DB_USER_NAME => &&DB_USER_NAME.
prompt Parameter 2 = SERVICE_NAME => &&SERVICE_NAME.
prompt
column username format a10
column user_id format 9999999
column SESSION_ID format 9999999
column inst_id format 99
column SQL_ID format a15
column last_sample_id format 99999999999
column SAMPLE_TIME format a18
column serial format 999999
column SQL_EXEC_START format a18
column SQL_EXEC_ID format 9999999999
ttitle "SQL Summary" skip 2
select count(*)
,u.username
,ah.user_id
,ah.SESSION_ID
,ah.inst_id
,ah.SQL_ID
,max(SAMPLE_ID) as last_sample_id
,to_char(max(SAMPLE_TIME),'dd.mm.yyyy hh24:mi') as SAMPLE_TIME
,ah.SESSION_SERIAL# as serial
,ah.SQL_EXEC_START
from GV$ACTIVE_SESSION_HISTORY ah
,GV$ACTIVE_SERVICES ass
,dba_users u
where ass.inst_id = ah.inst_id
and ass.NAME_HASH = ah.SERVICE_HASH
--and ass.name like '%&&SERVICE_NAME.%'
and u.username like '%&&DB_USER_NAME.%'
and u.user_id = ah.user_id
and ah.SAMPLE_TIME > (sysdate - ((1 / (24 * 60)) * 60))
group by u.username
,ah.user_id
,ah.SESSION_ID
,ah.inst_id
,ah.SQL_ID
,ah.SESSION_SERIAL#
,ah.SQL_EXEC_ID
,ah.SQL_EXEC_START
--having count(*) > 25 * 60
order by max(SAMPLE_ID) desc
/
ttitle "Summary" skip 2
select count(*)
,u.username
,ah.inst_id
,ah.SESSION_ID
,ah.WAIT_CLASS
,max(SAMPLE_ID) as last_sample_id
,to_char(SAMPLE_TIME,'dd.mm.yyyy hh24:mi') as SAMPLE_TIME
from GV$ACTIVE_SESSION_HISTORY ah
,GV$ACTIVE_SERVICES ass
,dba_users u
where ass.inst_id = ah.inst_id
and ass.NAME_HASH = ah.SERVICE_HASH
--and ass.name like '%&&SERVICE_NAME.%'
and u.username like '%&&DB_USER_NAME.%'
and u.user_id = ah.user_id
and ah.SAMPLE_TIME > (sysdate - ((1 / (24 * 60)) * 60))
group by u.username
,ah.inst_id
,ah.SESSION_ID
,ah.WAIT_CLASS
, to_char(SAMPLE_TIME,'dd.mm.yyyy hh24:mi')
--having count(*) > 25 * 60
order by max(SAMPLE_ID) desc
/
ttitle "Summary only sessions" skip 2
select count(*), username,SAMPLE_TIME from (
select count(*)
,u.username
,ah.inst_id
,ah.SESSION_ID
,max(SAMPLE_ID) as last_sample_id
,to_char(SAMPLE_TIME,'dd.mm.yyyy hh24:mi') as SAMPLE_TIME
from GV$ACTIVE_SESSION_HISTORY ah
,GV$ACTIVE_SERVICES ass
,dba_users u
where ass.inst_id = ah.inst_id
and ass.NAME_HASH = ah.SERVICE_HASH
--and ass.name like '%&&SERVICE_NAME.%'
and u.username like '%&&DB_USER_NAME.%'
and u.user_id = ah.user_id
and ah.SAMPLE_TIME > (sysdate - ((1 / (24 * 60)) * 60))
group by u.username
,ah.inst_id
,ah.SESSION_ID
, to_char(SAMPLE_TIME,'dd.mm.yyyy hh24:mi')
--having count(*) > 25 * 60
order by max(SAMPLE_ID) desc
)
group by username,SAMPLE_TIME
order by SAMPLE_TIME
/
ttitle off