6月30日,数据库发生了大量锁表。大概持续1小时,并且越锁越多。后来通过业务人员停掉程序,并kill掉会话后解决。

几天后再EM上查看CPU占用:

CPU发生了明显等待。

主要是由于enq:TX - row lock contention等待事件造成。

等待事件—enq:TX - row lock contention

enq是一种保护共享资源的锁定机制,一个排队机制,先进先出(FIFO)

发生TX锁的原因一般有几个:
1.不同的session更新或删除同一个记录。
2.唯一索引有重复索引
3.位图索引多次更新
4.同时对同一个数据块更新
5.等待索引块分裂

官网上关于TX - row lock contention的内容:

Oracle官网上关于TX - row lock contention的内容

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.

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 'entry' 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 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
通过awr报告查看:
SQL> @?/rdbms/admin/awrrpt.sql
  • 1

1.这2个小时进行AWR的收集和分析,首先,从报告头中看到DB Time达到2176分钟,(DB Time)/Elapsed=18,这个比值偏高:

2.再看TOP 10事件:
看到排在第一位的是enq: TX - row lock contention事件,也就是说系统中在这一个小时里产生了较为严重的行级锁等待事件。

3. 同时,从段的统计信息章节中,也看到下面的信息:

看到row lock waits发生在表上。

通过命令查看

那么,究竟是什么操作导致了这个enq: TX - row lock contention等待事件呢? 查看系统中,当前有哪些会话产生了enq: TX - row lock contention等待事件?

现在已经解锁了,所以无法查询

SQL> select event,sid,p1,p2,p3 from v$session_wait where event='enq: TX - row lock contention';

未选定行

如果正在锁着,可以参考enq: TX - row lock contention等待事件

查看系统中的当前会话,是在哪个对象上产生了enq: TX - row lock contention等待事件?

  • 查看引起enq: TX - row lock contention等待事件的object_id对象号
SQL> select ROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#  from v$session  where event='enq: TX - row lock contention';

那么这个数据库对象为ROW_WAIT_OBJ#的对象究竟是什么呢?

  • 查看ROW_WAIT_OBJ#对应的对象名称
SQL> select  object_name,object_idfrom  dba_objects  where object_id=【ROW_WAIT_OBJ#】;
  • 通过对象名称查看对象的owner及类型
SQL> select OWNER,OBJECT_NAME,OBJECT_ID,DATA_OBJECT_ID, OBJECT_TYPEfrom dba_objectswhereobject_name='【OBJECT_NAME】';

定位到的结果应该同AWR报告中段统计信息吻合。

通过查询gv$session找到当前的等待事件

SQL> select event,count(*) from gv$session group by event;

EVENT                                   COUNT(*)

SQLNet message from client 3205

wait for unread message on broadcast channel 5

Streams AQ: waiting for messages in the queue 4

ASM background timer 2

ges remote message 2

gcs remote message 8

LNS ASYNC end of log 2

pmon timer 2

rdbms ipc message 60

jobq slave wait 4

smon timer 2

gc cr request 1

Streams AQ: qmn slave idle wait 2

class slave wait 12

SQL
Net message to client 1

Space Manager: slave idle wait 9

GCR sleep 2

VKTM Logical Idle Wait 2

Streams AQ: waiting for time management or cleanup tasks 2

Streams AQ: qmn coordinator idle wait 2

PX Deq: Execution Msg 1

PX Deq Credit: send blkd 1

DIAG idle wait 4

PING 2

PX Deq: Execute Reply 1 已选择25行。

因为当前已经没有这个等待事件了,可以查看GV_$ACTIVE_SESSION_HISTORY

SQL> select SAMPLE_TIME,SESSION_ID,USER_ID,SQL_ID,EVENT,CURRENT_OBJ#,CURRENT_FILE#,CURRENT_BLOCK#  from GV_$ACTIVE_SESSION_HISTORY
where event like 'enq: TX%' and SAMPLE_TIME like '30-6月%' and module='JDBC Thin Client' and rownum<=500;
  • 1
  • 2


结果发现很多的enq: TX - row lock contention等待事件。

定位具体SQL:

  • 通过sql_ID字段,查询
SQL> select INST_ID,SQL_TEXT from GV_$SQL where sql_id='f9kdn3mdv252a';

SQL> select * from dba_hist_sqltext where sql_id='f9kdn3mdv252a';
  • 查看是哪个用户的SQL
    GV_$ACTIVE_SESSION_HISTORY中还有一个USER_ID=54
SQL> select USERNAME,USER_ID,CREATED from dba_users where USER_ID='54' ;
  • 查看到底是那个表出现了锁等待
SQL> select * from dba_objects where object_id='183598';
OWNER OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED LAST_DDL_TIME TIMESTAMP STATUS T G S NAMESPACE EDITION_NAME
------------------------------ ----------------- --------- -------------- ------------ ----------------------- ---------------------- ------------------- ------- - - - ---------- -----------
XX NODETITLEREPORT_TASK_PRJ 183598 183598 TABLE 25-4月 -2014 12:23:53 30-6月 -2020 15:42:53 2014-04-25:12:23:53 VALID N N N 1

解决办法

如果正在等待
1.通过v$session找到BLOCK=1的用户,告知用户提交事务

SQL> select SID,TYPE,ID1,ID2,LMODE,REQUEST,CTIME,BLOCK from V$lock where block=1 or request<>0;

2.通过sid找到pid,kill掉该进程

3.更改sql语句,

SQL> SELECT * FROM QRTZ_LOCKS WHERE LOCK_NAME = :1 FOR UPDATE no wait

加nowait的意思是得到或者得不到,不会等待

一般如果是现网中出现了大量类似的问题,排除人为原因,那么就要检查应用了。

参考:
初次遇见等待事件:enq;tx-row lock contention

enq: TX - row lock contention 等待事件

</article>

[转帖]等待事件 enq:TX - row lock contention分析与解决的更多相关文章

  1. ORACLE AWR结合ASH诊断分析enq: TX - row lock contention

    公司用户反馈一系统在14:00~15:00(2016-08-16)这个时间段反应比较慢,于是生成了这个时间段的AWR报告, 如上所示,通过Elapsed Time和DB Time对比分析,可以看出在这 ...

  2. ORACLE等待事件:enq: TX - row lock contention

    enq: TX - row lock contention等待事件,这个是数据库里面一个比较常见的等待事件.enq是enqueue的缩写,它是一种保护共享资源的锁定机制,一个排队机制,先进先出(FIF ...

  3. enq: TX - row lock contention“等待事件的处理

      enq: TX - row lock contention“等待事件的处理   session1: SQL> conn scott/triger Connected. SQL> CRE ...

  4. 大表建立索引引发enq: TX - row lock contention等待

    今天要给一张日志表(6000w数据)建立索引,导致生产系统行锁部分功能卡住 create index idx_tb_cid on tb_login_log(user_id); 开始执行后大概花费了20 ...

  5. 解决一则enq: TX – row lock contention的性能故障

    上周二早上,收到项目组的一封邮件: 早上联代以下时间点用户有反馈EDI导入"假死",我们跟踪了EDI导入服务,服务是正常在跑,可能是处理的慢所以用户感觉是"假死" ...

  6. enq: TX - row lock contention 参数P1,P2,P3说明

    enq: TX - row lock contention三个参数,例如,下面的等待事件 * P1 = name|mode          <<<<<<< ...

  7. AWR之-enq TX - row lock contention的性能故障-转

    1 对这一个小时进行AWR的收集和分析,首先,从报告头中看到DB Time达到近500分钟,(DB Time)/Elapsed=8,这个比值偏高:   Snap Id Snap Time Sessio ...

  8. [Oracle] enq: TX - row lock contention 优化案例

    依据开发反馈.近期每天早上7:30应用会报警.应用的日志显示数据库连接池满了.新的连接被拒绝. 首先.我做了ASH报告(报告区间:7:25 ~ 7:35),从ASH的等待事件发现enq: TX - r ...

  9. enq: TX - row lock contention故障处理一则

    一个非常easy的问题,之所以让我对这个问题进行总结.一是由于没我想象的简单,在处理的过程中遇到了一些磕磕碰碰,甚至绕了一些弯路.二是引发了我对故障处理时的一些思考. 6月19日,下午5点左右.数据库 ...

  10. 记一则update 发生enq: TX - row lock contention 的处理方法

    根据事后在虚拟机中复现客户现场发生的情况,做一次记录(简化部分过程,原理不变) 客户端1执行update语句 SQL> select * from test; ID NAME --------- ...

随机推荐

  1. Linux SNMP监控配置

    1, 安装SNMP服务 [root@zlm log]# yum -y install net-snmp net-snmp-utils 2, 编辑SNMP配置文件[root@zlm log]# vim ...

  2. Programming Abstractions in C阅读笔记:p202-p234

    <Programming Abstractions in C>学习第65天,p202-p234总结. 一.技术总结 完成第五章学习,第五章介绍递归在实际问题中的进一步应用,例如汉诺塔问题, ...

  3. Programming abstractions in C阅读笔记:p184-p195

    <Programming Abstractions In C>学习第61天,p184-p195总结. 一.技术总结 1.mutual recursion 2.natural number ...

  4. 文心一言 VS 讯飞星火 VS chatgpt (54)-- 算法导论6.2 6题

    文心一言 VS 讯飞星火 VS chatgpt (53)-- 算法导论6.2 5题 六.证明:对一个大小为 n的堆,MAX-HEAPIFY 的最坏情况运行时间为 Ω(Ign).(提示对于n个结点的堆, ...

  5. just_audio音频播放器

    代码 import 'package:flutter/material.dart'; import 'package:just_audio/just_audio.dart'; void main() ...

  6. BeanDefinition解密:构建和管理Spring Beans的基石

    本文分享自华为云社区<Spring高手之路11--BeanDefinition解密:构建和管理Spring Beans的基石>,作者: 砖业洋__ . BeanDefinition是Spr ...

  7. 华为云PB级数据库GaussDB(for Redis)解析第二期:Redis消息队列Stream的应用探讨

    摘要:本文将对Stream的常用命令和应用场景进行介绍,并探讨原生Redis Stream消息队列的缺陷以及GaussDB(for Redis)提供的解决方案,供大家学习和选用. 华为云高斯Redis ...

  8. 云小课 | 不了解EIP带宽计费规则?看这里!

    摘要:带宽要变更, 费用不会算?要问怎么办,小课带你看! 和小课一起来学习弹性公网IP(EIP)带宽的计费方式.使用场景及变更影响吧~ 在使用弹性公网IP(EIP)产品后,你是否遇到过以下几种场景: ...

  9. vue2升级vue3:vue3真的需要vuex或者Pinia吗?hooks全有了

    在写 <vue2升级vue3:TypeScript下vuex-module-decorators/vuex-class to vuex4.x>,建议新项目使用 Pinia,但是我的项目部分 ...

  10. 如何用Xcode安装ipa

    Xcode安装ipa iOS APP上架App Store其中一个步骤就是要把ipa文件上传到App Store!​ 下面进行步骤介绍!​ 利用Appuploader这个软件,可以在Windows.L ...