Oracle鎖資訊查詢

2021-09-26 23:11:55 字數 3955 閱讀 8501

--oracle鎖資訊查詢

--查詢oracle會話資訊

select * from v$session t order by t."logon_time";

--查詢oracle等待的會話資訊

select * from v$session_wait t order by t."seconds_in_wait" desc;

--查詢oracle所有的鎖

select * from v$lock t order by t."lmode" desc;

--查詢oracle包含dml的鎖資訊

select * from v$locked_object t;

--查詢oracle對v$lock的格式化檢視

select * from dba_locks t order by t.mode_held;

--查詢oracle程序資訊

select * from v$process t;

--查詢oracle執行過的sql語句

select * from v$sql t;

select * from v$sqlarea t order by t."first_load_time";

--查詢oracle死鎖程序與解鎖語句 

select t1."sid",

t1."serial#",

t2."oracle_username",

t2."os_user_name",

t3.object_name,

t2."locked_mode",

'alter system kill session ''' || t1.sid || ',' || t1.serial# || '''' as freesql

from v$session t1, v$locked_object t2, dba_objects t3

where t1."sid" = t2."session_id"

and t2."object_id" = t3.object_id;

--殺掉鎖表程序:如有記錄則表示有lock,記錄下sid和serial#,將記錄的id替換下面的738,1429,即可解除lock 

--alter system kill session '434,45624';

--查詢oracle正在執行的sql語句及執行該語句的使用者

select t2.sid      as oracleid,

t2.username as oracle使用者,

t2.serial#,

t1.spid     as 作業系統id,

t2.paddr,

t3.sql_text as 正在執行的sql,

t2.machine  as 計算機名,

t2."status"

from v$process t1, v$session t2, v$sqlarea t3

where t1.addr = t2.paddr

and t2.sql_hash_value = t3.hash_value

and t2."status" = 'active'

order by t2.username;

--查詢oracle正在執行的sql

select t1.serial#,

t1.osuser     as 電腦登入身份,

t1.program    as 發起請求的程式,

t1.username   as 登入系統的使用者名稱,

t1.schemaname,

t2.cpu_time   as 花費cpu的時間,

t1.status,

t2.sql_text   as 執行的sql

from v$session t1, v$sql t2

where t1.sql_address = t2.address

and t1.sql_hash_value = t2.hash_value

and t1."status" = 'active'

order by t2.cpu_time desc;

--查詢oracle鎖定表

select t1.sid,

t1.serial#,

t1.username,

t1.schemaname,

t1.osuser,

t1.process,

t1.machine,

t1.terminal,

t1.logon_time,

t2."lmode",

t2.type

from v$session t1, v$lock t2

where t1.sid = t2.sid

and t1.username is not null

order by t2."lmode" desc;

--查詢oracle鎖

select t1.username    as user_name,

t3.object_name as object_name,

t2.type        as lock_type,

t2.lmode,

t3.owner,

t2.sid,

t1.serial#     as serial_num,

t2.id1,

t2.id2,

t1.paddr

from v$session t1, v$lock t2, sys.dba_objects t3

where t1."sid" = t2."sid"

and t2."id1" = t3.object_id

and t3.owner <> 'sys'

order by t3.owner, t3.object_name;

--查詢oracle死鎖

select t1.session_id sid,

t3.serial#,

t1.locked_mode,

t1.oracle_username,

t1.os_user_name,

t3.machine,

t3.terminal,

t2.object_name,

t3.logon_time

from v$locked_object t1, all_objects t2, v$session t3

where t1.object_id = t2.object_id

and t1.session_id = t3.sid

order by sid, t3.serial#;

--查詢oracle所有鎖資訊

select t1."type",

t1."lmode",

t2."serial#",

t2."osuser",

t2."username",

t2."schemaname",

t3."cpu_time",

t2."status",

t3."sql_text"

from v$lock t1, v$session t2, v$sql t3

where t1."sid" = t2."sid"

and t2."sql_address" = t3."address"

and t2."sql_hash_value" = t3."hash_value"

order by t1."lmode" desc;

--查詢sql和對應的鎖資訊

select t1.sid, t1.serial#, t1.username, t1.event, t2.sql_text, t3."lmode"

from v$session t1, v$sql t2, v$lock t3

where t1.prev_sql_id = t2.sql_id

and t1.sid = t3.sid

and t2."sql_text" like '%select * from sms for update%';

oracle 查詢鎖表資訊

select a.owner 方案名,a.object name 表名,b.xidusn 回滾段號,b.xidslot 槽號,b.xidsqn 序列號,b.session id 鎖表session id,b.oracle username 鎖表使用者名稱,decode d.type,xr null ...

ORACLE鎖表查詢

select rule lpad decode l.xidusn 0,3,0 l.oracle username user name,o.owner,o.object name,o.object type,s.sid,s.serial from v locked object l,dba objec...

oracle查詢鎖參考

獲取鎖的基本資訊 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 session...