查詢oracle正在執行和執行過的sql語句--查詢oracle正在執行的sql語句及執行該語句的使用者
select b.sid oracleid,
b.username 登入oracle使用者名稱,
b.serial#,
spid 作業系統id,
paddr,
sql_text 正在執行的sql,
b.machine 計算機名
from v$process a, v$session b, v$sqlarea c
where a.addr =b.paddr
and b.sql_hash_value =c.hash_value
--檢視正在執行sql的發起者的發放程式
select osuser 電腦登入身份,
program 發起請求的程式,
username 登入系統的使用者名稱,
schemaname,
b.cpu_time 花費cpu的時間,
status,
b.sql_text 執行的sql
from v$session a
left join v$sql b on a.sql_address =b.address
and a.sql_hash_value =b.hash_value
order by b.cpu_time desc
--查出oracle當前的被鎖物件
select l.session_id sid,
s.serial#,
l.locked_mode 鎖模式,
l.oracle_username 登入使用者,
l.os_user_name 登入機器使用者名稱,
s.machine 機器名,
s.terminal 終端使用者名稱,
o.object_name 被鎖物件名,
s.logon_time 登入資料庫時間
from v$locked_object l, all_objects o, v$session s
where l.object_id =o.object_id
and l.session_id =s.sid
order by sid, s.serial#;
--kill掉當前的鎖物件可以為
alter system kill session
'sid, s.serial#『;
select * from v$access o where o.object like '
xxwpf007%
' --查詢正在執行的物件,獲取sid
select a.serial# from v$session a where a.sid=sid --通過sid 獲取serial#
alter system kill session
'sid,serial#
' --eg: alter system kill session '
123,3211
'select * from v$db_object_cache where name='
cux_oe_order_rpt_pkg
' and locks!='0'
;select sn.username,m.sid,sn.serial#,m.type,
decode(m.lmode,
0,'none
',1,'
null
',2,'
row share
',3,'
row excl.
',4,'
share
', 5,'
s/row excl.
',6,'
exclusive
',lmode,
ltrim(to_char(lmode,
'990
'))) lmode,
decode(m.request,
0,'none
',1, '
null
', 2,'
row share
', 3,'
row excl.
',4,'
share
', 5,'
s/row excl.
',6,'
exclusive
',request,
ltrim(to_char(m. request,
'990
'))) request,m.id1,m.id2
from v$session sn, v$
lock
m where (sn.sid = m.sid and m.request != 0
) or (sn.sid = m.sid and m.request = 0 and lmode != 4
and (id1, id2) in (select s.id1, s.id2
from v$
lock
s where request != 0
and s.id1 =m.id1
and s.id2 =m.id2))
order by id1, id2, m.request;
kill 所有占用資源的會話
命令形式:alter system kill session
'sid,serial#';
占用test_1的資源的會話:
alter system kill session
'158,15184
';
oracle鎖表檢視被鎖的表和解鎖
以下幾個為相關表 select from v lock select from v sqlarea select from v session select from v process select from v locked object select from all objects sele...
oracle檢視被鎖的表和解鎖
檢視鎖表程序sql語句1 select sess.sid,sess.serial lo.oracle username,lo.os user name,ao.object name,lo.locked mode from v locked object lo,dba objects ao,v ses...
oracle中檢視和刪除被鎖表
grant alter system to sa grant select on v lock to sa grant select on all objects to sa create or replace procedure d debug asv index varchar2 40 v ta...