今天一个系统oracle数据库老是报死锁问题,可以看出:
Thu Aug 26 15:57:11 2010
ORA-00060: Deadlock detected. More info in file /opt/app/oracle/admin/TMNEWOSS/udump/tmnewoss_ora_225.trc.
Thu Aug 26 16:00:27 2010
ORA-00060: Deadlock detected. More info in file /opt/app/oracle/admin/TMNEWOSS/udump/tmnewoss_ora_812.trc.
每隔一段时间就不停地报错,首先我们应该明确产生死锁的原因:
当两个或更多用户相互等待锁定的数据时就会发生死锁,发生死锁时,这些用户被卡住不能继续处理业务,Oracle自动检测死锁并解决它们(通过回滚一个包含在死锁中的语句实现),释放掉该语句锁住的数据,回滚的会话将会遇到Oracle错误“ORA-00060:等待资源时检测到死锁”。
那么这个问题处理就很容易了,程序设计逻辑上有些问题,因为oracle 10g检测和解除死锁的功能,并生成trace文件,那么我们可以找到生成的文件,里面有详细的错误,将发生问题的会话修改提交或回滚即可,如本次可以找到如下信息:
/opt/app/oracle/admin/TMNEWOSS/udump/tmnewoss_ora_225.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /opt/app/oracle/product/10.2.0
System name: SunOS
Node name: tmossstandby
Release: 5.10
Version: Generic_138888-03
Machine: sun4u
Instance name: TMNEWOSS
Redo thread mounted by this instance: 1
Oracle process number: 419
Unix process pid: 225, image: oracle@tmossstandby
*** 2010-08-26 15:57:11.288
*** SERVICE NAME:(SYS$USERS) 2010-08-26 15:57:11.248
*** SESSION ID:(561.4685) 2010-08-26 15:57:11.248
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
TX-00170025-0001f763 419 561 X 408 126 S
TX-00010004-0006102f 408 126 X 419 561 X
session 561: DID 0001-01A3-0008D5C0 session 126: DID 0001-0198-0011E9FB
session 126: DID 0001-0198-0011E9FB session 561: DID 0001-01A3-0008D5C0
Rows waited on:
Session 126: no row
Session 561: obj - rowid = 0000F909 - AAAPkJAANAAAAcxAAG
(dictionary objn - 63753, file - 13, block - 1841, slot - 6)
Information on the OTHER waiting sessions:
Session 126:
pid=408 serial=34132 audsid=48552656 user: 101/TMOSSALARM
O/S info: user: , term: , ospid: 1234, machine: tmossapp
program:
Current SQL Statement:
delete from ALARMINFO where ALARMNUMBER=:1
End of information on OTHER waiting sessions.
Current SQL statement for this session:
update ALARMINFO set ADAPTERNAME=:1, ALARMCAUSE=:2, CLEARABLE=:3, ISCLEARED=:4, INSERTTIME=:5, ALARMLEVEL=:6, PROBABLECAUSE=:7, source=:8, ALARMOBJECT=:9, OBJCLASS=:10, ALARMTYPE=:11, ISACKED=:12, ACKTIME=:13, ACKPERSON=:14, CLEARTIME=:15, CLEARPERSON=:16, COMPRESSED=:17, ALARMCOUNTER=:18, faultBillStatus=:19, ASSIGNPERSON=:20, ASSIGNTIME=:21, STARTTIME=:22, LASTSTARTTIME=:23, ORIGINAL_LEVEL=:24, ORIGINAL_TYPE=:25, REDEFINED=:26, UPGRADED=:27, USERREMARK=:28, starredUserForDao=:29, speciality=:30, originalCause=:31, sourceName=:32, neId=:33, neName=:34, neType=:35, vendorId=:36, TERRITORY_ID=:37, FINGERPRINT=:38, RELATEDALARMS=:39, STATIONCODE=:40, ACTIVEDURATION=:41, REMARKTIME=:42, STATIONNAME=:43, DISTRICTNAME=:44, clearAlarmText=:45, ALARMCAUSEID=:46, FAULTRULEID=:47, FAULTCLASSID=:48, middleObjectId=:49, smallObjectId=:50, middleObjectName=:51, smallObjectName=:52, neGroup=:53, middleObjectType=:54, smallObjectType=:55, additionalInfo=:56, notificationId=:57 where ALARMNUMBER=:58
===================================================
PROCESS STATE
-------------
Process global information:
process: 4b851f980, call: 407057f98, xact: 4b5670a38, curses: 4b86e5800, usrses: 4b86e5800
----------------------------------------
SO: 4b851f980, type: 2, owner: 0, flag: INIT/-/-/0x00
(process) Oracle pid=419, calls cur/top: 407057f98/407057f98, flag: (0) -
int error: 0, call error: 0, sess error: 0, txn error 0
(post info) last post received: 109 0 4
last post received-location: kslpsr
last process to post me: 4b84ba4b8 2 6
last post sent: 0 0 24
last post sent-location: ksasnd
last process posted by me: 4b84ba4b8 2 6
(latch info) wait_event=0 bits=0
Process Group: DEFAULT, pseudo proc: 4b8566a38
O/S info: user: oracle, term: UNKNOWN, ospid: 225
OSD pid info: Unix process pid: 225, image: oracle@tmossstandby
我们可以很清楚的找到问题的原因和根本,很简单,检查程序中的语句,使其执行后提交即可。