查詢被鎖的表 ,解鎖

2021-10-06 17:47:18 字數 2281 閱讀 3307

--查詢被鎖的表 

--查詢被鎖的表 

select a.sid, b.serial#,

decode(a.type,

'mr', 'media recovery',

'rt','redo thread',

'un','user name',

'tx', 'transaction',

'tm', 'dml',

'ul', 'pl/sql user lock',

'dx', 'distributed xaction',

'cf', 'control file',

'is', 'instance state',

'fs', 'file set',

'ir', 'instance recovery',

'st', 'disk space transaction',

'ts', 'temp segment',

'iv', 'library cache invalida-tion',

'ls', 'log start or switch',

'rw', 'row wait',

'sq', 'sequence number',

'te', 'extend table',

'tt', 'temp table',

'unknown') locktype,

c.object_name,

b.username,

b.osuser,

decode(a.lmode, 0, 'none',

1, 'null',

2, 'row-s',

3, 'row-x',

4, 'share',

5, 's/row-x',

6, 'exclusive', 'unknown') lockmode,

b.machine,d.spid

from v$lock a,v$session b,all_objects c,v$process d

where a.sid=b.sid and a.type in ('tm','tx')

and c.object_id=a.id1

and b.paddr=d.addr ;

--行級鎖

--行級鎖

select /*+ rule */

s.username,

decode(l.type, 'tm', 'table lock', 'tx', 'row lock', null) lock_level,

o.owner,

o.object_name,

o.object_type,

s.sid,

s.serial#,

s.terminal,

s.machine,

s.program,

s.osuser

from v$session s, v$lock l, dba_objects o

where l.sid = s.sid

and l.id1 = o.object_id(+)

and s.username is not null ;

--用於解鎖 

alter system kill session 'sid,serial#' ;

alter system kill session '4450,26459' ;

--分析表

analyze table ***xx  compute statistics;
----查某session 正在執行的sql語句,從而可以快速定位到哪些操作或者**導致事務一直進行沒有結束等.

select /*+ ordered */ 

sql_text

from v$sqltext a

where (a.hash_value, a.address) in

(select decode(sql_hash_value, 0, prev_hash_value, sql_hash_value),

decode(sql_hash_value, 0, prev_sql_addr, sql_address)

from v$session b

where b.sid = '7') /* 此處67 為sid*/

order by piece asc;

oracle查詢鎖表解鎖語句

1.如下語句 查詢鎖定的表 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 l...

oracle查詢鎖表解鎖語句

oracle查詢鎖表解鎖語句 首先要用dba許可權的使用者登入,建議用system,然後直接看sql吧 1.如下語句 查詢鎖定的表 select l.session id sid,s.serial l.locked mode,l.oracle username,l.os user name,s.ma...

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...