Oracle TM and TX locks

Oracle has two kinds of DML locks. A TM lock is taken on a table. It shows who is modifying the table and prevents conflicts with DDL. A TX lock is created once per transaction, and each row the transaction modifies gets a marker in the block that points to this transaction. When another session tries to modify the same row, it sees that marker and waits for that TX lock to be released (by commit or rollback).

Key specs

ItemValue
Table lockTM lock, modes RS(2), RX(3), S(4), SRX(5), X(6)
TM mode taken by DMLINSERT, UPDATE, DELETE, MERGE, SELECT ... FOR UPDATE: RX(3)
Row lockTX lock (one per transaction) + ITL slot in the block header + lock byte in the row header
Plain SELECTTakes no lock. Reads the read-consistent version built from undo
Lock escalationNone
ITL slotsStart at INITRANS (table default 1, index default 2) and grow from the free space in the block
Wait optionsFOR UPDATE, FOR UPDATE NOWAIT, FOR UPDATE WAIT n, FOR UPDATE SKIP LOCKED
Typical wait eventsenq: TX - row lock contention, enq: TX - allocate ITL entry, enq: TM - contention
DeadlockDetected automatically, one statement is rolled back with ORA-00060

TM lock modes

ModeNameTaken byBlocks
2RS (Row Share)LOCK TABLE ... IN ROW SHARE MODEX
3RX (Row Exclusive)DML, SELECT ... FOR UPDATES, SRX, X
4S (Share)LOCK TABLE ... IN SHARE MODE, the child table when the parent of an unindexed foreign key is modifiedRX, SRX, X
5SRX (Share Row Exclusive)LOCK TABLE ... IN SHARE ROW EXCLUSIVE MODERX, S, SRX, X
6X (Exclusive)LOCK TABLE ... IN EXCLUSIVE MODE, many DDL statementsAll modes

RS corresponds to intent share (IS), RX to intent exclusive (IX), and SRX to SIX. Between DML statements, RX and RX are compatible, so different rows of the same table can be modified at the same time.

How it works

Figure. How a row lock is recorded in the block

block-beta
  columns 6
  h["Block header"]:2 i1["ITL 1<br/>Transaction T1, undo address"]:2 i2["ITL 2<br/>Empty"]:2
  r1["Row A<br/>Lock byte = 1"]:3 r2["Row B<br/>Lock byte = 0"]:3
  w["T2 tries to modify Row A → sees T1 in ITL 1 and waits on T1's TX lock"]:6
  class h meta
  class i1 hot
  class i2 free
  class r1 hot
  class r2 data
  class w warn

Diagram explanation: When T1 modifies Row A, it writes its transaction number and undo address into an empty ITL slot (ITL 1) in the block header, and writes that slot number (1) into the lock byte of Row A. When T2 tries to modify the same row, it sees in the ITL that the lock byte points to that T1 is still active, and waits for T1's TX lock (enq: TX - row lock contention). A row whose lock byte is 0, like Row B, can be modified immediately.

Why there is no escalation. Row locks are recorded inside the data block, so lock manager memory does not grow no matter how many rows you lock. There is no need to promote row locks to a table lock as SQL Server does. Instead, the lock marker can remain in the block after commit, and the next session that reads that block may clean it up (delayed block cleanout).

ITL waits. If the number of transactions modifying rows of one block at the same time exceeds the number of ITL slots, and the block has no free space to add slots, sessions wait on enq: TX - allocate ITL entry even though they touch different rows. For tables with heavy concurrent updates, increase INITRANS and PCTFREE.

Foreign key indexes. If the foreign key column of a child table has no index, deleting a parent row or changing its primary key briefly places an S(4)-type TM lock on the whole child table, which conflicts with DML on the child table. As a rule, create an index on foreign key columns.

Settings and checks

-- Who is blocking whom
SELECT sid, serial#, username, event, blocking_session, seconds_in_wait, sql_id
FROM v$session WHERE blocking_session IS NOT NULL;

-- Lock list: for TM, id1 is the object number; for TX, it identifies the transaction
SELECT l.sid, l.type, l.id1, l.id2, l.lmode, l.request, l.block, o.object_name
FROM v$lock l LEFT JOIN dba_objects o ON l.type = 'TM' AND o.object_id = l.id1
WHERE l.type IN ('TM', 'TX');

SELECT * FROM dba_blockers;
SELECT * FROM dba_waiters;

-- Wait at most 3 seconds, and raise ORA-30006 if the lock cannot be taken
SELECT * FROM orders WHERE id = 42 FOR UPDATE WAIT 3;

-- Work queue that skips locked rows and takes the rest
SELECT id FROM jobs WHERE status = 'READY' FOR UPDATE SKIP LOCKED;

ALTER TABLE orders INITRANS 8;      -- applies from newly written blocks onward

Comparison with other DBMSs

OracleSQL ServerInnoDBPostgreSQL
Where row locks are recordedITL and row header in the blockLock manager memoryPer-page lock bitmap (memory)Row header (tuple header)
Lock escalationNoneYes (about 5,000 locks)NoneNone
Locking gaps between rowsNoneKey-range locks (Serializable)Gap locks, next-key locksNone (SSI uses predicate locks)
Plain SELECTNo lockS lock by default (none with RCSI)No lockNo lock

In the articles

NOTE The default INITRANS and the range of SKIP LOCKED support can vary by version.

Related pages