Question: I hear that Oracle mutexes are a
faster way to serialize library cache operations, and I want to use
mutex in my Oracle 11g database. How do I enable a mutex latching
mechanism in my Oracle database?
Answer: Mutexes are objects that exist within the operating system to
provide access to shared memory structures. They are similar to
latches, which will be covered in following chapters, as they are
serialized mechanisms used to control access to shared data
structures within the Oracle SGA.
Serialization provides benefits via mutexes in that they are
required to avoid having database objects being read during
modification and to provide consistency as part of the relational
database ACID (Atomicity, Consistency, Isolation and Durability)
Mutexes can be used and defined in various ways. Each data
structure within Oracle which is under the protection of a mutex
can also have its own mutex such as a parent cursor may have its
own separate mutex as well as each child cursor can also have its
own mutex. Structures within Oracle can be protected by
multiple mutexes so that each mutex will protect a different area
of the database structure. While latches and mutexes are similar
regarding both being serialization mechanisms and providing data
protection, mutexes differ from latches in the following ways.
Mutexes are smaller and operate faster than latches because
they contain fewer instructions than those in a latch get
operation. Secondly, mutexes take up fewer memory resources and
space than latches. Mutexes also provide less chance of contention
within the database than latches do which means that mutexes
provide greater protection of data structures and flexibility than
Another key feature of mutexes is that they can be
referenced across many sessions concurrently by using shared mode.
Mutexes also function in a dual role as both a serialization item
similar to a latch and also as pin operator by preventing objects
from aging out of the Oracle memory buffers. Since both
latches and mutexes are independent mechanisms, a process within
Oracle can hold both a latch and mutex at the same time.
Oracle 10g release 2 and beyond replaced some latch mechanisms
with the mutex approach, claiming that they are faster and more
efficient than traditional locking mechanisms. To improve cursor
execution speed and hard pare time within the library cache, mutexes
replace library cache latches and library cache pins. Oracle claims
that mutexes are faster and use less CPU, which is important for
CPU-bound database where large data buffers remove I/O as a primary
source of contention.
Oracle also claims that a mutex allows for improved concurrency
over the older latch mechanism because the code path is shorter.
Beware, Oracle bug 5184776
can affect 11g databases that deploy the mutex latching, causing
excessive 'cursor pin s wait on x' wait events.
Also see my notes on
Get the Complete
Oracle SQL Tuning Information
The landmark book
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
for 30% off directly from the publisher.