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

ORA-02049 ‘timeout: distributed transaction waiting for lock’ 解决

张维照 2019-05-31
3124

问题描述

ORA-02049 ‘timeout: distributed transaction waiting for lock’

ORA-02049是一个分布式事务等待超时的异常,当一个session 持有一个行级锁,另一个分布式事务比如通过dblink也想修改相同行的数据,就会产生 tx队列等待,当等待时间超过了系统参数distributed_lock_timeout的值时,就产生了这个错误,任何通过通过DBLINK的操作都是分布式事物。


专家解答

下面还原一下这个错误

SQL> create table testdl(id int);
Table created.

SQL> insert into testdl values(1);
1 row created.

SQL> commit;
Commit complete.

SQL> insert into testdl values(2);
1 row created.

SQL> commit;
Commit complete.




【session1】
sys@NCME>select * from testdl@dl_1913;
        ID
----------
         1
         2

sys@NCME>update testdl@dl_1913 set id=10 where id=1;
1 row updated.

【session2】
sys@NCME>update  testdl@dl_1913 set id=20 where id=2;
1 row updated.

sys@NCME>commit;
Commit complete.

sys@NCME>update  testdl@dl_1913 set id=100 where id=1;
update  testdl@dl_1913 set id=100 where id=1
*
ERROR at line 1:
ORA-02049: timeout: distributed transaction waiting for lock
ORA-02063: preceding line from DL_1913

----------------
SQL> alter  table testdl modify id primary key;
Table altered.
【session1】
sys@NCME>insert into testdl@dl_1913 values (3);
1 row created.
【session2】
sys@NCME>insert into testdl@dl_1913 values (3);
insert into testdl@dl_1913 values (3)
*
ERROR at line 1:
ORA-02049: timeout: distributed transaction waiting for lock
ORA-02063: preceding line from DL_1913

sys@NCME>show parameter distributed_lock
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
distributed_lock_timeout             integer     60

解决问题的思路
首先还是应用程序的代码设计,减少多个session同时修改相同数据,减小事务,或在代码中加try do something cache exception ,when exception is ORA-02049 retry.
其次就是增加distributed_lock_timeout参数的值,增加事务等待时间

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论