开发者

Long queue times for oracle row locks

开发者 https://www.devze.com 2022-12-22 20:05 出处:网络
I keep r开发者_JAVA百科unning into \"enq: TX - row lock contention\", when I run the Sql command below in a oracle 9 DB.

I keep r开发者_JAVA百科unning into "enq: TX - row lock contention", when I run the Sql command below in a oracle 9 DB. The table mytable is a small table, with less than 300 lines.

UPDATE MYTABLE
SET     col1 = col1 + :B3 ,
        col2    = SYSDATE
WHERE   :B2            = col3
    AND :B1        = col4

I run 10 threads at the same time, and some wait as long as 10 seconds to get a chance to update. I know I will face this deadlock issues, but the problem for me is that they should be able to be much faster, since the table is small, so updating it would be fast.

edit:I cannot alter this code, it is inside a third party application. I can only tweak the DB.

what can I do to improve the speed of the rowlock queue? How can I improve this waiting time so my threads run faster?


If you don't want to be blocked don't try to update blindly. Perform a SELECT FOR UPDATE NOWAIT first. If you raise an exception (ORA-00054) this means that another session is currently working with that row. In that case, depending upon your requirement, you could try to update another row (are you trying to build a queue/dequeue process?), wait (dbms_lock.sleep) or return an error message to the calling app.

You will never face a deadlock if you lock the row with FOR UPDATE NOWAIT first.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号