热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

数据库出现enq:TX-rowlockcontention的问题

数据库出现enq:TX-rowlockcontention的问题今天上午过来,做awr报告数据库出现了很多enq:TX-rowlockcontention的等待事件,以前从来没有过的,感觉很奇怪。查询gv$session中的等待事件[sql]scrac1...SyntaxHigh

数据库出现enq:TX-row lock contention的问题
 
今天上午过来,做awr报告数据库出现了很多enq: TX - row lock contention的等待事件,以前从来没有过的,感觉很奇怪。查询gv$session中的等待事件
[sql] 
scrac1/sys@JSCN> select event,count(*) from gv$session group by event;  
    www.2cto.com  
EVENT                                                              COUNT(*)  
---------------------------------------------------------------- ----------  
SQL*Net message from client                                             275  
Streams AQ: waiting for messages in the queue                             2  
ASM background timer                                                      2  
wait for unread message on broadcast channel                              1  
gcs remote message                                                       12  
ges remote message                                                        2  
jobq slave wait                                                           3  
rdbms ipc message                                                        34  
smon timer                                                                2  
pmon timer                                                                2  
Streams AQ: qmn slave idle wait                                           3  
class slave wait                                                          2  
PX Deq: reap credit                                                       2  
PX Deq: Execution Msg                                                     1  
Streams AQ: waiting for time management or cleanup tasks                  2  
Streams AQ: qmn coordinator idle wait                                     2  
DIAG idle wait                                                            2  
  
17 rows selected.  
 
在结果没有出现该等待事件,我们去ash中在看看
[sql] 
scrac1/sys@JSCN> select SAMPLE_TIME,SESSION_ID,USER_ID,SQL_ID,EVENT,CURRENT_OBJ#,CURRENT_FILE#,CURRENT_BLOCK#  from GV_$ACTIVE_SESSION_HISTORY  
where event like &#39;enq: TX%&#39; and  module=&#39;JDBC Thin Client&#39; and rownum<=10;    2  
  
SAMPLE_TIME                    SESSION_ID    USER_ID SQL_ID        EVENT                                                            CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#  
------------------------------ ---------- ---------- ------------- ---------------------------------------------------------------- ------------ ------------- --------------    www.2cto.com  
02-AUG-12 03.46.26.854 PM            3120         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3139         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3158         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3186         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3194         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3197         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3198         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3201         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510    www.2cto.com  
02-AUG-12 03.46.26.854 PM            3212         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
02-AUG-12 03.46.26.854 PM            3213         59 a209wq32zy3jw enq: TX - row lock contention                                           58359          1024            510  
 
结果发现很多的enq: TX - row lock contention等待事件,都是昨天的,这个是怎么回事,这个需要我们详细查看GV_$ACTIVE_SESSION_HISTORY表中的字段
首先,我们最容易想到的是sql_ID字段,查询
select * from V$SQL where sql_id=&#39;a209wq32zy3jw&#39;;
你妹啊,竟然是没有,不会啊,才昨天的sql,应该不会被重share pool中删掉啊,想了想,由于我们这个是rac会不会是连得另外一个节点啊
[sql] 
select * from GV_$SQL where sql_id=&#39;a209wq32zy3jw&#39;;  
scrac1/sys@JSCN> select INST_ID,SQL_TEXT from GV_$SQL where sql_id=&#39;a209wq32zy3jw&#39;;  
  
   INST_ID    www.2cto.com  
----------  
SQL_TEXT  
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
         1  
update QUARTZ.TASK_LOG      SET TASK_ID = :1,                       STATUS = :2,                       RESULT_DESC = :3,                       START_TIME = :4,                       END_TIME = :5  
 where LOG_ID = :6  
  
         1  
update QUARTZ.TASK_LOG      SET TASK_ID = :1,                       STATUS = :2,                       RESULT_DESC = :3,                       START_TIME = :4,                       END_TIME = :5  
 where LOG_ID = :6  
 
这个表和sql都很奇怪,之前我们并没有看到过,GV_$ACTIVE_SESSION_HISTORY中还有一个USER_ID=59
[sql] 
scrac1/sys@JSCN> select USERNAME,USER_ID,CREATED  from dba_users where  USER_ID=&#39;59&#39; ;
    www.2cto.com  
USERNAME                          USER_ID CREATED  
------------------------------ ---------- ------------  
QUARTZ                                 59 25-JUN-12  
查看到底是那个表出现了锁等待
[sql] 
scrac1/sys@JSCN> select * from dba_objects where object_id=&#39;58359&#39;;  
  
OWNER                          OBJECT_NAME                    SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED      LAST_DDL_TIM TIMESTAMP           STATUS  T G S  
------------------------------ ------------------------------ ------------------------------ ---------- -------------- ------------------- ------------ ------------ ------------------- ------- - - -  
QUARTZ                         TASK_LOG                                                           58359          58359 TABLE               02-AUG-12    02-AUG-12    2012-08-02:14:33:28 VALID   N N N  
 
想起来了,昨天他们一直再用这个用在做定时任务,在不停的测试。所以产生的。到此原因已经查明。
如果是在session中出现此类问题,解决方法有:
解决方法:
 
1:通过v$session找到BLOCK=1的用户,告知用户提交事务
2:通过sid找到pid,kill掉该进程
3:更改sql语句,SELECT * FROM QRTZ_LOCKS WHERE LOCK_NAME = :1 FOR UPDATE no wait
 
一般如果是现网中出现了大量类似的问题,排除人为原因,那么就要检查应用了
  www.2cto.com  
再看看官网上关于TX - row lock contention类容
http://docs.oracle.com/cd/B19306_01/server.102/b14211/instance_tune.htm#sthref761
10.3.7.2.4 TX enqueue
 
These are acquired exclusive when a transaction initiates its first change and held until the transaction does a COMMIT or ROLLBACK.
    Waits for TX in mode 6: occurs when a session is waiting for a row level lock that is already held by another session. This occurs when one user is updating or deleting a row, which another session wishes to update or delete. This type of TX enqueue wait corresponds to the wait event enq: TX - row lock contention.
    The solution is to have the first session already holding the lock perform a COMMIT or ROLLBACK.
    Waits for TX in mode 4 can occur if the session is waiting for an ITL (interested transaction list) slot in a block. This happens when the session wants to lock a row in the block but one or more other sessions have rows locked in the same block, and there is no free ITL slot in the block. Usually, Oracle dynamically adds another ITL slot. This may not be possible if there is insufficient free space in the block to add an ITL. If so, the session waits for a slot with a TX enqueue in mode 4. This type of TX enqueue wait corresponds to the wait event enq: TX - allocate ITL entry.
    The solution is to increase the number of ITLs available, either by changing the INITRANS or MAXTRANS for the table (either by using an ALTER statement, or by re-creating the table with the higher values).
    Waits for TX in mode 4 can also occur if a session is waiting due to potential duplicates in UNIQUE index. If two sessions try to insert the same key value the second session has to wait to see if an ORA-0001 should be raised or not. This type of TX enqueue wait corresponds to the wait event enq: TX - row lock contention.
    The solution is to have the first session already holding the lock perform a COMMIT or ROLLBACK.  www.2cto.com  
    Waits for TX in mode 4 is also possible if the session is waiting due to shared bitmap index fragment. Bitmap indexes index key values and a range of ROWIDs. Each &#39;entry&#39; in a bitmap index can cover many rows in the actual table. If two sessions want to update rows covered by the same bitmap index fragment, then the second session waits for the first transaction to either COMMIT or ROLLBACK by waiting for the TX lock in mode 4. This type of TX enqueue wait corresponds to the wait event enq: TX - row lock contention.
    Waits for TX in Mode 4 can also occur waiting for a PREPARED transaction.
    Waits for TX in mode 4 also occur when a transaction inserting a row in an index has to wait for the end of an index block split being done by another transaction. This type of TX enqueue wait corresponds to the wait event enq: TX - index contention.
 
10.3.7 enqueue (enq:) waits
 
Enqueues are locks that coordinate access to database resources. This event indicates that the session is waiting for a lock that is held by another session.
 
The name of the enqueue is included as part of the wait event name, in the form enq: enqueue_type - related_details. In some cases, the same enqueue type can be held for different purposes, such as the following related TX types:
 
    enq: TX - allocate ITL entry
    enq: TX - contention
    enq: TX - index contention
    enq: TX - row lock contention
  www.2cto.com  
The V$EVENT_NAME view provides a complete list of all the enq: wait events.
 
You can check the following V$SESSION_WAIT parameter columns for additional information:
 
    P1 - Lock TYPE (or name) and MODE
    P2 - Resource identifier ID1 for the lock
    P3 - Resource identifier ID2 for the lock
 
 
作者 RuleV5

推荐阅读
  • 一、Hadoop来历Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 本文介绍了adg架构设置在企业数据治理中的应用。随着信息技术的发展,企业IT系统的快速发展使得数据成为企业业务增长的新动力,但同时也带来了数据冗余、数据难发现、效率低下、资源消耗等问题。本文讨论了企业面临的几类尖锐问题,并提出了解决方案,包括确保库表结构与系统测试版本一致、避免数据冗余、快速定位问题等。此外,本文还探讨了adg架构在大版本升级、上云服务和微服务治理方面的应用。通过本文的介绍,读者可以了解到adg架构设置的重要性及其在企业数据治理中的应用。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了使用postman进行接口测试的方法,以测试用户管理模块为例。首先需要下载并安装postman,然后创建基本的请求并填写用户名密码进行登录测试。接下来可以进行用户查询和新增的测试。在新增时,可以进行异常测试,包括用户名超长和输入特殊字符的情况。通过测试发现后台没有对参数长度和特殊字符进行检查和过滤。 ... [详细]
  • 本文详细介绍了MysqlDump和mysqldump进行全库备份的相关知识,包括备份命令的使用方法、my.cnf配置文件的设置、binlog日志的位置指定、增量恢复的方式以及适用于innodb引擎和myisam引擎的备份方法。对于需要进行数据库备份的用户来说,本文提供了一些有价值的参考内容。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
  • MyBatis错题分析解析及注意事项
    本文对MyBatis的错题进行了分析和解析,同时介绍了使用MyBatis时需要注意的一些事项,如resultMap的使用、SqlSession和SqlSessionFactory的获取方式、动态SQL中的else元素和when元素的使用、resource属性和url属性的配置方式、typeAliases的使用方法等。同时还指出了在属性名与查询字段名不一致时需要使用resultMap进行结果映射,而不能使用resultType。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
author-avatar
紫木之阁_229
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有