Oracle下获取行锁引起阻塞的行对应的数据
Oracle环境下出现阻塞,从阻塞报表中,如何通过给到的信息获取表中对应的数据是哪条。
从上面的信息,我们明确知道是TX锁,数据库用户,和表名,但rowid跟已知的却不太相同。通过Oracle的官方文档了解到,rowid实际有两种类型restricted和extended,现在报表看到的就是restricted。
那么这种情况下,如何得到常见的18位长度的rowid呢,我们可以通过dbms_rowid.rowid_to_extended来获取
select dbms_rowid.rowid_to_extended('0009AA3D.0032.0005','V7620210723ORA','T_STK_INVUPLOCKIDTABLE',1) from dual;
然后通过下面select rowid,t.* from V7620210723ORA.T_STK_INVUPLOCKIDTABLE t where rowid='AACrK9AAFAACao9AAy',就可以得到具体的数据行了
附:
获取阻塞相关的信息,以获取行记录的脚本实现
--获取行锁对应的资源信息
select nvl(s.username, 'None') oracle_user,
s.logon_time,
p.username unix_user,
s.sid,
s.serial#,
p.spid unix_pid,
s.status,
s.process,
s.osuser,
s.program,
s.module,
s.machine,
s.event,
s.ROW_WAIT_OBJ#,
s.ROW_WAIT_FILE#,
s.ROW_WAIT_BLOCK#,
s.ROW_WAIT_ROW#,
l.SQL_TEXT,
s.sql_id,
s.prev_sql_id,
'ps -ef|grep ' || p.spid ||
'|grep LOCAL=NO|awk ''{print $2}''|xargs kill -9' kill_sh
from v$process p
join v$session s on s.paddr = p.addr
left join v$sql l on s.SQL_ADDRESS = l.ADDRESS and s.SQL_HASH_VALUE = l.HASH_VALUE and s.sql_child_number = l.child_number
where
s.event ='enq: TX - row lock contention'
--通过row_wait_obj#获取对象名
select * from dba_objects where object_id=434538
--dbms_rowid.rowid_create 函数说明
--获取rowid,通过对象ID,文件ID,数据块和行号
--参数说明:rowid_type:0:restricted rowid 忽略ROW_WAIT_OBJ#参数,结果如 0009AA3D.000A.0005
-- rowid_type:1:extended rowid 结果如 AACrK9AAFAACao8AA4
-- ROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#
--get rowid_type
select dbms_rowid.rowid_type(rowid) rowid_type# from V7620210723ORA.T_STK_INVUPLOCKIDTABLE where rownum<=1
---------------------------
ROWID_TYPE#
1
----通过dbms_rowid.rowid_create 获取rowid
select dbms_rowid.rowid_create(1,434538,5,633404,56) as myrowid from dual;
---------------------------
MYROWID
AABqFqAAFAACao8AA4
----通过rowid 获取行记录
select rowid,t.* from V7620210723ORA.T_STK_INVUPLOCKIDTABLE t where rowid='AACrK9AAFAACao8AA4'
---------------------------
ROWID FINVENTORYID FVALUE FCREATETIME
AACrK9AAFAACao8AA4 1332 1 2021/7/30 13:30:59
--通过rowid获取块号
select dbms_rowid.rowid_block_number('AACrK9AAFAACao8AA4') myrownum from dual;
---------------------------
MYROWNUM
633404
--根据rowid获取相关的信息
select rowid,dbms_rowid.rowid_type(rowid) rowid_type#,dbms_rowid.rowid_block_number(rowid) ROW_WAIT_BLOCK#,
dbms_rowid.rowid_to_absolute_fno(rowid,'V7620210723ORA','T_STK_INVUPLOCKIDTABLE') ROW_WAIT_FILE#,
dbms_rowid.rowid_row_number(rowid) ROW_WAIT_ROW#
from V7620210723ORA.T_STK_INVUPLOCKIDTABLE
where rowid='AACrK9AAFAACao8AA4'
---------------------------
ROWID ROWID_TYPE# ROW_WAIT_BLOCK# ROW_WAIT_FILE# ROW_WAIT_ROW#
AACrK9AAFAACao8AA4 1 633404 5 56
--如果从信息中得到的rowid=0009AA3C.0038.0005说明属于restricted,这个时候如果表里面rowid_type=0,需要通过下面的方式进行转换
select dbms_rowid.rowid_to_extended('0009AA3C.0038.0005','V7620210723ORA','T_STK_INVUPLOCKIDTABLE',1) from dual;
AACrK9AAFAACao8AA4
Oracle下获取行锁引起阻塞的行对应的数据
本文2024-09-23 01:17:24发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-144996.html