gpt4 book ai didi

oracle - 从 oracle 跟踪文件中查找死锁错误的原因

转载 作者:行者123 更新时间:2023-12-03 19:53:38 24 4
gpt4 key购买 nike

当多个用户正在使用该应用程序时,我的应用程序中经常出现“在等待资源时检测到 ora-00060 死锁”错误。我从 oracle Admin 那里得到了跟踪文件,但在阅读它时需要帮助。以下是跟踪文件中的一些数据,我希望这些数据有助于查找原因。

*** 2013-06-25 09:37:35.324
DEADLOCK DETECTED ( ORA-00060 )

[Transaction Deadlock]

The following deadlock is not an ORACLE error. It is a deadlock due
to user error in the design of an application
or from issuing incorrect ad-hoc SQL. The following
information may aid in determining the deadlock:

Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TM-000151a2-00000000 210 72 SX SSX 208 24 SX SSX
TM-000151a2-00000000 208 24 SX SSX 210 72 SX SSX

session 72: DID 0001-00D2-000000C6 session 24: DID 0001-00D0-00000043
session 24: DID 0001-00D0-00000043 session 72: DID 0001-00D2-000000C6

Rows waited on:
Session 72: no row
Session 24: no row

----- Information for the OTHER waiting sessions -----
Session 24:
sid: 24 ser: 45245 audsid: 31660323 user: 90/USER
flags: (0x45) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x40009) -/-/INC
pid: 208 O/S info: user: zgrid, term: UNKNOWN, ospid: 2439
image: oracle@xyz.local
client details:
O/S info: user: , term: , ospid: 1234
machine: xyz.local program:
current SQL:
delete from EMPLOYEE where EMP_ID=:1

----- End of information for the OTHER waiting sessions -----

Information for THIS session:

----- Current SQL Statement for this session (sql_id=dyfg1wd8xa9qt) -----
delete from EMPLOYEE where EMP_ID=:1
===================================================

如果有人能告诉我“死锁图::”在说什么,我将不胜感激。等待的行部分也说没有行。

我还在一些博客中读到跟踪文件中的“sqltxt”部分可以暗示原因。下面是我在该部分看到的查询。
 select /*+ all_rows */ count(1) from "USERS"."EMPLOYEE_SALARY" where EMPSAL_EMP_ID=:1

employee_salary 表在 EMPSAL_EMP_ID 列上有外键约束。

sql提示说“all_rows”,那么是不是意味着这个表在从employee表中删除记录时得到了表级锁?我目前在外键列上没有索引。在此列上添加索引有帮助吗?

请张贴,以防万一需要更多信息。

谢谢

最佳答案

首先,select语句从不锁定 Oracle 中的任何内容,只使用最后可用的一致数据版本。这不是 select ... for update 的情况锁定数据,如 update从 Oracle 9i 开始,但没有 for update来自问题的查询中的子句。

Resource Name          process session holds waits  process session holds waits
TM-000151a2-00000000 210 72 SX SSX 208 24 SX SSX

session #72 持有具有“行独占”类型 (SX) 的表级锁 (TM),并希望在同一表上获取“共享行独占”(SSX) 锁。此 session 已被 session #24 阻止,该 session 已持有相同类型 (SX) 的表级锁,并在 SSX 锁可用时等待。
Resource Name          process session holds waits  process session holds waits
TM-000151a2-00000000 208 24 SX SSX 210 72 SX SSX

这(第二行)演示了完全相同的情况,但方向相反: session #24 等待 SSX 锁可用,但被 session #72 阻止,该 session 已经在同一个表上持有 SX 锁。

因此, session #24 和 session #72 相互阻塞:发生死锁。

两种锁类型(SX 和 SSX)都是表级锁。
要了解情况,我建议阅读 this article作者:弗兰克·帕肖。

以下是本文的引文,与您的情况直接相关(请注意,SSX 和 SRX 缩写是等效的):

Referential integrity also acquires TM locks. For example, the common issue with unindexed foreign keys leads to S locks on child table when you issue a delete, or update on the key, on the parent table. This is because without an index, Oracle has no single lower level resource to lock in order to prevent a concurrent insert that can violate the referential integrity.
When the foreign key columns are the leading columns in a regular index, then the first index entry with the parent value can be used as a single resource and locked with a row level TX lock.
And what if referential integrity has an on delete cascade? In addition to the S mode, there is the intention to update rows in the child table, as with Row X (RX) mode. This is where the share row exclusive (SRX) occurs: S+RX=SRX.



因此,最可能的变体是 session #72 和 session #24 删除了 EMPLOYEE 中的一些行。表同时,还有 on delete cascade EMPSAL_EMP_ID 的约束结合 EMPLOYEE_SALARY 上没有索引表中 EMPSAL_EMP_ID首先列出的列。

关于oracle - 从 oracle 跟踪文件中查找死锁错误的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17358088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com