时间:2021-07-01 10:21:17 帮助过:78人阅读
执行下面SQL,先查看哪些表被锁住了:
select b.owner,b.object_name,a.session_id,a.locked_mode
from v$locked_object a,dba_objects b
where b.object_id = a.object_id;
查处引起死锁的会话
select b.username,b.sid,b.serial#,logon_time
from vlocked_object a,vsession b
where a.session_id = b.sid order by b.logon_time;
-- 这里会列出SID
查出SID和SERIAL#:
查V$SESSION视图:
SELECT SID,SERIAL#,PADDR FROM V$SESSION WHERE SID='刚才查到的SID';
-- 这一步将得到PADDR
查V$PROCESS视图:
SELECT SPID FROM V$PROCESS WHERE ADDR='刚才查到的PADDR';
-- 这一步得到SPID
杀死进程
在数据库中,杀掉ORACLE进程:
ALTER SYSTEM KILL SESSION '查出的SID,查出的SERIAL#';
如果在ORACLE中不能杀死进程,我们只能到操作系统中,使用操作系统命令杀死进程
KILL -9 “刚才查出的SPID”
在WINDOWS平台,可以是偶那个orakill。
SELECT vl.session_id || ',' || b.serial#, ao.object_name, b.*
FROM vlocked_object vl, all_objects ao, vsession b
WHERE vl.object_id = ao.object_id
AND vl.session_id = b.sid
AND b.status = 'ACTIVE' --session状态根据需要添加
AND ao.object_name LIKE 'object_name';
ALTER SYSTEM KILL SESSION '查出的SID, 查出的SERIAL#';
查询死锁的对象:
select username,lockwait,status,machine,program from v$session where sid in
(select session_id from v$locked_object);
查询死锁语句:
select sql_text from v$sql where hash_value in
(select sql_hash_value from v$session where sid in
(select session_id from v$locked_object));
SELECT s.lockwait,s.status,s.username,l.OBJECT_ID,l.SESSION_ID,s.SERIAL#,l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESS
FROM VLOCKED_OBJECT l,VSESSION S
WHERE l.SESSION_ID=S.SID and s.STATUS='ACT\IVE';
alter system kill session '25,16823' IMMEDIATE;
alter system kill session ‘sid,serial#’ IMMEDIATE;
MySQL 数据库死锁
标签:lock logo machine roc sel RoCE pid sql 数据库 模糊匹配