我正在使用多个客户端测试应用程序。在某些时候,我在数据库中遇到了死锁。我得到以下痕迹:
引起:com.indra.davinci.common.dataaccess.DataAccessException: SQL:DELETE FROM EMPLOYEE WHERE DEPT_ID IN(SELECT ID 从DPTO WHERE COMPANY_ID =?),参数:[409386]
和
引起:java.sql.SQLException:ORA-00060:检测到死锁时 等待资源
表EMPLOYEE有两个子表(MANAGER和DEVELOPER),它们都带有EMPLOYEE的外键。我已经为外键创建了索引。 未设置级联删除。另一方面,应用程序的代码执行以下操作: 1.删除子表MANAGER中属于具体EMPLOYEE的行。 2.删除属于具体EMPLOYEE的子表DEVELOPER中的行。 3.删除EMPLOYEE表中的行。 4.删除DPTO表中的行(EMPLOYEE是DPTO的子项,有外键和索引创建)。
我在应用程序中设置了跟踪以获取请求的性能顺序,我看到以下内容:
06/09/2017 08:43:13.539 INIT DELETE MANAGER客户:409383
06/09/2017 08:43:13.539 INIT DELETE MANAGER客户:409386
06/09/2017 08:43:13.555 END DELETE MANAGER客户端:409386
06/09/2017 08:43:13.555 INIT DELETE DEVELOPER客户:409386
06/09/2017 08:43:13.555 END DELETE MANAGER客户:409383
06/09/2017 08:43:13.555 INIT DELETE DEVELOPER客户:409383
06/09/2017 08:43:13.555 END DELETE DEVELOPER客户:409386
06/09/2017 08:43:13.555 INIT DELETE EMPLOYEE客户:409386
06/09/2017 08:43:13.555 END DELETE DEVELOPER客户:409383
06/09/2017 08:43:13.555 INIT DELETE EMPLOYEE客户:409383
06/09/2017 08:43:13.555 INIT DELETE MANAGER客户:409389
06/09/2017 08:43:13.570 INIT DELETE MANAGER客户:409407
06/09/2017 08:43:13.570 END DELETE MANAGER客户:409389
06/09/2017 08:43:13.570 INIT DELETE DEVELOPER客户:409389
06/09/2017 08:43:13.570 END DELETE DEVELOPER客户:409389
06/09/2017 08:43:13.570 INIT DELETE EMPLOYEE客户:409389
06/09/2017 08:43:13.570 END DELETE MANAGER客户端:409407
06/09/2017 08:43:13.570 INIT DELETE DEVELOPER客户:409407
06/09/2017 08:43:13.570 END DELETE DEVELOPER客户:409407
06/09/2017 08:43:13.570 INIT DELETE EMPLOYEE客户:409407
似乎在08:43:13.555瞬间,两个客户正在尝试从EMPLOYEE表中删除。
我在Oracle的跟踪文件中获得以下内容:
Trace file C:\ORACLEXE\APP\ORACLE\diag\rdbms\xe\xe\trace\xe_ora_10068.trc
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
Windows NT Version V6.1 Service Pack 1
CPU : 4 - type 586, 2 Physical Cores
Process Affinity : 0x0x00000000
Memory (Avail/Total): Ph:2347M/16247M, Ph+PgF:15271M/32493M, VA:2685M/4095M
Instance name: xe
Redo thread mounted by this instance: 1
Oracle process number: 36
Windows thread id: 10068, image: ORACLE.EXE (SHAD)
*** 2017-09-06 08:43:16.613
*** SESSION ID:(11.369) 2017-09-06 08:43:16.613
*** CLIENT ID:() 2017-09-06 08:43:16.613
*** SERVICE NAME:(XE) 2017-09-06 08:43:16.613
*** MODULE NAME:(JDBC Thin Client) 2017-09-06 08:43:16.613
*** ACTION NAME:() 2017-09-06 08:43:16.613
*** 2017-09-06 08:43:16.613
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-0008747d-00000000 36 11 SX SSX 32 10 SX SSX
TM-0008747d-00000000 32 10 SX SSX 36 11 SX SSX
session 11: DID 0001-0024-00000114 session 10: DID 0001-0020-0000001C
session 10: DID 0001-0020-0000001C session 11: DID 0001-0024-00000114
Rows waited on:
Session 11: no row
Session 10: no row
----- Information for the OTHER waiting sessions -----
Session 10:
sid: 10 ser: 27 audsid: 14562964 user: 184/USRPLNADIF
flags: (0x41) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x40009) -/-
pid: 32 O/S info: user: SYSTEM, term: MARRIETAW7, ospid: 13724
image: ORACLE.EXE (SHAD)
client details:
O/S info: user: marrieta, term: unknown, ospid: 1234
machine: marrietaw7 program: JDBC Thin Client
application name: JDBC Thin Client, hash value=2546894660
current SQL:
DELETE FROM EMPLOYEE WHERE DEPT_ID IN (SELECT ID FROM DPTO WHERE COMPANY_ID = :1)
----- End of information for the OTHER waiting sessions -----
Information for THIS session:
----- Current SQL Statement for this session (sql_id=6v66dbfh41hbx) -----
DELETE FROM EMPLOYEE WHERE DEPT_ID IN (SELECT ID FROM DPTO WHERE COMPANY_ID = :1)
关于可能发生的事情的任何想法?
感谢。
答案 0 :(得分:0)
好吧,我已经检查了跟踪文件中的死锁图,具体如下:
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TM-0008747d-00000000 36 11 SX SSX 32 10 SX SSX
TM-0008747d-00000000 32 10 SX SSX 36 11 SX SSX
我将十六进制0008747d转换为十进制并执行以下操作:
SELECT * FROM dba_objects WHERE object_id = 554109;
我得到了阻止数据库的表。该表不是由应用程序使用,而是在数据库中创建(可能是在旧版本的应用程序中使用),我发现该表是EMPLOYEE的子表,并且没有FK的索引。我要试着解决这个问题,我会发表评论。