一 查看锁的类型
select type,name,description from v$lock_type order by type
二 查看当前会话锁
select type,name,id1,id2,lmode,decode(type,'TM',(select object_name
from dba_objects where object_id=id1)) table_name
from v$Lock join v$lock_type using(type)
where sid=(select sid from v$session where audsid=userenv('sessionid'))
and type<>'AE'
手动锁定一个表
lock table dept in exclusive mode
select * from dept where deptno=20 for update nowait 此时会报ora-00054:resource busy and acquire with nowait specified.
当然你也可select * from dept where deptno=20 for update wait 2;
select * from v$lock a,v$lock_type b ,dba_objects c where a.type=b.type and a.id1=c.object_id
and a.type<>'AE'
三 查询锁等待事件
select wait_class#,wait_class,name from v$event_name where name like 'enq: TX%'
四 查询各类等待事件所占比率
select sum(total_waits) total_waits, wait_class,
round(sum(time_waited_micro) / 1000000, 2) time_waited,
round(sum(time_waited_micro) * 100 / SUM(sum(time_waited_micro) )OVER(), 2) pct
from v$system_event
where wait_class# <> 6
group by wait_class
order by 4 desc
--查看会话的阻塞关系
select rpad('+',level,'-')||sid||' '||s.module session_detail,blocker_sid,wait_event_text,
object_name,rpad(' ',level)||sql_text sql_text
from v$wait_chains c left outer join dba_objects o on (row_wait_obj#=object_id)
join v$session s using(sid) left outer join v$sql sql on (sql.sql_id=s.sql_Id
and sql.child_number=s.SQL_CHILD_NUMBER)
connect by prior sid=blocker_sid
--and prior s.serial#=s.BLOCKING_SESSION_serial#
---and prior instance=s.BLOCKING_INSTANCE
start with blocker_is_valid='FALSE'
五 查询某个段所占的比率
select OBJECT_NAME,VALUE ROW_LOCK_WAITS,ROUND(VALUE*100/SUM(VALUE) OVER() ,2 )PCT
from V$segment_statistics
WHERE STATISTIC_NAME='row lock waits' and value>0
order by value desc