2

I was wondering if Oracle guarantees that the sequence of dbms_lock.request granted is the same as the sequence in which they were requested. In my tests it always was the case, but I couldn't find any official statement in the Oracle documentation.

So let's assume we have at least three sessions:

  1. Session 1 requests the lock via dbms_lock.request(1) and is granted the lock immediately (as the lock is not yet held by any other session)
  2. Session 2 requests the lock via dbms_lock.request(1) and has to wait
  3. Session 3 requests the lock via dbms_lock.request(1) and also has to wait
  4. Now Session 1 releases the lock via dbms_lock.release(1) (or trx end or session end)

Is it guaranteed that Session 2 will now receive the lock and Session 3 still has to wait until Session 2 releases? Or might Session 3 receive the lock before Session 2?

Edit: if the answer is "yes, guaranteed", please provide link to Oracle documentation, whitepaper, V$ view or the like.

Edit 2: Database version in question is 11g and up

1
  • What version of Oracle are you using? Oct 13, 2014 at 12:54

1 Answer 1

-1

Yes!

There is a wait queue and the first requester is the first served. Beware of deadlocks...

2
  • 2
    Do you know any official reference from Oracle like documentation or whitepaper, where this is documented?
    – GWu
    Aug 13, 2014 at 13:30
  • -1 , that is not a useful answer without any references
    – miracle173
    Jun 26, 2015 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.