Oracle Locks
Oracle Locks
Locks are mechanisms that prevent destructive interaction between transactions accessing
the same resource.
General Object Type Affected By Locks:
1) User objects, such as tables and rows (structures and data)
2) System objects not visible to users, such as shared data structures in the memory and
data dictionary rows
Oracle Latches
Latches are low-level serialization mechanisms to protect shared data structures in the
system global area (SGA). Latches protect the oracle lists like list of users currently
accessing the database and protect the data structures describing the blocks in the buffer
cache. A server or background process acquires a latch for a very short time while
manipulating or looking at one of these structures. The implementation of latches is
operating system dependent, particularly in regard to whether and how long a process
will wait for a latch.
Deadlocks
Oracle automatically detects deadlock situations and resolves them by rolling back one of
the statements involved in the deadlock. This releases one set of the conflicting row
locks. A corresponding message also is returned to the transaction that undergoes the
rollback.
Deadlocks often occur when transactions override Oracle default locking. Oracle itself
does no lock escalation and does not use read locks for queries and does not use pagelevel locking, deadlocks rarely occur in Oracle.
Deadlocks can usually be avoided if transactions accessing the same tables lock those
tables in the same order, either through implicit or explicit locks and when a sequence of
locks for one transaction are required, you should consider acquiring the most exclusive
(least compatible) lock first.
Always close explicit cursors when finished to free locks.