Oracle Database - Latches (System Lock)

About

Latches are simple, low-level system lock (serialization mechanisms) that coordinate multi-user access (concurrency) to shared data structures, objects, and files.

Latches protect shared memory resources from corruption when accessed by multiple processes. Specifically, latches protect data structures from the following situations:

  • Concurrent modification by multiple sessions
  • Being read by one session while being modified by another session
  • Deallocation (aging out) of memory while being accessed

Typically, a single latch protects multiple objects in the SGA.

The implementation of latches is operating system-dependent, especially in respect to whether and how long a process waits for a latch.

Articles Related

Example

Background processes such as DBWn and LGWR allocate memory from the shared pool to create data structures. To allocate this memory, these processes use a shared pool latch that serializes access to prevent two processes from trying to inspect or modify the shared pool simultaneously. After the memory is allocated, other processes may need to access shared pool areas such as the library cache, which is required for parsing. In this case, processes latch only the library cache, not the entire shared pool.

Concurrency

An increase in latching means a decrease in concurrency. For example, excessive hard parse operations create contention for the library cache latch.

Latches are a type of lightweight lock. Locks are serialization devices. Serialization devices inhibit concurrency.

To build applications that have the potential to scale, ones that can service 1 user as well as 1,000 or 10,000 users, the less latching we incur in our approaches, the better off will be.

You have to choose always an approach that takes longer to run on the wall clock but that uses 10 percent of the latches. We know that the approach that uses fewer latches will scale substantially better than the approach that uses more latches.

Queuing

Unlike enqueue latches such as row locks, latches do not permit sessions to queue. When a latch becomes available, the first session to request the latch obtains exclusive access to it.

  • Latch spinning occurs when a process repeatedly requests a latch in a loop, whereas
  • Latch sleeping occurs when a process releases the CPU before renewing the latch request.

Typically, an Oracle process acquires a latch for an extremely short time while manipulating or looking at a data structure. For example, while processing a salary update of a single employee, the database may obtain and release thousands of latches.

Data Dictionary

The V$LATCH view contains detailed latch usage statistics for each latch, including the number of times each latch was requested and waited for.

  • Bookmark "Oracle Database - Latches (System Lock)" at del.icio.us
  • Bookmark "Oracle Database - Latches (System Lock)" at Digg
  • Bookmark "Oracle Database - Latches (System Lock)" at Ask
  • Bookmark "Oracle Database - Latches (System Lock)" at Google
  • Bookmark "Oracle Database - Latches (System Lock)" at StumbleUpon
  • Bookmark "Oracle Database - Latches (System Lock)" at Technorati
  • Bookmark "Oracle Database - Latches (System Lock)" at Live Bookmarks
  • Bookmark "Oracle Database - Latches (System Lock)" at Yahoo! Myweb
  • Bookmark "Oracle Database - Latches (System Lock)" at Facebook
  • Bookmark "Oracle Database - Latches (System Lock)" at Yahoo! Bookmarks
  • Bookmark "Oracle Database - Latches (System Lock)" at Twitter
  • Bookmark "Oracle Database - Latches (System Lock)" at myAOL
 
database/oracle/latches.txt · Last modified: 2011/01/12 16:21 by gerardnico