/
seswait.sql
98 lines (68 loc) · 2.67 KB
/
seswait.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
set verify off
declare
r v$session_wait%rowtype;
begin
select * into r from v$session_wait where sid = &1;
dbms_output.put_line('');
if r.wait_time = 0 then -- See Metalink 43718.1 / 1360119.1
dbms_output.put_line('Session is waiting (no CPU activity)');
else
dbms_output.put_line('Session is waiting with CPU activity');
if r.wait_time > 0 then
dbms_output.put_line('Duration of last wait in 100th of seconds');
else
dbms_output.put_line('TODO: Implement me, wait_time = ' || r.wait_time);
-- wait_time = -2 -> 'Duration of last wait unknown'
-- wait_time = -1 -> 'Last wait < 1 ms'
-- wait_time < -2 -> 'Time has probl. wrapped'
end if;
end if;
dbms_output.put_line('');
dbms_output.put_line(r.event);
if r.event = 'db file sequential read' then -- See Metalink 181306.1 -- {
declare
ts varchar2( 30);
fn varchar2(500);
is_tempfile boolean;
begin
begin
select tablespace_name, file_name
into ts , fn
from dba_data_files
where file_id = r.p1;
is_tempfile := false;
exception when no_data_found then
-- If select statement does not return anything AND
-- r.p1 > db_files parameter THEN the file is probably
-- a tempfile:
select tablespace_name, file_name
into ts , fn
from dba_temp_files t join
v$parameter p on p.value + t.file_id = r.p1
where p.name = 'db_files';
is_tempfile := true;
end;
dbms_output.put_line(' Tablespace: ' || ts );
dbms_output.put_line(' File: ' || fn );
dbms_output.put_line(' Blocks: ' || r.p3);
if not is_tempfile then -- { Show segment name
declare
own varchar2(30);
seg varchar2(30);
typ varchar2(30);
begin
--
-- Slow query ahead
--
select owner, segment_name, segment_type
into own , seg , typ
from dba_extents
where file_id = r.p1 and
r.p2 between block_id and block_id + blocks - 1;
dbms_output.put_line(' Segment: ' || initcap(typ) || ' ' || own || '.' || seg);
end;
end if; -- }
end;
end if; -- }
end;
/