行锁导致的SQL阻塞问题分析处理

news/2025/1/18 8:44:16/

行锁导致的SQL阻塞问题分析处理

  • 行锁分析处理流程
  • 锁与SQL阻塞分析脚本

行锁分析处理流程

查看表上是否有锁:

select inst_id,object_id,session_id sid,oracle_username, 
decode(locked_mode,0,'None',2,'Row Share Lock',3,'Row Exclusive Table Lock', 
4,'Share Table Lock',5,'Share Row Exclusive Table Lock',6,'Exclusive Table Lock','NULL') 
from gv$locked_object where object_id = ( select 
object_id from dba_objects where object_type = 'TABLE' 
and object_name = '&obj_name' and owner = '&owner');

找到对应inst_idsid的会话SQL:

select inst_id||':'||sid||','||serial# ssid,username,sql_id,event, 
substr(program,1,25) program,machine,state,last_call_et exec_time,status 
from gv$session where inst_id='&inst_id' and sid='&session_id';

杀掉造成阻塞的对应语句:

alter system kill session '&sid,&serial';

锁与SQL阻塞分析脚本

执行check_blocking_stats.sql脚本:

alter session set nls_date_format='yyyymmdd hh24:mi:ss';
select sysdate from dual;
set lines 200 pages 1000
col blocking_instance format 99
col inst_id format 99
col sid format 99999999
col blocking_session format 999999
col event for a40
col file_name format a40
col sql_text format a60
col PROGRAM format a18
col module format a18
col machine format a18
COLUMN owner FORMAT A20
COLUMN username FORMAT A20
COLUMN object_owner FORMAT A20
COLUMN object_name FORMAT A30
COLUMN locked_mode FORMAT A15prompt "blocking sessions"
select blocking_instance, blocking_session, count(*)from gv$sessionwhere blocking_session is not nullgroup by blocking_instance, blocking_sessionorder by 1, 3;prompt
prompt
prompt "blocking detail"
select inst_id,sid,serial#,nvl(sql_id,prev_sql_id) sql_id,prev_sql_id,event,state,seconds_in_wait,p1,p2,blocking_instance,blocking_sessionfrom gv$sessionwhere blocking_session is not nullorder by blocking_instance,blocking_session,inst_id,seconds_in_wait ;prompt "Holder and Waiter:"
select decode(request,0,'***holder:','     waiter:') holder,
sid,id1,id2,lmode,request,type,ctime,block
from v$lock
where (id1,id2,type) in
(select id1,id2,type from v$lock where request>0) 
order by id1,request;prompt
prompt
prompt "Event enq: TX - row lock contention waiting object"select se.inst_id,se.sid,se.serial#,obj.owner,obj.object_name,obj.object_type,se.ROW_WAIT_BLOCK#from gv$session se, dba_objects obj 
where se.event='enq: TX - row lock contention'and se.row_wait_obj# = obj.object_id; prompt 
prompt "Lock info"
select INST_ID,SID,TYPE,ID1,ID2,LMODE,REQUEST,CTIME,BLOCK 
from GV$lock where block=1 or request<>0 ORDER BY 1,2; prompt
prompt
prompt "Locked objects:"
prompt "Locked objects:"
SELECT b.session_id AS sid,NVL(b.oracle_username, '(oracle)') AS username,a.owner AS object_owner,a.object_name,Decode(b.locked_mode, 0, 'None',1, 'Null (NULL)',2, 'Row-S (SS)',3, 'Row-X (SX)',4, 'Share (S)',5, 'S/Row-X (SSX)',6, 'Exclusive (X)',b.locked_mode) locked_mode,b.os_user_name
FROM   dba_objects a,v$locked_object b
WHERE  a.object_id = b.object_id
ORDER BY 1, 2, 3, 4;prompt
prompt
prompt "blocking sql text"
select se.inst_id,se.sid,se.sql_id,sq.sql_text
fromgv$session se,v$sql sq
where se.sql_id =  sq.sql_idand (inst_id,sid) in(select inst_id,sidfrom(select distinctblocking_instance as inst_id,blocking_session  as sidfrom gv$session where blocking_session is not null ));prompt
prompt
prompt "blocked sql text"
select se.inst_id,se.sid,nvl(se.sql_id,se.prev_sql_id) sql_id,sq.sql_textfrom gv$session se,v$sql sqwhere blocking_session is not nulland nvl(se.sql_id,prev_sql_id) = sq.sql_id;prompt 
prompt blocking session info
select se.inst_id,se.sid,nvl(se.sql_id,se.prev_sql_id) sql_id,logon_time,program,username,machine,module,last_call_et
fromgv$session se
where (inst_id,sid) in(select inst_id,sidfrom(select distinctblocking_instance as inst_id,blocking_session  as sidfrom gv$session where blocking_session is not null ));promptpromptprompt blocking session consume rollback segmentsselect se.inst_id,se.sid,se.serial#,nvl(se.sql_id,se.prev_sql_id) sql_id,tr.used_ublk,tr.used_urec
fromgv$session se,gv$transaction tr
where (se.inst_id,se.sid) in(select inst_id,sidfrom(select distinctblocking_instance as inst_id,blocking_session  as sidfrom gv$session where blocking_session is not null ))and se.taddr = tr.addr;

http://www.ppmy.cn/news/911603.html

相关文章

token的验证流程

前端 后台 1.1 登录接口(携带账号和密码(MD5)) -->到后台 需要&#xff1a; 验证(账号密码)生成Token(包含id昵称&#xff0c;不敏感的数据) 1.2 后台需要解析&#xff0c;-->然后在前端显示 解析(解析出前端需要显示的数据)把token放到某一个位置…

简单版本视频播放服务器V2

简单版本视频播放服务器V2 一直想做个家用版本的家庭影院&#xff0c;通过这个服务器可以给电脑&#xff0c;平板&#xff0c;手机等设备提供直接播放电影的作用&#xff0c;通过浏览器就是可以访问电脑里面的视频&#xff0c;实现简单的家庭版本服务了。 备注注意 &#xff1a…

让ShearPoint 2010在线广播PPT演示文稿

前几天&#xff0c;有一位老师要做在线视频培训&#xff0c;条件是要对方同步看到PPT演示文稿&#xff0c;并且&#xff0c;鉴于他的这项研究比较前沿&#xff0c;演示文稿还不能复制给大家&#xff0c;还有一个条件&#xff0c;就是在培训的时间点&#xff0c;有一位正在出差的…

微软的未来:超越Windows 7和PC

10/23/2009 10:47:40 PM 导语&#xff1a;美国《纽约时报》网络版今天撰文称&#xff0c;对于一直依靠销售桌面软件和计算机服务软件并收取授权费的微软而言&#xff0c;云计算将带来一系列巨大的挑战。 设备革命 当被问及Windows和Office等旗舰产品的最新版是否令人兴奋时&…

该想的不该想到的方法~测试方法总结

网站测试方法 一、性能测试 性能测试可以检验网站响应速度、承受负载和压力的能力。 &#xff08;1&#xff09;链接速度测试。用户链接到网站的速度根据上网方式的不同而不同&#xff0c;他们或者电话拔号&#xff0c;或者是宽带上网。 &#xff08;2&#xff09;负载测试…

微软应用iOS/安卓/WP版体验对比

2015年夏天&#xff0c;Windows独占的Cortana在安卓设备上开启公测&#xff0c;笔者不知给微软小娜的微信公众号发了多少次“小娜抱抱”&#xff0c;终于抢到一个内测邀请码&#xff0c;简直如获至宝。那个时候笔者还不知道&#xff0c;一切才刚刚开始。 后来&#xff0c;越来越…

《网站分析实战--如何以数据驱动决策,提升网站价值》学习笔记

网站分析实战--如何以数据驱动决策&#xff0c;提升网站价值 一、网站分析的目的及流程1.1 网站分析的目标1.2 如何进行网站分析1.2.1 流量分析1.2.2 内容分析1.2.3 转化分析&#xff08;漏斗分析&#xff09;1.2.4 投资回报 1.3 网站分析基本流程1.3.1 定义1.3.2 测量1.3.3 分…

天翼品牌: 内容日益饱满,互联网手机逐渐成型

一年前&#xff0c;中国电信将其新手机品牌天翼定位于“互联网手机”&#xff0c;彼时&#xff0c;由于其手机应用尚不成熟&#xff0c;业界对这一概念还持怀疑态度。但从那之后移动互联网的快速发展来看&#xff0c;中国电信互联网手机这一概念确实抓住了3G时代的核心和趋势&a…