欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

锁(上)

程序员文章站 2024-02-12 15:16:58
...

-------------------查看当前有哪些用户正在使用数据 SELECT osuser, a.username,cpu_time/executions/1000000||'s', sql_fulltext,machine from v$session a, v$sqlarea b where a.sql_address =b.address order by cpu_time/executions desc; ------------

-------------------查看当前有哪些用户正在使用数据
SELECT osuser, a.username,cpu_time/executions/1000000||'s', sql_fulltext,machine
from v$session a, v$sqlarea b
where a.sql_address =b.address order by cpu_time/executions desc;


--------------------查询是什么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#;

--------------------查看被锁对象和解锁方法
(1)被锁对象
select a.SID, a.SERIAL#, c.object_name, b.oracle_username,b.os_user_name
from
v$session a,
v$locked_object b,
v$process p,
all_objects c
where
a.process=b.process and
a.paddr=p.addr and
b.object_id= c.object_id;