查找 Oracle 用戶鎖的DLL SQL
這是Oracle DBA的常使用到的
也是我每天必用的腳本之一
運行此腳本之前請用SYS用戶登錄
create or replace procedure SYS
EEDBA_RPT_BLOCKING_SID IS
cursor C
is
select s
username Usrname
s
osuser osuser
s
sid
s
type lock_type
decode(lr
lmode
None
SS
SX
S
SSX
EX
) Mode_Held
lr
type
s
process UnixID
s
machine machine
s
terminal
s
status
a
owner||
||a
object_name object_hold
lr
block
s
program
s
logon_time
from all_objects a
v$locked_object o
v$session s
v$lock lr
where (id
id
) in (
select id
id
from v$lock le
where le
request >
)
and s
sid = lr
sid
and s
sid = o
session_id
and a
object_id (+)= o
object_id
order by lr
id
lr
id
lr
block desc ;
counter number :=
;
begin
dbms_output
new_line;
dbms_output
put_line(
Username OSUser SID Mode Type UNIX ID
||
Machine Terminal Active Object Logon Application
);
dbms_output
put_line(
======== ====== === ==== ==== =======
||
======= ======== ====== ====== ===== ===========
);
for r
in C
loop
if r
block >
and counter >
then
dbms_output
put_line(
);
dbms_output
put_line(
);
end if;
if r
block =
then
dbms_output
put(
+
);
end if;
dbms_output
put(r
Usrname);
dbms_output
put(
);
dbms_output
put(r
osuser);
dbms_output
put(
);
dbms_output
put(r
sid);
dbms_output
put(
);
dbms_output
put(r
Mode_Held);
dbms_output
put(
);
dbms_output
put(r
type);
dbms_output
put(
);
dbms_output
put(r
UnixID);
dbms_output
put(
);
dbms_output
put(r
machine);
dbms_output
put(
);
dbms_output
put(r
terminal);
dbms_output
put(
);
dbms_output
put(r
status);
dbms_output
put(
);
dbms_output
put(r
object_hold);
dbms_output
put(
);
dbms_output
put(r
logon_time);
dbms_output
put(
);
dbms_output
put_line(r
program);
counter := counter +
;
end loop;
if counter =
then
dbms_output
put_line(
);
dbms_output
put_line(
NO Blocking found
);
end if;
dbms_output
put_line(
);
dbms_output
put_line(
);
dbms_output
put_line(
End of report
);
end EEDBA_RPT_BLOCKING_SID ;
/
grant execute on SYS
EEDBA_RPT_BLOCKING_SID to system
/
From:http://tw.wingwit.com/Article/program/Oracle/201311/18777.html