2008年4月2日 星期三

oracle錯誤訊息 ora-00054

ora-00054

這是我同事在進行某一oracle 10g database的資料更新時,
所遇到的錯誤訊息代碼!
根據查詢到的一些技術文件,說明這是當你在進行資料庫操作更新時,
剛好你要更新的table有其他人在使用,或進行其他的作業。
造成資料庫發生locked的情形!

還好有篇文件,提到如何解決的方法!
http://www.lslnet.com/linux/edosc/42/linux-42294950.htm


+===================================================+
補充:
http://vanhazar.blogspot.com/search/label/Oracle
+===================================================+

ORACLE Lane locks of the following models :
0:none
1:null air
2:Row-S Bank share (RS) : Sharing the table lock sub share
3:Row-X trip to monopolize (RX) : for the changes, sub exclusive
4:Share shared locks (S) : stop other DML operation, share
5:S/Row-X sharing firms to monopolize (SRX) : stop other operations, exclusive share/sub
6:exclusive exclusive (X) : the use of an independent visit, exclusive

The higher the level the greater the number of locks, the more influence the operation.

Level 1 : Select locks, and sometimes there will v$locked_object.

Level 2 : Select for update locks, Lock For Update, Lock Row Share
When the select for update update for the use of dialogue to open up a series of sub-Vernier, all data transportation will concentrate on the return trip at the level (Row-X) exclusive locking, data about these other firms can object, can not update, select for update or delete operation.

Level 3 locks : Insert, Update, Delete, Exclusive Lock Row
Not commit the same insert a record will not, because after a three locks will have been waiting for a three locks, we must continue to be a work release.

Level 4 : Create Index locks, Lock Share
Locked_mode for 2,3,4 not affect DML (insert, delete, update, select) operation, but DDL (alter, drop, etc.) will operate suggested ora-00054 wrong.
00054, 00000, the "resource busy and acquire with NOWAIT specified"
4003rd *Cause : Resource interested is busy.
4003rd *Action : Retry if necessary.

Level 5 Exclusive locks : Lock Share Row
Specifically there are bound outside Key update / delete. . . It may be four to five locks.

Level 6 : Alter table level locks, Drop table, Drop Index, Truncate table, Exclusive Lock

DBA role to check the current database locks can be used as follows : SQL

Per owner for PGA
PGA object_name for a16
Select b.owner, b.object_name, l.session_id, l.locked_mode
From v$locked_object l, b dba_objects
Where b.object_id=l.object_id
/

Select t2.username, t2.sid, t2.serial#, t2.logon_time
From v$locked_object t1, t2 v$session
Where t1.session_id=t2.sid order by t2.logon_time
/

If there is a long series, is not likely to release the lock. We can not release below-normal SQL kill long locks :

Alter system kill session 'sid, serial#';

If there is a lock, a DML operation may wait for a long time no response.

When you are directly connected to the database, do not use OS 9 system orders $kill process_num $kill process_num or to terminate user connectivity, as a user process may have more than one lock, lock kill OS process and the issue can not be completely removed.

原文寫得有點亂!
不過,藍色文字的操作語法,可以用強制的手法,把被locked的情形解除!
但,這不是常規作法,正常來說,應用程式寫得好的話,
應該要能在正常把作業進行完畢後,解除鎖定才是。
若程式給的資料庫更新或新增作業做完後,還會留住session和鎖住資料。
那就是程式寫得有問題了!

原文的譯文:
ORACLE裏鎖有以下幾種模式:
0:none
1:null 空
2:Row-S 行共用(RS):共用表鎖,sub share
3:Row-X 行獨佔(RX):用於行的修改,sub exclusive
4:Share 共用鎖(S):阻止其他DML操作,share
5:S/Row-X 共用行獨佔(SRX):阻止其他事務操作,share/sub exclusive
6:exclusive 獨佔(X):獨立訪問使用,exclusive

數字越大鎖級別越高, 影響的操作越多。

1級鎖有:Select,有時會在v$locked_object出現。
2級鎖有:Select for update,Lock For Update,Lock Row Share
select for update當對話使用for update子串打開一個游標時,所有返回集中的資料行都將處於行級(Row-X)獨佔式鎖定,其他物件只能查詢這些資料行,不能進行update、delete或select for update操作。
3級鎖有:Insert, Update, Delete, Lock Row Exclusive
沒有commit之前插入同樣的一條記錄會沒有反應, 因為後一個3的鎖會一直等待上一個3的鎖, 我們必須釋放掉上一個才能繼續工作。
4級鎖有:Create Index, Lock Share
locked_mode為2,3,4不影響DML(insert,delete,update,select)操作, 但DDL(alter,drop等)操作會提示ora-00054錯誤。
00054, 00000, "resource busy and acquire with NOWAIT specified"
// *Cause: Resource interested is busy.
// *Action: Retry if necessary.
5級鎖有:Lock Share Row Exclusive
具體來講有主外鍵約束時update / delete ... ; 可能會產生4,5的鎖。
6級鎖有:Alter table, Drop table, Drop Index, Truncate table, Lock Exclusive

以DBA角色, 查看當前資料庫裏鎖的情況可以用如下SQL語句:


col owner for a12
col object_name for a16
select b.owner,b.object_name,l.session_id,l.locked_mode
from v$locked_object l, dba_objects b
where b.object_id=l.object_id

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



如果有長期出現的一列,可能是沒有釋放的鎖。我們可以用下面SQL語句殺掉長期沒有釋放非正常的鎖:

alter system kill session 'sid,serial#';

如果出現了鎖的問題, 某個DML操作可能等待很久沒有反應。

當你採用的是直接連接資料庫的方式,也不要用OS系統命令 $kill process_num 或者 $kill -9 process_num來終止用戶連接,因為一個用戶進程可能產生一個以上的鎖, 殺OS進程並不能徹底清除鎖的問題。

沒有留言:

搜尋此網誌

本站大事記

這個部落格(網站)內容以分享LINUX和延伸出的技術文章為主!
特別是為了工作和進修需要,搜集了不少網站連結。
希望對來這裡觀文的朋友們,有提供一些有用的資訊或文章。
但這裡的文章中,也包含個人的心情扎記和隨興言談……
若是當中沒有對上你的口味,請多包涵!

原「琳娜絲與希斯寇的邂逅」,改名為「愛上琳娜絲」!

原「琳娜絲與希斯寇的邂逅」,改名為「愛上琳娜絲」!
--原序文--
就是當LINUX遇上CISCO啦!他們的結合還能作什麼事…不就是讓這個世界的網路,串…串起來啊…不然你們那能上這網站看部落格!