12
返回列表 发新帖
楼主: cib_ct

[讨论] 关于TX锁问题求助

[复制链接]
论坛徽章:
0
11#
 楼主| 发表于 2016-9-30 10:41 | 只看该作者
Yong Huang 发表于 2016-9-30 00:15
I can only reproduce this problem with a distributed transaction. In the source database, v$lock for ...

感谢答复。
这几天找了些资料,看到maclean的一篇文章,如下几个场景均能产生仅有TX锁的情况。最奇怪的是select 远程对象也会在本地产生TX锁。不明白这个TX锁究竟锁的是什么资源。。。
1、事务中包括远程DML操作;
2、远程select也会在本地产生TX锁,且语句执行完毕后v$Lock中仍然显示TX锁,运行commit或rollback才能释放。
3、事务中使用savepoint;
4、使用dbms_transaction包的相关函数
5、事务中所涉及到的表启用了”disable table lock”或DML_LOCKS设置为0

使用道具 举报

回复
论坛徽章:
122
现任管理团队成员
日期:2011-05-07 01:45:08
12#
发表于 2016-9-30 13:18 | 只看该作者

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
13#
发表于 2016-9-30 22:29 | 只看该作者
本帖最后由 Yong Huang 于 2016-9-30 14:55 编辑

Among the 5 cases you listed above, number 5 doesn't apply to you. Correct? 1 and 2 are both called distributed transaction (a remote query creates a transaction). But since you said "未使用分布式事务", 1 and 2 may not apply to you either. Did you have savepoint or call dbms_transaction?

I can add one more case where this problem is reproduced:

SQL>  with x as (select /*+ materialize */ inst_id, sid, type, count(*) from gv$lock group by inst_id, sid, type) select * from x where type in ('TM','TX','DX') order by 1,2,3;

   INST_ID        SID TY   COUNT(*)
---------- ---------- -- ----------
         1        406 TM          1
         1        406 TX          1
         1        419 TM          3
         1        419 TX          1
         1        800 TX          1

SQL>  with x as (select /*+ materialize */ sid, type, count(*) from v$lock group by sid, type) select * from x where type in ('TM','TX','DX') order by 1,2;

       SID TY   COUNT(*)
---------- -- ----------
       406 TM          1
       406 TX          1
       419 TM          3
       419 TX          1
       800 TX          1

Sid 800 is my current session. During the execution of the SQL, it seems to hold a TX lock but not TM (nor DX) lock. The database is 11.2.0.3 single node. The materialize hint speeds up the query against gv$lock but not v$lock. If I remove this hint, the single TX lock (i.e. not accompanied with TM) disappears. I'm guessing that a TM lock on the global temporary table created on the fly may be briefly held during the execution and is not captured while the TX lock is, probably because it's held longer. We may be able to verify it with events such as 10704 (Print out information about what enqueues are being obtained). We know that a query against v$ views is not guaranteed read consistency.

But I doubt that's what you have in your database.

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
14#
发表于 2016-10-4 22:18 | 只看该作者
Yet one more case is found. I analyze table compute statistics. While that's running, from another session, I find that the first session running analyze takes a TX lock in mode 6 (plus an AE lock which always exists), with no TM lock. It ends with the completion of analyze. This is mentioned in
ORA-2049 IN ANY DISTRIBUTED ENVIRONMENT (Doc ID 1029942.6)
for version 10.2. But I reproduced it in 11.2.0.3.

This doesn't happen with dbms_stats.gather_table_stats, which takes TX and also TM at the beginning, and no lock afterward.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表