Oracle定位对阻塞的对象或锁信息
2022/1/13 19:03:56
本文主要是介绍Oracle定位对阻塞的对象或锁信息,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
set serveroutput on size unlimited set feedback off DECLARE v_num_sessions INTEGER := 0; CURSOR cv IS SELECT dba_objects.object_name, locks_t.row#, locks_t.blocked_secs, locks_t.blocker_text, locks_t.blocked_text, locks_t.blocked_sql_text FROM (SELECT /*+ NO_MERGE */ blocking_lock_session.username||'@'||blocking_lock_session.machine||'(SID='||blocking_lock_session.sid||') ['|| blocking_lock_session.program||'/PID='||blocking_lock_session.process||']' as blocker_text, blocked_lock_session.username||'@'||blocked_lock_session.machine|| '(SID='||blocked_lock_session.sid||') ['|| blocked_lock_session.program||'/PID='||blocked_lock_session.process||']' as blocked_text, blocked_lock_session.row_wait_obj#, blocked_lock_session.row_wait_file#, blocked_lock_session.row_wait_block#, blocked_lock_session.row_wait_row#, DBMS_ROWID.ROWID_CREATE (1, blocked_lock_session.row_wait_obj#, blocked_lock_session.row_wait_file#, blocked_lock_session.row_wait_block#, blocked_lock_session.row_wait_row#) row#, blocked_lock_session.seconds_in_wait blocked_secs, blocked_sql.sql_text blocked_sql_text FROM v$lock blocking_lock, v$session blocking_lock_session, v$lock blocked_lock, v$session blocked_lock_session, v$sql blocked_sql WHERE blocking_lock.block = 1 AND blocking_lock.id1 = blocked_lock.id1 AND blocking_lock.id2 = blocked_lock.id2 AND blocked_lock.request > 0 AND blocking_lock.sid = blocking_lock_session.sid AND blocked_lock.sid = blocked_lock_session.sid AND blocked_lock_session.sql_id = blocked_sql.sql_id AND blocked_lock_session.sql_child_number = blocked_sql.child_number ) locks_t, dba_objects WHERE locks_t.row_wait_obj# = dba_objects.object_id AND locks_t.blocked_secs > &1 ORDER BY locks_t.blocked_secs; BEGIN FOR cv_rec IN cv LOOP dbms_output.put_line( '========= $Revision: 1.4 $ ($Date: 2013/09/16 13:15:22 $) ==========='); v_num_sessions := v_num_sessions + 1; dbms_output.put_line('Locked object : '|| cv_rec.object_name); dbms_output.put_line('Locked row# : '|| cv_rec.row#); dbms_output.put_line('Blocked for : '|| cv_rec.blocked_secs||' seconds'); dbms_output.put_line('Blocker info. : '|| cv_rec.blocker_text); dbms_output.put_line('Blocked info. : '|| cv_rec.blocked_text); dbms_output.put_line('Blocked SQL : '|| cv_rec.blocked_sql_text); END LOOP; dbms_output.new_line; dbms_output.put_line('Found '||TO_CHAR(v_num_sessions)|| ' blocked session(s).'); END; / exit;
上面这个语句用来查当前被阻塞的对象详细信息,特别好使
根据上面的结果 知道了阻塞对象、阻塞数据的rowid,阻塞者和被阻塞者的SID
根据阻塞者的SID 找到对应对应和serial#
select b.sid,b.serial#,b.username,a.sql_text
from v$sqlarea a,v$session b where a.SQL_ID=b.PREV_SQL_ID and b.SID=14;
然后kill掉这个进程,阻塞被释放
alter system kill session '14,16293'
这篇关于Oracle定位对阻塞的对象或锁信息的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-11国产医疗级心电ECG采集处理模块
- 2025-01-10Rakuten 乐天积分系统从 Cassandra 到 TiDB 的选型与实战
- 2025-01-09CMS内容管理系统是什么?如何选择适合你的平台?
- 2025-01-08CCPM如何缩短项目周期并降低风险?
- 2025-01-08Omnivore 替代品 Readeck 安装与使用教程
- 2025-01-07Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5
- 2025-01-06PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”
- 2025-01-05Easysearch 可搜索快照功能,看这篇就够了
- 2025-01-04BOT+EPC模式在基础设施项目中的应用与优势
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南