DB2锁问题分析与解释

来源:未知 责任编辑:责任编辑 发表时间:2015-03-01 01:41 点击:
DB2 锁问题分析与解释


DB2 应用中经常会遇到锁超时与死锁现象,那么这种现象产生的原因是什么呢。本文以试验的形式模拟锁等待、锁超时、死锁现象,并给出这些现象的根本原因。


试验环境:


DB2 v9.7.0.6
AIX 6.1.0.0
采用默认的隔离级别CS

STUDENT表的DDL与初始内容
------------------------------------------------
-- DDL Statements for table "E97Q6C "."STUDENT"
------------------------------------------------

CREATE TABLE "E97Q6C "."STUDENT" (
"AGE" INTEGER ,
"NAME" CHAR(8) )
IN "USERSPACE1" ;


$ db2 "select * from student"


AGE NAME
----------- --------
3 xu
5 gao
2 liu
1 gu







试验1:验证insert操作与其他操作的锁等待问题


session 1中发出insert操作,在session 2中观察insert,update,delete操作是否会锁超时。


session 1
---------
$ db2 +c "insert into student values(4, 'miao')"
DB20000I The SQL command completed successfully.


session 2
---------
$ db2 "insert into student values(6, 'mu')"
DB20000I The SQL command completed successfully.
$ db2 "update student set name='gu' where age=1"
DB20000I The SQL command completed successfully.
$ db2 "delete from student where age=2"
DB20000I The SQL command completed successfully.

----------------------------------------------------------------------------

结论1:当session 1对表作insert操作时,session 2对该表的insert及其他行的update,delete操作都不会有问题


----------------------------------------------------------------------------


试验2:验证update操作与其他操作的锁等待问题
session 1中发出update操作,在session 2中观察insert,update,delete操作是否会锁超时。
--------------
session 1
---------
$ db2 commit


$ db2 "select * from student"


AGE NAME
----------- --------
3 xu
5 gao
6 mu
4 miao
1 gu


5 record(s) selected.


$ db2 +c "update student set name = 'qing' where age=4"
DB20000I The SQL command completed successfully.


session 2
---------
$ db2 "insert into student values(6, 'mu')"
DB20000I The SQL command completed successfully.
$ db2 "update student set name='gu' where age=1"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0911N The current transaction has been rolled back because of a deadlock
or timeout. Reason code "68". SQLSTATE=40001
$ db2 "delete from student where age=2"
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • DB2 · CREATE TABLESPACE
  • DB2数据库的导出与导入(Windows客户端)
  • DB2查看表结构及所用表语句
  • db2 CLP中如何换行
  • db2管理工具小结
  • 使用DB2对象:创建模式、表和视图
  • DB2数据库逻辑卷的复制
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索 - 移动版 - 返回顶部
Copyright © 2008-2013 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1