Thursday, August 1, 2013

What is a Latch


Oracle SGA consists of numerous data structures such as Buffer Cache, Shared pool, Library cache, Dictionary cache, redo log buffer etc. Many oracle processes need to access these SGA data structures concurrently. Though these SGA components are shared, only one process must be able to modify it at any particular point in time. Oracle achieves this by protecting the SGA data structures with latches.

Latches do not allow multiple processes to inspect the protected data structures simultaneously. They provide only exclusive access. A latch is a kind of lock that can be very quickly acquired and freed.

When do Oracle Process obtain a latch?

Oracle sessions need to update or read from the SGA for almost all operations. For instance,

  • When a session performs a physical read, it must modify a free block in the buffer cache and adjust the Buffer Cache LRU Chain.
  • When a session reads a block from the SGA, it will modify the LRU chain.
  • When a new SQL statement is parsed, it will be added to the library cache.
  • As changes are made to blocks, entries are placed in the redo buffer.
  • The DBWr and redo log writer writes buffers from buffer to disks.

Latches prevent any of these operations from colliding and possible corrupting the same area of SGA.

A process acquires a latch when working with a structure in the SGA. It continues to hold the latch for the period of time it works with the structure. The latch is dropped when the process is finished with the structure. Each latch protects a different set of data, identified by the name of the latch.

Latches are held for short periods of time and provide a mechanism for cleanup in case a holder dies abnormally while holding it. This cleaning is done using the services of PMON.

Latches Vs Locks

Request Queuing: Request for locks are queued and serviced in order, whereas there is no request queuing in latches the process requests for latch until it succeeds. Latches are serviced in random.

Management: Locks management is complex because of their support for queuing and concurrency. Latch management is simple, essentially just a single location in memory representing the state of a latch.

Because latches are very efficient Oracle uses latch to protect the data structures  that are expected to be accessed briefly and intermittently.


Segment Availability during Shrink

The segment shrink is done online. During shrink operation, the conventional DML operations can coexist but parallel DMLs cannot.

During segment shrink, data will be moved as part of the compaction phase.
During compaction locks will be held on individual rows and/or blocks containing the data. This will cause the concurrent DMLs like updates and deletes to serialize on the locks. The compaction will be done in units of smaller transactions, so the availability of the object will not be impacted significantly.

However during certain phases of segment shrink (when the HWM is adjusted), the segment will have to be locked in exclusive mode.

This phase is for a very short duration and should impact the availability of the object less significantly.

NOTE: Shrinking space of a large segment can take a lot of time, e.g. tens of hours, and can generate lots of redo. Therefore, it is not advised to interrupt a shrink statement to prevent a possibly massive rollback.


Thursday, February 10, 2011

RMAN: Archivelogs lost

Problem: I have lost some of the archivelog files without taking backup. If I run the rman to backup available archive logs, it throws error that the archivelog_seq# is not available.

Solution: run the following command.

RMAN> change archivelog all validate;

Now you run the backup archivelog command. RMAN will backup the available archivelogs successfully.




Oracle Database Administration. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com