Tuning Database Locks & Latches: Hamid R. Minoui
Tuning Database Locks & Latches: Hamid R. Minoui
Tuning Database Locks & Latches: Hamid R. Minoui
Latches
Hamid R. Minoui
Fritz Companies Inc.
NoCOUG May 16, 2001
Locks:
Allow serialized
access to some
resources
Requests for locks are
queued and serviced
in order
Locks:
Complex data
structure that is further
protected by latch
Protect resources
needed for a longer
time (e.g. tables)
Less efficient
Categories of latches:
Solitary latches protecting one data
structure (majority of latches)
Multiple latches protecting different parts of
a single data structure (grouped in a child-parent
relationship)
Modes of latches
Willing-to-Wait Mode
When an attempt to get a latch in a willing-towait mode fails, the process will spin and try
again
2- Sleep
Wakeup Mechanisms
Timeout
Benefit:
Cost:
Requires protecting a latch wait list data structure
by yet another latch, namely latch wait list latch
When used extensively, it can result in a
secondary latch contention
Latch Contention
V$LATCH
V$LATCHNAME
Query that shows the number of processes that had to sleep, and the
number of times they had to sleep.
V$LATCHHOLDER
V$LATCH_CHILDREN
These views contain statistics about child
latches and parent latches for multiple
latches
Child latches with the same LATCH#
have the same parents
The CHILD# column identifies the child
latch for the same parent
V$LATCH_PARENT
Has the same columns found in
V$LATCH
The union of this view and
V$LACH_CHILDREN represents all
latches
V$LATCH_MISSES
Contains statistics about missed attempts to
acquire a latch
NWFAIL_COUNT - Number of times that a
no-wait (immediate) acquisition of the latch
failed
SLEEP_COUNT - Number of times that
acquisition attempts caused sleeps
Key Latches
redo allocation
redo copy
cache buffers LRU
enqueues
row cache objects
library cache
shared pool
Sleeps Parameters
_MAX_EXPONENTIAL_SLEEP
_MAX_SLEEP_HOLDING_LATCH
A sample query
Enqueue latch
This latch is used to protect the enqueue data
structure
To tune:
Set ENQUEUE_RESOURCES to a value greater
than 10
P1
P2
P3
v$session_event &v$system_event
Locks
Allow sessions to join a queue for a
resource that is not immediately available
To achieve consistency and integrity
Performed automatically by Oracle and
manually by users
Lock Usage
Buffer locks
Lock Modes
X - Exclusive
S - Shared
N- Null
SS - Sub-shared
SX- Sub-exclusive
SSX-Shared-sub exclusive
Enqueue Conversion
The operation of changing the mode of an
enqueue lock
Example:
ENQUEUE Locks
Enqueue Resources
Enqueue Locks
A second fixed array used for enqueue
locking
Size set by _ENQUEUE_LOCK
Used by each session waiting for a lock or
holding a lock on a resource
Corresponding views
Each row in v$resource represents a locked
enqueue resource that is currently locked
All locks owned by enqueue state objects
are shown in v$enqueue_lock
All locks held by Oracle or locks and
outstanding requests for locks and latches
are recorded in v$lock
Enqueue wait
Occurs when an enqueue request or
conversion can not be granted at once
An enqueue wait event is recorded by the
blocked process in the v$session_wait view
Enqueue statistics
enqueue waits
enqueue requests
enqueue conversions
enqueue timeouts
enqueue deadlocks
Deadlock Detection
DML Locks
DML_LOCKS
V$LOCK view
Records locks currently held as well as
outstanding requests for a lock or a latch
Key columns are:
V$LOCKED_OBJECTS
Records information on all locks acquired
by all transactions including slot numbers
being used by locks
Used to obtain session information for
sessions holding DML locks on crucial
database objects
V$RESOURCE_LIMIT view
To monitor consumption of resources
Reveals number of used slots in the fixed
array of lock structures
Use it to adjust ENQUEUE_RESOURCE &
DML_LOCKS parameter settings
Resources