oracle 查看及kill进程,DDL死锁,锁表查询处理。sql语句执行时长查询
-- 查询正在运行的长时间SQL语句
SELECT s.sid,
s.serial#,
s.username,
s.program,
s.type,
s.terminal,
s.machine,
s.osuser,
s.status,
s.schemaname,
t.start_time,
t.sql_text,
ROUND(t.elapsed_seconds, 2) AS elapsed_seconds
FROM v$session s
JOIN v$sql t ON s.sql_id = t.sql_id
WHERE t.elapsed_seconds > 60 -- 设置阈值,这里是60秒
AND s.type != 'BACKGROUND';
-- 查询DDL操作的死锁信息
SELECT dl.xidusn,
dl.object_id,
dl.session_id,
o.object_name,
s.username,
s.sid,
s.serial#,
s.status
FROM dba_objects o,
v$locked_object dl
LEFT JOIN v$session s ON dl.session_id = s.sid
WHERE o.object_id = dl.object_id
AND o.object_type = 'DDL';
-- 查询锁表的会话信息
SELECT l.session_id,
s.serial#,
s.username,
s.osuser,
s.machine,
s.terminal,
s.program,
s.type,
s.schemaname,
o.object_name,
o.object_type
FROM v$locked_object l
JOIN dba_objects o ON l.object_id = o.object_id
JOIN v$session s ON l.session_id = s.sid
WHERE o.object_type = 'TABLE';
-- 杀掉长时间运行的会话
ALTER SYSTEM KILL SESSION 'sid,serial#';
在实际操作中,你需要根据实际情况调整查询条件和阈值,并确保你有足够的权限执行这些操作。对于杀掉会话的操作,应谨慎执行,因为这可能会导致数据一致性问题。
评论已关闭