Example to show the dead lock caused by lack of index on foreign key of child table.

Session 1:

create table p ( x int primary key );
create table c ( x references p );

insert into p select rownum from all_users where rownum <= 2;
insert into c select * from p;
commit;
delete from c where x = 1;

Session 2:

prompt delete from c where x = 2;
prompt delete from p where x = 2; -- session 2 will be hang.

Session 1:

delete from p where x = 1; -- session1 will be hang, deadlock will be detected after a while.

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-00012c11-00000000 47 138 SX SSX 45 136 SX SSX
TM-00012c11-00000000 45 136 SX SSX 47 138 SX SSX

session 138: DID 0001-002F-00000176 session 136: DID 0001-002D-00000098
session 136: DID 0001-002D-00000098 session 138: DID 0001-002F-00000176

Rows waited on:
Session 138: no row
Session 136: no row

----- Information for the OTHER waiting sessions -----
Session 136:
sid: 136 ser: 207 audsid: 384548 user: 100/TEST flags: 0x45
pid: 45 O/S info: user: SYSTEM, term: PRICNESSD, ospid: 7044
image: ORACLE.EXE (SHAD)
client details:
O/S info: user: PRICNESSD\Administrator, term: PRICNESSD, ospid: 6880:8016
machine: WORKGROUP\PRICNESSD program: sqlplus.exe
application name: SQL*Plus, hash value=3669949024
current SQL:
delete from p where x=2

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

Information for THIS session:

----- Current SQL Statement for this session (sql_id=dyg3c78z0ft6g) -----
delete from p where x=1
===================================================

The typical identifer for this is two SQL waiting on delete statement on one table, both transaction hold SX lock waiting on SSX lock.

Create on index on the foreign key column will resolve this problem.

create index c_idx on c(x);

Oracle deadlock SX/SSX caused by no index on foreign key.的更多相关文章

  1. Caused by: java.security.InvalidKeyException: Illegal key size or default parameters

    How to remove the key size restriction in Java JDK? Are you developing your beautiful application us ...

  2. Oracle外键(Foreign Key)使用详细的说明(一)

    Oracle外键(Foreign Key)使用详细的说明(一) 1.目标 演示如何Oracle使用外键数据库 2.什么是外键? 1)在Oracle数据库中,外键是用来实现參照完整性的方法之中的一个.打 ...

  3. Oracle之外键(Foreign Key)使用方法具体解释(二)- 级联删除(DELETE CASCADE)

    Oracle外键(Foreign Key)之级联删除(DELETE CASCADE) 目标 演示样例解说怎样在Oracle外键中使用级联删除 什么是级联删除(DELETE CASCADE)? 级联删除 ...

  4. Caused by: java.lang.IllegalStateException: duplicate key: datasource

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...

  5. FOREIGN KEY 外键约束; UNIQUE和PRIMARY KEY 主键约束、CREATE INDEX建立索引的使用

    1)foreign key 是个约束,意思是说如果你给A字段设置了外键约束,以后你要往A字段插入数据,这个数据一定是要在foreign key 后面跟的那个字段中存在的值.这个的意义就是约束了数据的完 ...

  6. Oracle数据库-primary key/foreign key和references关系

    主要介绍一下个人对主键(primary key).外键(foreign key).候选键(Candidate key).超键(super key).references的总结 概念: 主键:用户选择元 ...

  7. oracle deadlock

    Basic operation su - oracle sqlplus / as sysdba show parameter background show parameter user_dump_d ...

  8. Oracle Deadlock / 死锁 处理

    Get the directory of alert log sqlplus / as sysdba show parameters udmp SQL> show parameters dump ...

  9. 转://oracle deadlock死锁trace file分析之一

    ---oracle versionSQL> select * from v$version where rownum=1;BANNER------------------------------ ...

随机推荐

  1. linux进程用户内存空间和内核空间

    When a process running in user mode requests additional memory, pages are allocated from the list of ...

  2. HDU 1043 & POJ 1077 Eight(康托展开+BFS+预处理)

    Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30176   Accepted: 13119   Special ...

  3. UIButton 长按点击 背景改变效果

    1.添加按钮的点击事件和按下事件 [btn setImage:[UIImage imageNamed:@"NorMal.png"] forState:UIControlStateN ...

  4. 升级xcode6和ios8后,unity遇到的一些小问题

    升级最新的Xocde6后,如果不是最新版本的unity,虽然也可以也可以正常的build,但如果想通过unity连真机进行profile的话,就会在xocde中报错,这个的主要原因是unity的配置里 ...

  5. php开源项目

    论坛社区:Discuz.PHPWind.ThinkSAAS.phpBB CMS内容管理:DedeCMS.PHPCMS.帝国CMS.齐博CMS.Drupal 企业建站:CmsEasy.KingCMS.P ...

  6. JavaScript数据类型(转)

    JavaScript中有5种简单数据类型(也称为基本数据类型):Undefined.Null.Boolean.Number和String.还有1种复杂数据类型——Object,Object本质上是由一 ...

  7. Java Tool

    PS参数详解 http://blog.csdn.net/hanner_cheung/article/details/6081440 JVM 参数 JVM调优总结 -Xms -Xmx -Xmn –Xss ...

  8. log4j常用配置以及日志文件保存位置

    log4j.rootLogger=INFO,CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender ...

  9. Android之Dialog详解

    Android中的对话框形式大致可分为五种:分别是一般对话框形式,列表对话框形式,单选按钮对话框,多选按钮对话框,自定义对话框. 在实际开发中,用系统的对话框会很少,因为太丑了,美工不愿意,多是使用自 ...

  10. LogNet4学习笔记

    LogNet是一套开源的程序日志记录系统,经过配置后可以自动抓取程序中的错误.异常信息,并写入磁盘,也可以在异常发生时执行其他指定的操作,比如:通知某人右键.写入数据库等. 这里写个AspNet应用L ...