暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

再记分布式事务回滚

Oracle工作笔记 2019-08-05
1749
  1. Distributed Transactions in Prepared State Fails

之前写了一篇记录分布式事务回滚的文章,事务状态为collecting,这次再记一次分布式事务回滚,事务状态为prepared。

一、事件描述

分布式事务的状态为prepared,正常情况下,可执行

rollback force 'local_tran_id';

进行回滚,其中的 local_tran_id 会在分布式事务报错时给出。查询字典 dba_2pc_pending 可以获得该分布式事务的详细信息

select * from dba_2pc_pending where local_tran_id='&local_tran_id';

但有时候,回滚命令会hang住执行不下去,查询会话等待事件,为“free global transaction table entry”。

二、解决方案

假设分布式事务的 local_tran_id 为 6.12.399297,首先查询底层视图 x$ktuxe 中是否有该分布式事物的相关信息

SELECT ktuxeusn,
ktuxeslt,
ktuxesqn,
ktuxesta status,
ktuxecfl flags
FROM x$ktuxe
WHERE ktuxesta != 'inactive'
AND ktuxeusn = 6
AND ktuxeslt = 12
AND ktuxesqn = 399297;

注意 ktuxeusn、ktuxeslt、ktuxesqn 与分布式事务 local_tran_id 之间对应的关系。
若查询 x$ktuxe 有输出,执行以下语句

delete from sys.pending_trans$ where local_tran_id = '6.12.399297';

delete from sys.pending_sessions$ where local_tran_id = '6.12.399297';

delete from sys.pending_sub_sessions$ where local_tran_id ='6.12.399297';

commit;

alter system disable distributed recovery;

随后,重新插入相关信息

INSERT INTO pending_trans$
(local_tran_id,
global_tran_fmt,
global_oracle_id,
state,
status,
session_vector,
reco_vector,
type#,
fail_time,
reco_time)
VALUES ( '6.12.399297', /* <== Replace this with your local tran id */
306206,
'123.12345.1.2.3',
'prepared',
'p',
Hextoraw('00000001'),
Hextoraw('00000000'),
0,
sysdate,
sysdate );

INSERT INTO pending_sessions$
VALUES ( '6.12.399297',/* <==replace only this with your local tran id */
1,
Hextoraw('05004f003a1500000104'),
'c',
0,
30258592,
'',
146 );

注意要commit

commit;

最后,回滚事务

rollback force '6.12.399297';
alter system enable distributed recovery;

三、结语

涉及到底层字典或视图的操作当慎之又慎,不到万不得已不要去动oracle数据库底层的东西。



本文分享自微信公众号 - Oracle工作笔记,如有侵权,请联系 service001@enmotech.com 删除。
文章转载自Oracle工作笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论