oracle多进程阻塞,为什么一个普通的select 语句也会阻塞其他进程的update语句?

本文介绍了一种使用PL/SQL检查Oracle数据库中进程阻塞情况的方法,并详细分析了一个具体实例,涉及锁定等待、锁类型及模式等关键概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用这个语句发现有进程阻塞:

declare

mes varchar2(2000);

tmp_id1 number(22);

tmp_id2 number(22);

lk_sid number(22);

tmp_mac varchar2(64);

fl boolean;

begin

fl:=false;

for c1 in (select sid,serial#,machine,lockwait

from v$session

where lockwait is not null) loop

fl:=true;

mes:='sid:'||to_char(c1.sid)||','||c1.machine||'is be locked by sid ';

select id1,id2 into tmp_id1,tmp_id2

from v$lock where sid=c1.sid and kaddr=c1.lockwait;

for c2 in (select sid lk_sid from v$lock where sid!=c1.sid and id1=tmp_id1 and id2=tmp_id2 and block='1') loop

select machine into tmp_mac from v$session where sid=c2.lk_sid;

dbms_output.put_line(mes||to_char(c2.lk_sid)||' '||tmp_mac);

end loop;

end loop;

if not fl then

dbms_output.put_line('目前系统中没有互锁现象');

end if;

end;

/

sid:96,jupiteris be locked by sid 177 jupiter

sid:119,WORKGROUP\PZZHANG

sid:157,jupiteris be locked by sid 177 jupiter

sid:173,jupiteris be locked by sid 177 jupiter

sid:180,jupiteris be locked by sid 177 jupiter

发现有几个进程被177锁住.而177执行的sql语句是

select SQL_TEXT, c.spid, b.sid,b.USERNAME

from V$SQLAREA a, v$session b, v$process c

where b.SQL_ADDRESS = a.ADDRESS

and b.SQL_HASH_VALUE = a.HASH_VALUE

and c.ADDR = b.paddr

and b.sid = 177;

/

select this_.id                as id0_,

this_.name              as name2_0_,

this_.password          as password2_0_,

this_.mobile            as mobile2_0_,

this_.status            as status2_0_,

this_.email             as email2_0_,

this_.code              as code2_0_,

this_.birthday          as birthday2_0_,

this_.gender            as gender2_0_,

this_.region            as region2_0_,

this_.real_name         as real11_2_0_,

this_.user_agent        as user12_2_0_,

this_.home              as home2_0_,

this_.logo              as logo2_0_,

this_.latest_login_date as latest15_2_0_,

this_.creation_date     as creation16_2_0_

from imeg_user this_

where this_.mobile = :1

and this_.status <> :2

程序员说这条sql语句是通过中间件生成的,继续调查发现177进程的这条语句持有的锁的lock_type有Transaction enqueue lock和DML enqueue lock.持有的锁的lock_mode有Row Exclusive和Exclusive.这样看起来和一般的update持有的锁一样.

其他几个被锁住的进程都是在执行

update imeg_user set latest_login_date=:1 where id=:2

数据库是9201,这种情况是什么问题?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值