DB2如何将数据库表解锁(2009-06-27 14:09:44)转载标签:it 分类:数据库技术

在DB2的命令行中输入:

update monitor switches using lock on table on

然后打开另一个DB2命令窗口执行我的那个被吊死的Update语句。

然后在第一个DB2命令窗口执行:

get snapshot for locks on Database_Name(你的数据库的名字)> locks.TXT

然后,可以看到第一个DB2的窗口有一个信息输出,把这些信息输出到TXT中,大致如下:

应用程序句柄                    = 36
应用程序标识                    = AC100C47.IC05.00F6C6095828
序号                          = 0246
应用程序名                      = java.exe
CONNECT 授权标识                = DB2ADMIN
应用程序状态                    = UOW 正在等待
状态更改时间                    = 未收集
应用程序代码页                  = 1208
挂起的锁定                      = 0
总计等待时间(毫秒)            = 0

应用程序句柄                    = 43
应用程序标识                    = *LOCAL.DB2.060512054331
序号                          = 2273
应用程序名                      = java.exe
CONNECT 授权标识                = DB2ADMIN
应用程序状态                    = 联合请求暂挂
状态更改时间                    = 未收集
应用程序代码页                  = 1208
挂起的锁定                      = 6
总计等待时间(毫秒)            = 0

锁定列表
 锁定名称                       = 0x031F9052000000000000000055
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 255
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部
 方式                           = S

 锁定名称                       = 0x26800000000000000000000044
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部
 方式                           = S

 锁定名称                       = 0x020006000F1700000000000052
 锁定属性                       = 0x00000000
 发行版标志                     = 0x00000001
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 5903
 对象类型                       = 行
 表空间名                       = USERSPACE1
 表模式                         = DB2ADMIN
 表名                           = C_USER
 方式                           = NS

 锁定名称                       = 0x01000000010000000500BC0056
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部变化锁定
 方式                           = S

 锁定名称                       = 0x535953534E333030FD965C0641
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部方案锁定
 方式                           = S

 锁定名称                       = 0x02000600000000000000000054
 锁定属性                       = 0x00000000
 发行版标志                     = 0x00000001
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 6
 对象类型                       = 表
 表空间名                       = USERSPACE1
 表模式                         = DB2ADMIN
 表名                           = C_USER
 方式                           = IS

应用程序句柄                    = 557
应用程序标识                    = *LOCAL.DB2.060512053913
序号                          = 1254
应用程序名                      = java.exe
CONNECT 授权标识                = DB2ADMIN
应用程序状态                    = 联合请求暂挂
状态更改时间                    = 未收集
应用程序代码页                  = 1208
挂起的锁定                      = 6
总计等待时间(毫秒)            = 0

锁定列表
 锁定名称                       = 0x031F9052000000000000000055
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 255
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部
 方式                           = S

 锁定名称                       = 0x26800000000000000000000044
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部
 方式                           = S

 锁定名称                       = 0x02000600071D00000000000052
 锁定属性                       = 0x00000000
 发行版标志                     = 0x00000001
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 7431
 对象类型                       = 行
 表空间名                       = USERSPACE1
 表模式                         = DB2ADMIN
 表名                           = C_USER
 方式                           = NS

 锁定名称                       = 0x01000000010000000500BC0056
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部变化锁定
 方式                           = S

 锁定名称                       = 0x535953534E333030FD965C0641
 锁定属性                       = 0x00000000
 发行版标志                     = 0x40000000
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 0
 对象类型                       = 内部方案锁定
 方式                           = S

 锁定名称                       = 0x02000600000000000000000054
 锁定属性                       = 0x00000000
 发行版标志                     = 0x00000001
 锁定计数                       = 1
 挂起计数                       = 0
 锁定对象名                     = 6
 对象类型                       = 表
 表空间名                       = USERSPACE1
 表模式                         = DB2ADMIN
 表名                           = C_USER
 方式                           = IS

 

其中应用程序句柄43和557的状态都是死锁了,猜测是这2个应用争用DB2的表,造成死锁,根据日志提示,在DB2的命令窗口输入:

force application (43)

force application (557)

提示这个操作是异步的,我执行list applicaions,结果进程中还有那2个进程,那2个进程可能是在执行比较大的操作,需要耐心等待,如何还不行,则使用下面的命令来强制所有的应用都停止,然后重启DB2:

force application all

terminate

db2stop force

db2start

    如果DB2在Window上,则可以使用“控制中心”->实例->右键“应用程序”,可以看到当前的锁定情况,并且可以强行关闭某个进程,也可以显示“锁定链”。