Question

I keep running 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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top