Lock Modes

Locks are applied to both compound and simple objects. The classic example of a compound object and its component parts is a table and its rows. A cache buffer is an example of a simple object. Simple objects may only be locked in the following modes:

Exclusive

If a session needs to modify a simple object, then an exclusive lock is required on the resource to prevent any concurrent access.

Shared

If a session needs to inspect a simple object, then a shared lock on the resource is sufficient to ensure that the data structure will not be modified by another session, while allowing concurrent shared access.

Null

If a session has some information cached about an object, then a null mode lock may be held as a placeholder, even when the resource is not actively being used. A null mode lock does not inhibit any concurrent access, but if the resource is invalidated, the null mode lock acts as a trigger for the session to invalidate its private cached information. There is an important difference between holding a null mode lock, and not holding a lock at all.

In addition to the modes above, compound objects may also be locked in the following modes:

Sub-shared

If a session needs shared access to part of a compound object, then a shared lock on the entire compound resource would be unduly restrictive, because it would prevent exclusive access to other parts of the compound resource. In such cases, a sub-shared lock is used instead.

Sub-exclusive

If a session needs exclusive access to part of a compound resource, then a sub-exclusive lock is sufficiently restrictive.

Shared-sub-exclusive

This lock mode is used when a session needs exclusive access to part of a compound resource and shared access to the entire compound resource at the same time.

These lock modes apply both to local locks and to the instance locks that are used between parallel server instances. However, different terminology is used for instance locks. Table 4.1 shows the corresponding lock mode names together with the symbolic and numeric representations used in dumps and wait parameter values.

Table 4-1. Lock Modes

Local Lock Modes

  

Instance Lock Modes

  

Name

Symbol

Number

Name

Symbol

Number

   

(No lock)

NLCK

0

   

Null

N

1

Null

NL

0

Sub-Shared

SS

2

Concurrent Read

CR

1

Sub-Exclusive

SX

3

Concurrent Write

CW

2

Shared

S

4

Protected Read

PR

3

Shared-Sub-Exclusive

SSX

5

Protected Write

PW

4

Exclusive

X

6

Exclusive

EX

5

It is important to understand which lock modes are compatible with one another. Table 4.2 shows the complete lock mode compatibility matrix.

Table 4-2. Lock Mode Compatibility

 

N

SS

SX

S

SSX

X

N

Yes

Yes

Yes

Yes

Yes

Yes

SS

Yes

Yes

Yes

Yes

Yes

No

SX

Yes

Yes

Yes

No

No

No

S

Yes

Yes

No

Yes

No

No

SSX

Yes

Yes

No

No

No

No

X

Yes

No

No

No

No

No

Get Oracle Internals: An Introduction now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.