后台代码执行一条update语句报超时,一开始以为是数据库连接的问题,于是把这条语句拿出来单独执行发现也不行,我怀疑后台锁表了,一看还真是,以下是排查方法:
--正在执行的sql,会不断刷新
select b.SID, b.USERNAME, b.SERIAL#, spid, paddr, sql_text, b.MACHINE
from v$process a, v$session b, v$sqlarea c
where a.ADDR = b.PADDR
and b.SQL_HASH_VALUE = c.HASH_VALUE;
--查看被锁的sql
select l.SESSION_ID,
s.SERIAL#,
l.LOCKED_MODE,
l.ORACLE_USERNAME,
l.OS_USER_NAME,
s.MACHINE,
s.TERMINAL,
o.OBJECT_NAME,
s.LOGON_TIME,
r.SQL_TEXT
from v$locked_object l, all_objects o, v$session s ,v$sqlarea r
where l.OBJECT_ID = o.OBJECT_ID
and l.SESSION_ID = s.SID
and s.SQL_HASH_VALUE = r.HASH_VALUE
order by sid, s.SERIAL#;
--查看被锁的操作
select l.SESSION_ID,
s.SERIAL#
from v$locked_object l
join all_objects o
on l.OBJECT_ID = o.OBJECT_ID
join v$session s
on s.SID = l.SESSION_ID;
--解锁--SESSION_ID,SERIAL
alter system kill session '104,47499';
注:解锁时如果报 ora-01031:insufficient privileges ,说明权限不足,需要在服务器端以dba用户执行
标签:语句,session,--,OBJECT,update,卡住,SESSION,SERIAL,ID From: https://blog.csdn.net/qq_20665933/article/details/144438493