1. 程式人生 > >Oracle報錯ora-00054:resource busy and acquire with nowait specified解決方法

Oracle報錯ora-00054:resource busy and acquire with nowait specified解決方法

當某個資料庫使用者在資料庫中插入、更新、刪除一個表的資料或者增加一個表的主鍵或者表的索引時,常常會出現ORA-00054:resource busy and acquire with nowait spacified這樣的錯誤;

主要是因為有事務正在執行(或者事務已經被鎖),所以導致執行不成功。

解決方案:

1.用DBA許可權的使用者檢視資料庫都有哪些鎖

select t2.username,t2.sid,t2.serial#,t2.logon_time from v$locked_object t1,v$session t2 where t1.session_id=t2.sid order by t2.logon_time;【查詢哪些物件被鎖】

如:testuser 339 13545 2009-3-5 17:40:05
知道被鎖的使用者testuser,sid為339,serial#為13545

2.根據sid檢視具體的sql語句,如果sql不重要,可以kill掉

select sql_test from v$session a,v$sqltext_with_newlines b where

DECODE(a.sql_hash_value,o,prev_hash_value,sql_hash_value)=b.bash_value and a.sid=&sid order by piece;

查出的sql,如:begin: id :=sys.dbms_transaction.local_transaction_id;end;

3.kill該事務

alter system kill session 'sid,serial';【殺死一個程序】

eg:alter system kill session '339,13545';

4.這樣就可以執行其他的事務sql語句了

如增加表的主鍵:

alter table test add constraint PK_test primary key (test_NO);

若提示:ORA-00030:USer session ID dose not exist

eg:alter session set events 'immediate trace name flush_cache level 1';

一些ORACLE中的程序被殺掉後,狀態被置為"killed",但是鎖定的資源很長時間不釋放,有時是在沒辦法,只好重啟資料庫,現在提供一種方法解決這種問題,那就是在ORACLE中殺不掉的,在OS一級再殺;

a.首先利用下面的語句獲得程序(執行緒)號:

select spid,osuser,s.program from v$session s,v$process p where s.paddr=p.addr and s.sid=339  【339是上面的sid】

b.在OS上殺死這個程序(執行緒):

1)在unix上,用root身份執行命令:

#kill -9 spid 【a中返回的spid號】

2)在windows(unix也適用)上用orakill殺死執行緒,orakill是Oracle提供的一個可執行命令,語法是:

orakill sid thread

其中:

sid 表示要殺死的程序屬於的例項名;

thread是要殺死的執行緒號,及a中返回的spid.

eg:C:>orakill orcl 12345

kill -9 12345

================================================================================================