Internal Locks
Internal Locks
Professional
Internals of Oracle
Database Locks
Riyaj Shamsudeen
In this article, Riyaj Shamsudeen explains various data Holding a latch, starting from the bucket, the hash chain
structures associated with locks and provides a cursory is searched for the specific resource.
overview of some locking-related initialization parameters. These arrays are fixed arrays and are statically
allocated during the startup and don’t grow dynamically.
L
OCKS (also known as “enqueues”) are used to The length of the resources array is determined by the
control the access to resources. Example of resources enqueue_resources parameter. The length of the locks
include rows, tables, redo threads, media recovery array is determined by the _enqueue_locks parameter.
threads, and so forth. The number of hash buckets is determined by the
_enqueue_hash parameter. The number of latches
Internal operation of locks protecting these hash buckets is determined by the
Before we dive in to the details of the internal locking _enqueue_hash_chain_latches parameter.
behavior, it’s important to understand the terminology
that’s used in this article. x$ tables
These fixed arrays are externalized as x$ tables. The
What’s a resource identifier? resources array is externalized as x$ksqrs fixed table, and
When a session needs access to a particular resource, it the locks array is externalized as x$ksqeq fixed table.
requests a lock on that resource in a specific mode. The
mode requested depends upon the intended operation. Tracking the resources
Resources are identified with the format {<two char When a session requests a lock on a resource, a unique
resource type >, id1, id2}. resource identifier is generated of the format (type, id1,
This two-character type identifies the type of the id2). This resource identifier is hashed in to the enqueues
resource for which a lock has been requested. For hash table to determine the status of the resource.
example, TX identifies a transaction lock and is used Holding one of the enqueue_hash_chain latches, this hash
for row-level locking. Id1 and id2 identify the specific chain is searched for the specific resource (see Figure 1).
resource within that resource type.
Another example is MR locks. MR is the resource type
for the Media Recovery, and DBW0 holds locks on every
datafile on this resource. Id1 is the file#.
A combination of the lock type, id1, and id2 is unique,
and each resource will have a unique resource identifier.
Enqueue dumps then you might be able to use this information to pinpoint
You can dump the enqueues with the following command: the problem area and tune it. For example, to find the
how should it break?
AD
A GE
LF
P
HA
Disclaimer
Oracle resource locking and management is a complex
subject. Due to space constraints, some details have been
omitted. Additionally, I can only speak to the relevance of Sign up now for Pinnacle’s FREE eNewsletters!
the information in this article as it relates to the Sun, Get tips, tutorials, and news from gurus in the field
Sequent, and HP platforms. However, other UNIX delivered straight to your Inbox.
platforms can probably be expected to provide similar
http://www.FREEeNewsletters.com
services and functionality as outlined here. The Windows
NT platform might introduce other problems or subtleties XML • Web Development • SQL Server • Visual Basic • MS Access • Oracle • Visual C++ •
Delphi • FoxPro • XML • Web Development • SQL Server • Visual Basic • MS Access • Oracle
not explored in this article. ▲
Oracle Professional (ISSN 1525-1756) is published monthly (12 times Oracle, Oracle CASE Dictionary, and Oracle CASE Designer are or implied, respecting the contents of this publication, including
per year) by Pinnacle Publishing, Inc., 1000 Holcomb Woods Pkwy, registered trademarks and Oracle 7, Cooperative Development but not limited to implied warranties for the publication,
Bldg 200, Suite 280, Roswell, GA 30076. Environment, Oracle Forms, PL/SQL, Oracle Forms Generator, Oracle performance, quality, merchantability, or fitness for any particular
Reports Generator, Oracle CASE, Oracle Reports, Oracle Graphics, purpose. Pinnacle Publishing, Inc., shall not be liable to the purchaser
POSTMASTER: Send address changes to Oracle Professional, PO Box and Oracle Access are trademarks of Oracle Corporation. Other or any other person or entity with respect to any liability, loss, or
769389, Roswell, GA 30076-8220. brand and product names are trademarks or registered trademarks damage caused or alleged to be caused directly or indirectly by
of their respective holders. this publication. Articles published in Oracle Professional reflect
Copyright © 2001 by Pinnacle Publishing, Inc. All rights reserved. No the views of their authors; they may or may not reflect the view
part of this periodical may be used or reproduced in any fashion This publication is intended as a general guide. It covers a highly of Pinnacle Publishing, Inc. Inclusion of advertising inserts does
whatsoever (except in the case of brief quotations embodied in technical and complex subject and should not be used for making not constitute an endorsement by Pinnacle Publishing, Inc. or
critical articles and reviews) without the prior written consent of decisions concerning specific products or applications. This Oracle Professional.
Pinnacle Publishing, Inc. Printed in the United States of America. publication is sold as is, without warranty of any kind, either express
The Source Code portion of the Oracle Professional Web site is available to paid subscribers only.
Log in for access to all current and archive content and source code. For access to this issue only,
User name iodine
go to www.oracleprofessionalnewsletter.com, click on “Source Code,” select the file(s) you want
from this issue, and enter the User name and Password at right when prompted. Password jealous