oracle查詢鎖參考

2021-10-24 20:32:17 字數 2701 閱讀 9517

–獲取鎖的基本資訊

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 sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid;

–獲取sql文字

select l.session_id sid,

s.serial#,

l.locked_mode,

l.oracle_username,

s.user#,

l.os_user_name,

s.machine,

s.terminal,

a.sql_text,

a.action

from v$sqlarea a,

v$session s,

v$locked_object l

where l.session_id = s.sid

and s.prev_sql_addr = a.address

order by sid, s.serial#;

select distinct aa.sql_text,

t2.osuser,

t2.username,

t2.sid,

'alter system kill session '

''|| t2.sid||

','||t2.serial#||

''''

||';'

, t2.logon_time,

aa.first_load_time 操作時間,

t2.sql_id,

t2.process,

t2.machine,

aa.module,

aa.action,

ab.event 事件

from v$locked_object t1, v$session t2, v$sql aa,v$session_wait ab

where t1.session_id = t2.sid

and t2.sql_id = aa.sql_id

and t2.sid=ab.sid

order by t2.logon_time;

當session是active的時候,alter system kill session 只是將session標識為killed

或者pseudo狀態,並不會釋放session持有的資源,所以我們在執行完alter system kill session 後,看會話還

是一直存在。

這種情況下可以使用 immediate選項,強制立即kill會話,如下:

alter system kill session '3964,51752' immediate;

–獲取未提交sql, 沒有提交的sql不一定查詢的到,有可能從共享池裡面被移除了

select s.sid

, s.serial#

, s.username

, s.osuser

, s.program

, s.event

,to_char

(s.logon_time,

'yyyy-mm-dd hh24:mi:ss'),

to_char

(t.start_date,

'yyyy-mm-dd hh24:mi:ss'

), s.last_call_et

, s.blocking_session

, s.status

,( select q.sql_text

from v$sql q

where q.last_active_time = t.start_date

and rownum <=

1) as sql_text

from v$session s,

v$transaction t

where s.saddr = t.ses_addr;

–查詢package被哪些session鎖住, ddl鎖

select distinct aa.session_id sid,

'alter system kill session '

''|| aa.session_id ||

','||

vv.serial# ||

''''

||';'

, aa.session_id sid,

owner,

name,

aa.type,

mode_held held,

mode_requested request

from dba_ddl_locks aa, v$session vv

where aa.name =

'***_pub_insert'

and aa.session_id = vv.sid;

有不對的地方,還請指正,謝謝

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鎖資訊查詢

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 a.owner 方案名,a.object name 表名,b.xidusn 回滾段號,b.xidslot 槽號,b.xidsqn 序列號,b.session id 鎖表session id,b.oracle username 鎖表使用者名稱,decode d.type,xr null ...