ORA-00031: session marked for kill
Windows 下Oracle 数据库,出现锁表的情况,查询锁表语句:
select object_name, machine, s.sid, s.serial#from gv$locked_object l, dba_objects o, gv$session swhere l.object_id = o.object_idand l.session_id = s.sid;
用alter system kill session ‘sid, serial#’ 结束会话
当session是active的时候,alter system kill session 只是将session标识为killed状态,并不会释放session持有的资源,所以在执行完alter system kill session 后,看会话还是一直存在,等待PMON进程回收资源和释放锁。
--释放SESSION SQL:
--alter system kill session 'sid, serial#';
alter system kill session '510,24348';ORA-00031: session marked for kill
增加immediate 参数,也不起作用:
SQL> alter system kill session '510,24348' immediate;
alter system kill session '510,24348' immediateORA-00031: session marked for kill
加强版的处理,在sqlplus中无法kill ,在操作系统中cmd中执行 orakill + my_oracle_sid + spid :
select 'alter system kill session ''' || s.sid || ',' || s.serial# ||''' immediate;' as killsession,'orakill my_oracle_sid ' || p.spid || ';' as orakillcmdfrom v$process p, v$session swhere p.addr = s.paddrand s.sid in (select distinct s.sidfrom gv$locked_object l, dba_objects o, gv$session swhere l.object_id = o.object_idand l.session_id = s.sid)order by s.sid;
在操作系统的cmd窗口下,多执行几次:
C:\Users\User>orakill myorclsid 8844;Kill of thread id 8844; in instance myorclsid successfully signalled.C:\Users\User>orakill myorclsid 8844;Kill of thread id 8844; in instance myorclsid successfully signalled.
终于可以kill 会话,避免重新启动数据库。