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:
- 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) - Session 2 requests the lock via
dbms_lock.request(1)
and has to wait - Session 3 requests the lock via
dbms_lock.request(1)
and also has to wait - 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.