Question:
How does row level locking work
in Oracle?
Answer: When a transaction begins it opens
an exclusive lock on a resource. The name of the lock depends
on the transaction ID for the freshly started transaction.
This resource then, if requested by another transaction, will serve
as a wait point until the transaction holding the lock performs
either a commit or a rollback.
For example, assume we have two transactions, each requesting the
same resource. The first transaction accesses the resource and
generates a lock. The second transaction will detect that the
resource it is trying to access is locked by the first transaction,
and would then request a lock in exclusive mode, on the resource.
When the first transaction commits or performs a rollback, it will
release the exclusive lock on the resource. When the lock is
released, the second transaction gains an exclusive lock and
proceeds.
This is a step by step look at the row locking mechanism:
- Transaction begins either implicitly via any DML, or
explicitly via set transaction.
- A slot is allocated in the rollback segment header.
This slot is allocated either via a round robin selection
process, or specified by the set transaction use rollback
segment ... statement.
- Blocks to be changed are identifired using the execution
plan, utilizing whatever access paths are specified there.
- The transaction looks for an empty slot on the Interested
Transaction List (ITL). If there are none available, one
will be allocated from free space in the block if it is
available. If that fails, the transaction will wait on a
TX enqueue in mode 4. When the ITL slot has been
allocated, it will point to the rollback segment header that was
previously reserved by the transaction.
- When the ITL slot is allocated in the block, specific rows
are marked as locked in the row directory. The lock byte
will be set to point to the ITL slot held by the transaction.
This is the mechanism that acutally maintains the row-level
locks in Oracle. Once the lock byte is set, the row can be
operated on. If changes to the block are made, the before
images are recorded in the rollback segment reserved by the
transaction.
- When a commit or rollback is performed, the lock is
released. When a commit occurs, in order to release the
lock, the rollback segment header slot must be marked as
committed. Cleanup of the block itself is usually delayed
until a later time.
|
|
|
|
Guarantee your Success!
Oracle is the
world's most complex, robust and flexible database, considered
impossible to master without a mentor.
That's why all BC
Oracle trainers are working professionals, experts in Oracle who
share their tips and secrets. |
|
| |
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright ? 1996 - 2012
All rights reserved.
Oracle ?
is the registered trademark of Oracle Corporation.
|
|