3、死锁
死锁就是两个进程都在等待对方持有的资源锁,要等对方释放持有的资源锁之后才能继续工作,它们互不相让,坚持到底,实际上,双方都要等到对方完成之后才能继续工作,而双方都完成不了。
Oracle死锁样本: 步骤一:
登陆ORACLE SQL *plus 之一窗口,执行:
update HR.JOBS
SET JOB_title = ’S.Finance Manager’
where job_id = ’FI_MGR’ 步骤二:
登陆ORACLE SQL *plus 之二窗口,执行:
update HR.JOBS
SET JOB_title = ’S.President’
where job_id = ’AD_PRES’; 步骤三:
重新ORACLE SQL *plus 之一窗口,执行
update HR.JOBS
SET JOB_title = ’S.President’
where job_id = ’AD_PRES’;
发现已经无法完成,因为在等待资源释放。 步骤四:
登陆ORACLE SQL *plus 之二窗口,执行:
update HR.JOBS
SET JOB_title = ’S.Finance Manager’
where job_id = ’FI_MGR’
此时出现ORA-00060错误,如下图所示:
发现报出错误,系统检测到死锁,此时打开C:\oracle\admin\ORADB\udump\的oradb_ora_5528文件会发现已经记录了死锁deadlock日志,文字如下:
*** 2008-07-05 16:46:43.000
*** SESSION ID:(17.16) 2008-07-05 16:46:43.000
DEADLOCK DETECTED
Current SQL statement for this session:
update HR.JOBS
SET JOB_title = ’S.President’
where job_id = ’AD_PRES’
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
infromation may aid in determining the deadlock:
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-000a0002-00001904 16 17 X 17 18 X
TX-00010010-00001917 17 18 X 16 17 X
session 17: DID 0001-0010-00000003 session 18: DID 0001-0011-00000003
session 18: DID 0001-0011-00000003 session 17: DID 0001-0010-00000003
Rows waited on:
Session 18: obj - rowid = 00007339 - AAAHM5AAFAAAABGAAD
(dictionary objn - 29497,file- 5, block - 70, slot - 3)
Session 17: obj - rowid = 00007339 - AAAHM5AAFAAAABGAAA
(dictionary objn - 29497, file - 5, block - 70, slot - 0)
Information on the OTHER waiting sessions:
Session 18:
pid=17 serial=20 audsid=0 user: 0/SYS
O/S info: user: WANGTM\wangtm, term: WANGTM, ospid: 5200:4876, machine: WORKGROUP\WANGTM
prigram: sqlplusw.exe
Current SQL Statement:
update HR.JOBS
SET JOB_title = ’S.Finance Manager’
where job_id = ’FI_MGR’
End of information on OTHER waiting sessions.