Understanding Oracle Locking
Understanding Oracle Locking
Locks:
Are used to protect data (blocks, segments, rows …)
Several users can share locks
Lock requests are queued up using mechanism called as
enqueue. Enqueues are lists/queues stored in Shared
Pool
A transaction ID of a transaction that locks a table or
a row is stored in the header of that table or row.
Latches:
Used to protect memory structure (SGA)
Latches cannot be shared by processes
Latch request are not queued up. (immediate or willing
to wait (spins))
Isolation levels
Lock Modes
o Exclusive (X) (other users cannot modify the
resource. They can read)
o Share (S) (other users can obtain share locks)
Lock Types
Explicit
Implicit
SELECT s.username,
DECODE(l.type,’TM’,’TABLE LOCK’, ‘TX’,’ROW LOCK’,
NULL) “LOCK LEVEL”,
o.owner, o.object_name, o.object_type
FROM v$session s, v$lock l, dba_objects o
WHERE s.sid = l.sid
AND o.object_id = l.id1
AND s.username IS NOT NULL;
V$DBA_WAITERS
DBA_BLOCKERS
SELECT s.username
FROM dba_blockers db, v$session s
WHERE db.holding_session = s.sid;
Enqueue Statistics
select *
from v$sgastat
where name like ‘%enqueue%’
Enqueue wait
Enqueue requests
Enqueue conversions (e.g. upgrading locks)
Enqueue timeouts
Enqueue deadlocks
Initialization Parameters