ORACLE:
在平时工作中经常会遇到数据库死锁的情况,以前使用oracle时候(那时候还不懂),出现这种情况时前辈给了我一段命令:
SELECT dob.OBJECT_NAME Table_Name,lo.SESSION_ID||', '||vss.SERIAL# 删除号,vss.program,vss.osuser,vss.TERMINAL,
lo.locked_mode,lo.SESSION_ID, vss.SERIAL#,vss.action Action,vss.osuser OSUSER, vss.LOGON_TIME,
vss.process AP_PID, VPS.SPID DB_PID ,vss.*
From v$locked_object lo, dba_objects dob, v$session vss, V$PROCESS VPS
Where lo.OBJECT_ID = dob.OBJECT_ID
and lo.SESSION_ID = vss.SID
AND VSS.paddr = VPS.addr
order by 2,3,DOB.object_name;
ALTER system kill session '134, 12007'; -- --sid,serial
先查询到死锁的对象,在通过查询的结果杀掉该进程即可。
SQLSERVER:
在最近工作中很不幸遇到一个问题,那就是SqlServer的死锁,这个很特别,因为它不是锁了某个对象,而是把整个数据库锁掉了,根本无法访问到该数据库。
最后的解决方案是,在master中执行杀进程的命令:
USE [master]
DECLARE @cmdKill VARCHAR(50)
DECLARE killCursor CURSOR FOR
SELECT 'KILL ' + Convert(VARCHAR(5), p.spid)
FROM master.dbo.sysprocesses AS p
WHERE p.dbid = db_id('auth_ldjt')
OPEN killCursor
FETCH killCursor INTO @cmdKill
WHILE 0 = @@fetch_status
BEGIN
EXECUTE (@cmdKill)
FETCH killCursor INTO @cmdKill
END
CLOSE killCursor
DEALLOCATE killCursor