<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; TX Enqueue contention</title>
	<atom:link href="https://www.xifenfei.com/tag/tx-enqueue-contention/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Thu, 29 Oct 2026 15:31:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>分析一例 TX Enqueue contention案例</title>
		<link>https://www.xifenfei.com/2012/07/%e5%88%86%e6%9e%90%e4%b8%80%e4%be%8b-tx-enqueue-contention%e6%a1%88%e4%be%8b.html</link>
		<comments>https://www.xifenfei.com/2012/07/%e5%88%86%e6%9e%90%e4%b8%80%e4%be%8b-tx-enqueue-contention%e6%a1%88%e4%be%8b.html#comments</comments>
		<pubDate>Thu, 05 Jul 2012 07:03:27 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[Oracle性能优化]]></category>
		<category><![CDATA[TX Enqueue contention]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=3436</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2012/07/%e5%88%86%e6%9e%90%e4%b8%80%e4%be%8b-tx-enqueue-contention%e6%a1%88%e4%be%8b.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2012/07/%e5%88%86%e6%9e%90%e4%b8%80%e4%be%8b-tx-enqueue-contention%e6%a1%88%e4%be%8b.html" target="_blank">分析一例 TX Enqueue contention案例</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>应用反馈某个业务比较慢,需要紧急处理<br />
<strong>查询等待事件</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE    9.2.0.8.0       Production
TNS for IBM/AIX RISC System/6000: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production

SQL&gt; select A.INST_ID,count(*), event
  2    from Gv$session_wait a
  3  where event not in ('SQL*Net more data to client',
  4  'rdbms ipc message',
  5               'smon timer',
  6               'pmon timer',
  7               'SQL*Net message from client',
  8               'lock manager wait for remote message',
  9               'ges remote message',
 10               'gcs remote message',
 11               'gcs for action',
 12               'client message',
 13               'pipe get',
 14               'null event',
 15               'PX Idle Wait',
 16               'single-task message',
 17               'PX Deq: Execution Msg',
 18               'KXFQ: kxfqdeq - normal deqeue',
 19               'listen endpoint status',
 20               'slave wait',
 21               'wakeup time manager','jobq slave wait')
 22  group by INST_ID,event
 23  order by 1 desc,2 desc;

   INST_ID   COUNT(*) EVENT
---------- ---------- --------------------------------------
         2          8 enqueue
         2          1 async disk IO
         2          1 db file sequential read
         2          1 SQL*Net message to client
         2          1 PX Deq: reap credit
         1          2 global cache cr request
         1          1 async disk IO
         1          1 PX Deq: reap credit
         1          1 PX Deq: Execute Reply

9 rows selected.
</pre>
<p><strong>发现enqueue等待有些多,怀疑是TX enquenue,查询阻塞者</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; set linesize 100
SQL&gt; set pagesize 66
SQL&gt; col c1 for a15
SQL&gt; col c1 heading &quot;Program Name &quot;
SQL&gt; select l.inst_id,l.SID,program c1,l.TYPE,l.ID1,l.ID2,l.LMODE,l.REQUEST
  2  from gv$lock l,gv$session s
  3  where l.type like 'TX' and l.REQUEST =6
  4  and l.inst_id=s.inst_id and l.sid=s.sid
  5  order by id1
  6  / 

   INST_ID        SID Program Name    TY        ID1        ID2      LMODE    REQUEST
---------- ---------- --------------- -- ---------- ---------- ---------- ----------
         2        295 rtStopMain@zwq_ TX    1441805    2391806          0          6
                      bill_2 (TNS V1-
                      V3)

         2        992 rtStopMain@zwq_ TX    1441805    2391806          0          6
                      bill_2 (TNS V1-
                      V3)

         2       1238 rtStopMain@zwq_ TX    6946827    2546365          0          6
                      bill_2 (TNS V1-
                      V3)

         2       1298 rtStopMain@zwq_ TX    6946827    2546365          0          6
                      bill_2 (TNS V1-
                      V3)

         2       1684 rtStopMain@zwq_ TX    6946827    2546365          0          6
                      bill_2 (TNS V1-
                      V3)

         2       1553 rtStopMain@zwq_ TX    6946827    2546365          0          6
                      bill_2 (TNS V1-
                      V3)

         2         75 rtStopMain@zwq_ TX   12451856     199146          0          6
                      bill_2 (TNS V1-
                      V3)

         2       1125 rtStopMain@zwq_ TX   14352404      63837          0          6
                      bill_2 (TNS V1-
                      V3)
</pre>
<p><strong>查询持有者</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; set linesize 100
SQL&gt; set pagesize 66
SQL&gt; col c1 for a15
SQL&gt; col c1 heading &quot;Program Name &quot;
SQL&gt; select l.inst_id,l.SID,program c1,l.TYPE,l.ID1,l.ID2,l.LMODE,l.REQUEST
  2  from gv$lock l,gv$session s
  3  where l.type like 'TX' and l.LMODE =6 and (l.ID1,l.ID2) in
  4  (select id1,id2 from gv$lock where type like 'TX' and REQUEST =6)
  5  and l.inst_id=s.inst_id and l.sid=s.sid
  6  order by id1
  7  / 

   INST_ID        SID Program Name    TY        ID1        ID2      LMODE    REQUEST
---------- ---------- --------------- -- ---------- ---------- ---------- ----------
         2         75 rtStopMain@zwq_ TX    1441805    2391806          6          0
                      bill_2 (TNS V1-
                      V3)

         2        992 rtStopMain@zwq_ TX    6946827    2546365          6          0
                      bill_2 (TNS V1-
                      V3)

         2        295 rtStopMain@zwq_ TX   12451856     199146          6          0
                      bill_2 (TNS V1-
                      V3)

         2       1553 rtStopMain@zwq_ TX   14352404      63837          6          0
                      bill_2 (TNS V1-
                      V3)
</pre>
<p>通过持有者和阻塞者可以得出:<br />
1.持有者和阻塞者都是在2号实例上<br />
2.持有者75阻塞了295/992的会话<br />
3.持有者992阻塞了1238/1298/1684/1553的会话<br />
4.持有者295阻塞了75的会话<br />
5.持有者1553阻塞了1125的会话<br />
6.同时分析发现,所有的持有者sid也在阻塞者中,也就是持有者阻塞了某个sid,而自身又被其他sid给阻塞,形成了多级阻塞或者环.如:75阻塞了295,而295有阻塞了75;992阻塞了1553,而1553阻塞了1125<br />
<br />
<strong>查询阻塞和持有者对象</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; set linesize 110
SQL&gt; col c0 for 999
SQL&gt; col c0 heading &quot;INS&quot;
SQL&gt; col c1 for a15
SQL&gt; col c1 heading &quot;Program Name &quot;
SQL&gt; select inst_id c0,sid,program c1,ROW_WAIT_OBJ# object_no, ROW_WAIT_FILE# Rfile_no,
  2  ROW_WAIT_BLOCK# Block_no ,ROW_WAIT_ROW# Row_no
  3  from gv$session
  4  where (inst_id,sid) in (select inst_id,sid from gv$session_wait where p1='1415053318')
  5  / 

 INS        SID Program Name     OBJECT_NO   RFILE_NO   BLOCK_NO     ROW_NO
---- ---------- --------------- ---------- ---------- ---------- ----------
   2         75 rtStopMain@zwq_    1323132         13     122601        111
                bill_2 (TNS V1-
                V3)

   2        295 rtStopMain@zwq_    1323132         13     122601        100
                bill_2 (TNS V1-
                V3)

   2        992 rtStopMain@zwq_    1323132         13     122601        101
                bill_2 (TNS V1-
                V3)

   2       1125 rtStopMain@zwq_    1323132         84      38445         70
                bill_2 (TNS V1-
                V3)

   2       1238 rtStopMain@zwq_    1323132         15     255066         41
                bill_2 (TNS V1-
                V3)

   2       1298 rtStopMain@zwq_    1323132         14     118411          8
                bill_2 (TNS V1-
                V3)

   2       1553 rtStopMain@zwq_    1323132         15     255066         19
                bill_2 (TNS V1-
                V3)

   2       1684 rtStopMain@zwq_    1323132         14     118411         21
                bill_2 (TNS V1-
                V3)

8 rows selected.

SQL&gt; set linesize 100
SQL&gt; set pagesize 100
SQL&gt; col owner for a10
SQL&gt; col object_name for a20
SQL&gt; col object_type for a10
SQL&gt; select owner,object_name,object_id,object_type
  2  from dba_objects
  3  where
  4  object_id in (select ROW_WAIT_OBJ# from gv$session
  5  where (inst_id, sid) in (select inst_id,sid from gv$session_wait where p1='1415053318'))
  6  / 
 

OWNER      OBJECT_NAME           OBJECT_ID OBJECT_TYP
---------- -------------------- ---------- ----------
DBACCADM   DCUSTCREDITBALANCE      1323132 TABLE
</pre>
<p>通过查询的出来,所有操作的聚焦点都是在DBACCADM.DCUSTCREDITBALANCE表上面<br />
<br />
<strong>查询相关sql语句</strong></p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; SQL&gt; set linesize 120
SQL&gt; set pagesize 66
SQL&gt; col c0 for 999
SQL&gt; col c0 heading &quot;INS&quot;
SQL&gt; col c1 for a9
SQL&gt; col c1 heading &quot;OS User&quot;
SQL&gt; col c2 for a9
SQL&gt; col c2 heading &quot;Oracle User&quot;
SQL&gt; col c3 for a15
SQL&gt; col c3 heading &quot;Program Name&quot;
SQL&gt; col b1 for a9
SQL&gt; col b1 heading &quot;Unix PID&quot;
SQL&gt; col b2 for 9999 justify left
SQL&gt; col b2 heading &quot;ORA SID&quot;
SQL&gt; col b3 for 999999 justify left
SQL&gt; col b3 heading &quot;SERIAL#&quot;
SQL&gt; col sql_text for a45
SQL&gt; set space 1
SQL&gt; break on b1 nodup on c0 nodup on c3 nodup on c1 nodup on c2 nodup on b2 nodup on b3 skip 2
SQL&gt; select a.inst_id c0,b.sid b2,c.spid b1, b.program c3, b.username c2,b.serial# b3, a.sql_text
  2    from gv$sql a, gv$session b, gv$process c
  3   where
  4     a.address = b.sql_address
  5     and b.paddr = c.addr
  6     and a.hash_value = b.sql_hash_value
  7     and a.inst_id=b.inst_id and a.inst_id=c.inst_id
  8     and a.inst_id like '&amp;inst_id' and b.sid like '&amp;sid'
  9   order by c.spid,a.hash_value
 10  / 
Enter value for inst_id: 2
Enter value for sid: 75
old   8:    and a.inst_id like '&amp;inst_id' and b.sid like '&amp;sid'
new   8:    and a.inst_id like '2' and b.sid like '75'

 INS ORA SID Unix PID  Program Name    Oracle Us SERIAL# SQL_TEXT
---- ------- --------- --------------- --------- ------- ---------------------------------------------
   2      75 1167392   rtStopMain@zwq_ DBCUSTOPR   42815 update dcustcreditbalance  set limit_owe=:b0,
                       bill_2 (TNS V1-                   unbill_fee=:b1,prepay_fee=:b2,owe_fee=:b3,op_
                       V3)                               time=sysdate where id_no=:b4




SQL&gt; /
Enter value for inst_id: 2
Enter value for sid: 992
old   8:    and a.inst_id like '&amp;inst_id' and b.sid like '&amp;sid'
new   8:    and a.inst_id like '2' and b.sid like '992'

 INS ORA SID Unix PID  Program Name    Oracle Us SERIAL# SQL_TEXT
---- ------- --------- --------------- --------- ------- ---------------------------------------------
   2     992 2760870   rtStopMain@zwq_ DBCUSTOPR   56282 update dcustcreditbalance  set limit_owe=:b0,
                       bill_2 (TNS V1-                   unbill_fee=:b1,prepay_fee=:b2,owe_fee=:b3,op_
                       V3)                               time=sysdate where id_no=:b4




SQL&gt; /
Enter value for inst_id: 2
Enter value for sid: 295
old   8:    and a.inst_id like '&amp;inst_id' and b.sid like '&amp;sid'
new   8:    and a.inst_id like '2' and b.sid like '295'

 INS ORA SID Unix PID  Program Name    Oracle Us SERIAL# SQL_TEXT
---- ------- --------- --------------- --------- ------- ---------------------------------------------
   2     295 1639008   rtStopMain@zwq_ DBCUSTOPR   35740 update dcustcreditbalance  set limit_owe=:b0,
                       bill_2 (TNS V1-                   unbill_fee=:b1,prepay_fee=:b2,owe_fee=:b3,op_
                       V3)                               time=sysdate where id_no=:b4
</pre>
<p>其他阻塞者和持有者执行sql语句均和该语句相同,省略其他查询.通过这些查询可以确定是因为对dcustcreditbalance表的更新操作导致了这样的现象发生.<br />
<br />
<strong>处理方案</strong><br />
1.临时处理方案:kill掉持有者<br />
2.永久处理方案:修改这部分程序业务逻辑</p>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/06/to-find-the-tx-enqueue-contention-in-a-rac-or-ops-environment.html" rel="bookmark" class="crp_title">To find the TX Enqueue contention in a RAC or OPS environment</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2023/04/vwait_chains.html" rel="bookmark" class="crp_title">V$Wait_Chains定位阻塞源头</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/01/%e8%af%a1%e5%bc%82dblink%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3-dblink-insert%e6%93%8d%e4%bd%9c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%8f%91%e7%94%9f%e6%94%b9%e5%8f%98.html" rel="bookmark" class="crp_title">诡异dblink问题解决&#8211;dblink insert操作数据类型发生改变</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2022/10/oracle-open-hang.html" rel="bookmark" class="crp_title">oracle open hang 等待cursor: pin S wait on X</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2013/01/%e8%ae%be%e7%bd%ae_smu_debug_mode%e5%ae%9e%e7%8e%b0%e6%8c%87%e5%ae%9asession%e7%ba%a7%e5%88%ab%e4%bd%bf%e7%94%a8%e7%89%b9%e5%ae%9a%e5%9b%9e%e6%bb%9a%e6%ae%b5.html" rel="bookmark" class="crp_title">设置_smu_debug_mode实现指定session级别使用特定回滚段</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/06/gv%e8%a7%86%e5%9b%be%e4%b8%8d%e8%83%bd%e6%9f%a5%e8%af%a2%e6%89%80%e6%9c%89%e8%8a%82%e7%82%b9%e4%bf%a1%e6%81%af.html" rel="bookmark" class="crp_title">gv$视图不能查询所有节点信息</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/12/vpwfile_users%e5%92%8c%e5%af%86%e7%a0%81%e6%96%87%e4%bb%b6%e5%85%b3%e7%b3%bb%e7%bb%ad.html" rel="bookmark" class="crp_title">V$PWFILE_USERS和密码文件关系(续)</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/02/show-hidden-parameter.html" rel="bookmark" class="crp_title">show hidden parameter</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2010/12/%e5%af%bc%e8%87%b4oracle%e8%a2%ab%e9%94%81%e7%9a%84sql%e8%af%ad%e5%8f%a5.html" rel="bookmark" class="crp_title">查询oracle被锁对象并解锁</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2020/01/heatmap-segment-size-is-large.html" rel="bookmark" class="crp_title">sysaux中HEATMAP 对象较大</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/03/v%e8%a7%86%e5%9b%be%e7%94%b1%e6%9d%a5.html" rel="bookmark" class="crp_title">v$和gv$来源</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/01/reliable-message.html" rel="bookmark" class="crp_title">reliable message等待</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2012/07/%e5%88%86%e6%9e%90%e4%b8%80%e4%be%8b-tx-enqueue-contention%e6%a1%88%e4%be%8b.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
