http://www.cnblogs.com/loveLearning/p/3625544.html
oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT
问题如下:
sql> conn scott/tiger@vm_database
Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
Connected as scott
。。。。。。
sql> drop table student2;
drop table student2
ORA-00054: 资源正忙,但指定以 NOWAIT 方式获取资源,或者超时失效
=========================================================
解决方法如下:
=========================================================
sql> select session_id from v$locked_object;
SESSION_ID
----------
142
sql> SELECT sid,serial#,username,osuser FROM v$session where sid = 142;
SID SERIAL# USERNAME OSUSER
---------- ---------- ------------------------------ ------------------------------
142 38 SCOTT LILWEN
sql> ALTER SYSTEM KILL SESSION '142,38';
System altered
(注)
ALTER SYSTEM KILL SESSION '142,38';
会失败,返回:
ora-00031:session marked for kill(标记要终止的会话)
------------------------------------------
select session_id from v$locked_object;
SESSION_ID ---------- 1725
SELECT sid,osuser FROM v$session where sid = 1725;
SID SERIAL# ---------- ---------- USERNAME -------------------------------------------------------------------------------- OSUSER -------------------------------------------------------------------------------- 1725 5237 GS AIERXUAN
select a.spid,b.sid,b.serial#,b.username from v$process a,v$session b where a.addr=b.paddr and b.status='KILLED';
SPID ------------------------------------------------------------------------ SID SERIAL# ---------- ---------- USERNAME -------------------------------------------------------------------------------- 10545 1725 5237 GS
select spid,osuser,s.program from v$session s,v$process p where s.paddr=p.addr and s.sid=1725;
SPID ------------------------------------------------------------------------ OSUSER -------------------------------------------------------------------------------- PROGRAM -------------------------------------------------------------------------------- 10545 AIERXUAN sql Developer
使用root直接kill -9 10545直接把链接进程杀掉!!!
select * from v$lock;
select * from v$lock where block=1;
2.查询被锁的对象
select * from v$locked_object;
3.查询阻塞
查被阻塞的会话
select * from v$lock where lmode=0 and type in ('TM','TX');
查阻塞别的会话锁
select * from v$lock where lmode>0 and type in ('TM','TX');
select * from v$session where lockwait is not null;
5.查询会话之间锁等待的关系
select a.sid holdsid,b.sid waitsid,a.type,a.id1,a.id2,a.ctime from v$lock a,v$lock b
where a.id1=b.id1 and a.id2=b.id2 and a.block=1 and b.block=0;
6.查询锁等待事件
select * from v$session_wait where event='enqueue';
解决方案:
select session_id from v$locked_object; --首先得到被锁对象的session_id
SELECT sid,osuser FROM v$session where sid = session_id; --通过上面得到的session_id去取得v$session的sid和serial#,然后对该进程进行终止。
ALTER SYSTEM KILL SESSION 'sid,serial';
example:
ALTER SYSTEM KILL SESSION '13,8';
一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长时间不释放,有时实在没办法,只好重启数据库。现在提供一种方法解决这种问题,那就是在ORACLE中杀不掉的,在OS一级再杀。
1.下面的语句用来查询哪些对象被锁:
select object_name,machine,s.sid,s.serial#
from v$locked_object l,dba_objects o,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;
2.下面的语句用来杀死一个进程:
alter system kill session '24,111'; (其中24,111分别是上面查询出的sid,serial#)
【注】以上两步,可以通过Oracle的管理控制台来执行。
3.如果利用上面的命令杀死一个进程后,进程状态被置为"killed",但是锁定的资源很长时间没有被释放,那么可以在os一级再杀死相应的进程(线程),首先执行下面的语句获得进程(线程)号:
select spid,s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=24 (24是上面的sid)
4.在OS上杀死这个进程(线程):
1)在unix上,用root身份执行命令: #kill -9 12345(即第3步查询出的spid) 2)在windows(unix也适用)用orakill杀死线程,orakill是oracle提供的一个可执行命令,语法为: orakill sid thread 其中: sid:表示要杀死的进程属于的实例名 thread:是要杀掉的线程号,即第3步查询出的spid。 例:c:>orakill orcl 12345