先查看哪些表被锁住了
select bownerbobject_nameasession_idalocked_mode
from v$locked_object adba_objects b
where bobject_id = aobject_id;
OWNER OBJECT_NAME SESSION_ID LOCKED_MODE
WSSB SBDA_PSHPFTDT
WSSB_RTREPOS WB_RT_SERVICE_QUEUE_TAB
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB
WSSB_RTREPOS WB_RT_NOTIFY_QUEUE_TAB
WSSB SBDA_PSDBDT
WSSB_RTREPOS WB_RT_AUDIT_DETAIL
select busernamebsidbserial#logon_time
from v$locked_object av$session b
where asession_id = bsid order by blogon_time;
USERNAME SID SERIAL# LOGON_TIME
WSSB_RTACCESS
WSSB_RTACCESS
杀会话
alter system kill session sidserial#;
eg
alter system kill session ;
如果有ora错误则在后面加immediate;
alter system kill session immediate;
1查哪个过程被锁
查V$DB_OBJECT_CACHE视图:
SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER=过程的所属用户 AND CLOCKS!=;
查是哪一个SID通过SID可知道是哪个SESSION
查V$ACCESS视图:
SELECT * FROM V$ACCESS WHERE OWNER=过程的所属用户 AND NAME=刚才查到的过程名;
查出SID和SERIAL#
查V$SESSION视图:
SELECT SIDSERIAL#PADDR FROM V$SESSION WHERE SID=刚才查到的SID
查V$PROCESS视图:
SELECT SPID FROM V$PROCESS WHERE ADDR=刚才查到的PADDR;
杀进程
()先杀ORACLE进程:
ALTER SYSTEM KILL SESSION 查出的SID查出的SERIAL#;
()再杀操作系统进程:
KILL 刚才查出的SPID
或
ORAKILL 刚才查出的SID 刚才查出的SPID
oracle的死锁
查询数据库死锁
select tusername|| ||tsid|| ||tserial#|| ||tlogon_time|| ||tsql_text
from v$locked_object tv$session tv$sqltext t
where tsession_id=tsid
and tsql_address=taddress
order by tlogon_time;
查询出来的结果就是有死锁的session了
下面就是杀掉
拿到上面查询出来的SID和SERIAL#填入到下面的语句中
alter system kill session sidserial#;
一般情况可以解决数据库存在的死锁了
或通过session id 查到对应的操作系统进程在unix中杀掉操作系统的进程
SELECT ausernamecspid AS os_process_idcpid AS oracle_process_id FROM v$session av$process c
WHERE caddr=apaddr and asid= and aserial#= ;
然后采用kill (unix) 或 orakill(windows )
在unix中
ps ef|grep os_process_id
kill os_process_id
ps ef|grep os_process_id
经常在oracle的使用过程中碰到这个问题所以也总结了一点解决方法)
)查找死锁的进程
sqlplus /as sysdba (sys/change_on_install)
SELECT susernamelOBJECT_IDlSESSION_IDsSERIAL#lORACLE_USERNAMElOS_USER_NAMElPROCESS
FROM V$LOCKED_OBJECT lV$SESSION S WHERE lSESSION_ID=SSID;
)kill掉这个死锁的进程
alter system kill session sidserial#; (其中sid=lsession_id)
)如果还不能解决
select prospid from v$session sesv$process pro where sessid=XX and sespaddr=proaddr;
其中sid用死锁的sid替换
exit
ps ef|grep spid
其中spid是这个进程的进程号kill掉这个Oracle进程