Friday, May 13, 2011

V$LOCKED_OBJECT Oracle dynamic view

How to use the V$LOCKED_OBJECT Oracle view

The Oracle database makes very frequent use of locks, and for good reason; without them, your data integrity would be compromised. So, it’s good to have a knowledge about how locking works so that you can design your applications with it in mind.

If you take a look at the v$locked_object dynamic view, you will see that there are many columns. The ones we are interested in at the moment are the SESSION_ID,OBJECT_ID and LOCKED_MODE columns. These columns show you that object withOBJECT_ID has been locked the user with a SESSION_ID at a particular lock level,LOCKED_MODE.

When someone comes along to try and take out a lock on an object, Oracle compares the lock mode requested with the lock mode that is currently on the object. If the requested lock mode is lower than the current lock mode, then the locks are compatible and the request will proceed.

However, if the lock mode is equal to or higher than the current lock mode, you will have to wait until it is released. You may experience the following error:

ORA-00054: resource busy and acquire with NOWAIT specified

No comments:

Post a Comment