当前位置:Gxlcms > mysql > 表解锁

表解锁

时间:2021-07-01 10:21:17 帮助过:48人阅读

1 查出被锁的表信息 SELECT /* rule*/ a.sid, b.owner, object_name, object_type FROM v$lock a, all_objects b WHERE TYPE = 'TM' and a.id1 = b.object_id; --1.查出锁定object的session的信息以及被锁定的object名 SELECT l.session_id sid, s.serial#,

1 查出被锁的表信息
SELECT /*+ rule*/
a.sid, b.owner, object_name, object_type
FROM v$lock a, all_objects b
WHERE TYPE = 'TM'
and a.id1 = b.object_id;

--1.查出锁定object的session的信息以及被锁定的object名
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, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial# ;

--2.查出锁定表的session的sid, serial#,os_user_name, machine name, terminal和执行的语句
--比上面那段多出sql_text和action
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#;

--3.查出锁定表的sid, serial#,os_user_name, machine_name, terminal,锁的type,mode
SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,
s.terminal, s.logon_time, l.type
FROM v$session s, v$lock l
WHERE s.sid = l.sid
AND s.username IS NOT NULL
ORDER BY sid;

2 查出serial
SELECT sid,serial# FROM v$session WHERE sid = 662;

3 杀掉session
alter system kill session '662,44825';

SELECT 'alter system kill session '''||sid||','||serial#||''';' FROM v$session WHERE username='DCDB';

4 查出是否有长时间执行的SQL
select a.sid, b.sql_text
from v$session a, v$sqlarea b
where a.sql_hash_value = b.hash_value
and a.sid in
(SELECT SID from GV$Session_longops where TIME_REMAINING > 0);

人气教程排行