Professional Documents
Culture Documents
SELECT ADDR, KADDR, SID, TYPE, ID1, ID2, LMODE, BLOCK from v$lock;
SELECT
p.spid unix_spid,
s.sid sid,
p.addr,
s.paddr,
substr(s.username, 1, 10) username,
substr(s.schemaname, 1, 10) schemaname,
s.command command,
substr(s.osuser, 1, 10) osuser,
substr(s.machine, 1, 25) machine
FROM v$session s, v$process p
WHERE s.paddr=p.addr
ORDER BY p.spid;
-- explanation of locks:
Locks:
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SRX)', /* C */
6, 'Exclusive', /* X */
to_char(b.lmode)
TX: enqueu, waiting
TM: DDL on object
MR: Media Recovery
A TX lock is acquired when a transaction initiates its first change and is
held until the transaction does a COMMIT or ROLLBACK. It is used mainly as
a queuing mechanism so that other sessions can wait for the transaction to
complete.
TM Per table locks are acquired during the execution of a transaction
when referencing a table with a DML statement so that the object is
not dropped or altered during the execution of the transaction,
if and only if the dml_locks parameter is non-zero.
LOCKS: locks op user objects, zoals tables en rows
LATCH: locks op system objects, zoals shared data structures in memory en data
dictionary rows
LOCKS - shared of exclusive
LATCH - altijd exclusive
UL= user locks, geplaats door programmatuur m.b.v. bijvoorbeeld DBMS_LOCK
package
DML LOCKS: data manipulatie: table lock, row lock
DDL LOCKS: preserves de struktuur van object (geen simulane DML, DDL statements)
DML locks:
row lock (TX): voor rows (insert, update, delete)
row lock plus table lock: row lock, maar ook voorkomen DDL statements
table lock (TM): automatisch bij insert, update, delete, ter voorkoming DDL op
table
table lock: S: share lock
RS: row share
RSX: row share exlusive
RX: row exclusive
X: exclusive (ANDere tansacties kunnen alleen SELECT..)
in V$LOCK lmode column:
0, None
1, Null (NULL)
2, Row-S (SS)
3, Row-X (SX)
4, Share (S)
5, S/Row-X (SSX)
6, Exclusive (X)
Internal Implementation of Oracle Locks (Enqueue)
Oracle server uses locks to provide concurrent access to shared resources whereas
it uses latches to provide
exclusive and short-term access to memory structures inside the SGA. Latches also
prevent more than one process
to execute the same piece of code, which other process might be executing. Latch
is also a simple lock,
which provides serialize and only exclusive access to the memory area in SGA.
Oracle doesn �t use latches to
provide shared access to resources because it will increase CPU usage. Latches are
used for big memory structure
and allow operations required for locking the sub structures. Shared resources can
be tables, transactions,
redo threads, etc. Enqueue can be local or global. If it is a single instance then
enqueues will be local to
that instance. There are global enqueus also like ST enqueue, which is held before
any space transaction
can be occurred on any tablespace in RAC. ST enqueues are held only for
dictionary-managed tablespaces.
These oracle locks are generally known as Enqueue, because whenever there is a
session request for a lock
on any shared resource structure, it's lock data structure is queued to one of the
linked list attached to
that resource structure (Resource structure is discussed later).
Before proceeding further with this topic, here is little brief about Oracle
locks. Oracle locks can be applied
to compound and simple objects like tables and the cache buffer. Locks can be held
in different modes like shared,
excusive, null, sub-shared, sub-exclusive and shared sub-exclusive. Depending on
the type of object,
different modes are applied. Foe example, a compound object like a table with
rows, all above mentioned modes
could be applicable whereas for simple objects only the first three will be
applicable. These lock modes don�t
have any importance of their own but the importance is how they are being used by
the subsystem.
These lock modes (compatibility between locks) define how the session will get a
lock on that object.