what is latch?

posted Jul 15, 2011, 8:53 AM by Sachchida Ojha

Latches are serialization mechanisms that protect areas of Oracle’s shared memory (the SGA). In simple terms, latches prevent two processes from simultaneously updating — and possibly corrupting — the same area of the SGA. A latch is a type  of a lock that can be very quickly acquired and freed. Latches are typically used to prevent more than one process from executing the same  piece of  code at  a given time.

Oracle sessions need to update or read from the SGA for almost all database operations. For instance:
  1.   When a session reads a block from disk, it must modify a free block in the buffer cache and adjust the buffer cache LRU chain
  2.   When a session reads a block from the SGA, it will modify the LRU chain.
  3.   When a new SQL statement is parsed, it will be added to the library cache within the SGA.
  4.   As modifications are made to blocks, entries are placed in the redo buffer.
  5.   The database writer periodically writes buffers from the cache to disk (and must update their status from “dirty” to “clean”).
  6.   The redo log writer writes entries from the redo buffer to the redo logs.
Latches prevent any of these operations from colliding and possibly corrupting the SGA.

Comments