FAQ: Detecting and Resolving Locking Conflicts and Ora-00060 errors [ID 15476.1]
In this Document
Purpose
Last Review Date
Instructions for the Reader
Troubleshooting Details
How does Oracle handle locking?
How to find the resource definitions?
Which lock modes are required for which table action?
How compatibility of locks works
How to detect locking situations?
Which views can be used to detect locking problems?
Which tools are there to diagnostic locking issues?
How to resolve locking situations?
Deadlock Situations
Unusual locking problems
How to use dbms_lock?
References
Applies to:
Oracle Server - Enterprise Edition - Version: 7.1.1.0 to 11.2.0.3 - Release: 7.1.1 to 11.2Oracle Server - Personal Edition - Version: 7.1.4.0 to 11.2.0.3 [Release: 7.1.4 to 11.2]
Oracle Server - Standard Edition - Version: 7.0.16.0 to 11.2.0.3 [Release: 7.0 to 11.2]
Information in this document applies to any platform.
Checked for relevance on 8-16-2010.
Purpose
This document covers frequently asked questions about detecting and resolving locking conflicts.Last Review Date
November 2, 2011Instructions for the Reader
Troubleshooting Details
How does Oracle handle locking?
Oracle use enqueues as locking mechanism for managing access to shared resources. A shared resource can be a table definition, a transaction or any type of structure that represent something sharable between sessions Each type of actions performed by Oracle sessions on those shared resources will require a certain type of lock or lock mode (e.g. a 'select on a table' action will require that the executing session has a shared lock on the resource 'table definition' of the selected table). When conflicting actions are occuring, Oracle will serialize the processing by putting a number of sessions in waiting mode until the work of the blocking session has been completed.Each enqueue represent a sharable resource. Sessions may be acquiring, converting and releasing locks on resources in function of the work they need to perform.
- Releasing locks are performed by the sessions when they issue a commit or a DDL statement (i.e. implicit commit), or by PMON if the sessions have been killed. (Remember this only pertains to row locks. Only TX, TM, and DX enqueues are held until commit. Other locks such as RT enqueues will be held until the instance is shutdown.)
- Conversion is the process of changing a lock from the mode we currently hold to a different mode.
We are allowed to convert a lock if the mode we require, is a subset of the mode we hold or is compatible with the modes already held by other sessions. Otherwise, we wait on the converters queue of the resource. - Acquiring a lock is the process of getting a lock on a resource on which we currently do not have a lock.
We are allowed to acquire a lock, if there are no converters or waiters ahead of us and the mode we require is compatible with the modes already held by others. Otherwise, we wait on the waiters queue of the resource.
When a session has a lock on a resource, then it stands in the owner queue of the resource. When a lock is released or converted, the converters and waiters are re-checked to see if they can be acquired. The converters are processed first, then the waiters.
Row locking in Oracle is based on the TX enqueues and is known as transactional locking. When two or more sessions are changing data on one row of a table (DML statements on the same record), the first session will lock the row by putting his transaction reference in the block containing the row header. The other sessions will look at this lock information and will wait on the transaction (i.e. the TX enqueue of the blocking session) of the first session before proceeding. When the first session performs a commit, the TX resource will be released and the waiters will start their own locking. The waiting sessions are thus waiting on an exclusive TX resource, but their TM resources they are holding give the objects they are in fact waiting on.
If a lock has not been acquired or converted, a deadlock check is made by the waiting session after a timeout. For example, following situation generates a deadlock:
- User A gets an S lock on resource 1
- User B gets an S lock on resource 2
- User A request an X lock on resource 2 and waits
- User B requests an X lock on resource 1 and waits
A is waiting for B to release resource 2, which is waiting for A to release resource 1
A is indirectly waiting for A. This is a deadlock, generating a tracefile in the user_dump_dest and and ORA-60 in the detecting session which results in the session being killed.
How to find the resource definitions?
Each resource is represented by an enqueue. An enqueue is identified by a unique name, also known as the resource name. The name has the form. . Type has two characters and represent a resource type (e.g. TM for the table definition type). ID1 and ID2 are positive numbers and identify the resource fully (e.g. ID1 is the object_id of the table if the resource type is "TM"). ID1 and ID2 have different meanings depending on the type of enqueue.The description of most enqueue/resource types can be found in the appendixes of the Oracle Reference Guide.
See also:
The most commonly known resource types are the TM, TX and UL resources:
- The TM resource, known as the DML enqueue, is acquired during the execution of a statement when referencing a table so that the table is not dropped or altered during the execution of it.
- The TX resource, known as the transaction enqueue, is acquired exclusive when a transaction initiates its first change and is held until the transaction does a COMMIT or ROLLBACK. Row locking is based on TX enqueues. PMON will mark a transaction status as dead in the undo segment header. At that point the TX enqueue associated with that transaction is also released. PMON will then attempt to rollback some of the changes associated with the "dead" transaction, but will then pass it to SMON to apply the remainder of the associated undo records.
- The UL resource represent the user-defined locks defined by the DBMS_LOCK package.
Which lock modes are required for which table action?
The following table describes what lock modes on DML enqueues are actually gotten for which table operations in a standard Oracle installation.
------------------------- --------- ----- ----------------
Select NULL 1 null
Select for update SS 2 sub share
Insert SX 3 sub exclusive
Update SX 3 sub exclusive
Delete SX 3 sub exclusive
Lock For Update SS 2 sub share
Lock Share S 4 share
Lock Exclusive X 6 exclusive
Lock Row Share SS 2 sub share
Lock Row Exclusive SX 3 sub exclusive
Lock Share Row Exclusive SSX 5 share/sub exclusive
Alter table X 6 exclusive
Drop table X 6 exclusive
Create Index S 4 share
Drop Index X 6 exclusive
Truncate table X 6 exclusive
How compatibility of locks works
The compatibility of lock modes are normally represented by following matrix:
LMODE Description Name NULL SS SX S SSX X 0,1 No Lock NULL YES YES YES YES YES YES 2 Row-Share SS YES YES YES YES YES no 3 Row-Exclusive SX YES YES YES no no no 4 Share S YES YES no YES no no 5 Share Row-Exc SSX YES YES no no no no 6 Exclusive X YES no no no no no
How to detect locking situations?
Different tools can be used to detect locking issues and the identity of a blocking session or sessions. The following article contains some selects to find blocking locks:
A methodology using OEM Top Sessions report is explained in:
Which views can be used to detect locking problems?
A number of Oracle views permits to detect locking problems.V$SESSION_WAIT
When a session is waiting on a resource, it can be found waiting on the enqueue wait event
Example:
- SID identifier of session holding the lock
- P1, P2, P3 determine the resource when event = 'enqueue'
- SECONDS_IN_WAIT gives how long the wait did occurs
Session information and row locking information
- SID, SERIAL# identifier of the session
- EVENT event waited on
- P1, P2, P3 determine the resource when event = 'enqueue'
- # SECONDS_IN_WAIT gives how long the wait did occurs
- LOCKWAIT address of the lock waiting, otherwise null
- ROW_WAIT_OBJ# object identified of the object we are waiting on (object_id of dba_objects)
- ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#
file_id , block_id and row location within block of the locked row
List of all the locks in the system
- SID identifier of session holding the lock
- TYPE, ID1 and ID2 determine the resource
- LMODE and REQUEST indicate which queue the session is waiting on, as follows:
LMODE > 0, REQUEST = 0 owner
LMODE = 0, REQUEST > 0 acquirer
LMODE > 0, REQUEST > 0 converter - CTIME time since current mode was converted
- BLOCK are we blocking another lock
BLOCK = 0 non blocking
BLOCK = 1 blocking others
DBA_LOCK or DBA_LOCKS
Formatted view on V$LOCK (created via $ORACLE_HOME/rdbms/admin/catblock.sql)
- SESSION_ID == SID in V$LOCK
- LOCK_TYPE, LOCK_ID1, LOCK_ID2 formatted value of TYPE, ID1, ID2 from V$LOCK
- MODE_HELD and MODE_REQUESTED formatted value of LMODE and REQUEST from V$LOCK
- LAST_CONVERT == CTIME of V$LOCK
- BLOCKING_OTHERS formatted value of BLOCK from V$LOCK
V$TRANSACTION_ENQUEUE
Subset of V$LOCK for the blocking TX resources only
(same description as for the V$LOCK view)
V$ENQUEUE_LOCK
Subset of V$LOCK for the system resources only and
blocked TX resources only. (same description as for the V$LOCK view)
DBA_DML_LOCKS
Subset of the V$LOCK for the DML (TM) locks only
Created via $ORACLE_HOME/rdbms/admin/catblock.sql
Same description as the DBA_LOCK view
V$LOCKED_OBJECT
Same info as DBA_DML_LOCKS, but linked with the rollback and session information
- XIDUSN, XIDSLOT and XIDSQN rollback information to be linked with V$TRANSACTION
- OBJECT_ID object being locked
- SESSION_ID session id
- ORACLE_USERNAME oracle user name
- OS_USER_NAME OS user name
- PROCESS OS process id
- LOCKED_MODE lock mode
V$RESOURCE
List of all the currently locked resources in the system.
Each row can be associated with one or more rows in V$LOCK
- TYPE, ID1 and ID2 determine the resource
DBA_DDL_LOCKS
Has a row for each DDL lock that is being held, and one row for each outstanding request for a DDL lock.
It is subset of DBA_LOCKS
Same description as the DBA_LOCK view
DBA_WAITERS
View that retrieve information for each session waiting on a
lock (created via $ORACLE_HOME/rdbms/admin/catblock.sql)
- WAITING_SESSION waiting session
- HOLDING_SESSION holding session
- LOCK_TYPE, LOCK_ID1, LOCK_ID2 resource locked
- MODE_HELD lock type held
- MODE_REQUESTED lock type requested
DBA_BLOCKERS
View that gives the blocking sessions (created via $ORACLE_HOME/rdbms/admin/catblock.sql)
- HOLDING_SESSION holding session
Which tools are there to diagnostic locking issues?
- OEM Top Session
OEM Top Session permits to see all the session information. The sessions that are in status ACTIVE can be waiting on locks. By right clicking on those sessions and choosing the 'detail' screen, you can go to the 'lock' leaflet and find blocking sessions.
For more information seeNote 164760.1 Detecting and Resolving Locking Conflicts using TopSessions - Lock Charts in Performance Manager of Oracle Enterprise Manager
OEM contains a lock graph facility named the Lock Charts in the Performance Manager that is part of the Oracle Diagnostics Pack of OEM. The Performance Manager requires the Oracle Data Gatherer to run. You should select the database from the OEM Console Navigator window. Then launch Performance Manager from the Applications menu bar. When the application comes up, select the 'Lock Charts'. You can use the Performance Manager to kill the session. You just need to right-mouse click on the session you want to kill. Since the Lock Charts are automatically refreshed, you can watch the charts and instantly see locks being released. - Scripts for detecting locking
A number of sample scripts exist to retrieve locking information.Note 1020012.6 TFTS SCRIPT. TO RETURN MEDIUM DETAIL LOCKING INFO Note 1020008.6TFTS FULLY DECODED LOCKING SCRIPT
Note 1020007.6 SCRIPT. DISPLAY LOCKS AND GIVE SID AND SERIAL # TO KILL ()
Note 1020010.6 SCRIPT. DISPLAY SQL TEXT FROM LOCKS
Note 1020047.6 SCRIPT. SCRIPT. TO DISPLAY USER LOCK INFORMATION Note 1020088.6 SCRIPT. REPORT SESSIONS WAITING FOR LOCKS () - Using the logminer (Oracle8i onwards)
All locking statements are logged in the redologs.Note 198828.1 Analyzing them permits to understand locking situations
How to resolve locking situations?
Most locking issues are application specifics. To resolve locking contention, one needs to free the resource by:- Asking the HOLDER to commit or rollback
- Killing the session which holds the lock,
For example:
ALTER SESSION KILL SESSION 'sid, serial#'; - Killing the unix/vms shadow process directly.
This is not recommended as it may prevent proper cleanup of a session
When killing the shadow process, please be careful of shared servers in a multi-threaded environment. - ROLLBACK FORCE or COMMIT FORCE if 2pc pending transaction.
Deadlock Situations
If you are encountering a deadlock situation (which may be accompanied by an "ORA-60 Deadlock Detected" error) this should generate a deadlock report trace which should enable you to diagnose the cause. ORA-60 is an application error which usually occurs because a consistent locking strategy has not been followed thoughout an application.
Please refer to the following articles for more information:
Note:62365.1 What to do with "ORA-60 Deadlock Detected" Errors
Note:62354.1 TX Transaction locks - Example wait scenarios
Unusual locking problems
- Some common locking scenarios are explained in:Note 62354.1TX Transaction and Enq: Tx - Row Lock Contention - Example wait scenarios
- When your application has referential integrity and attempts to modify the child/parent table, Oracle will get additional locking on the parent/child table when there is NO index on the foreign key. To bypass this problem, the most efficient way is to create indexes for all foreign key defined in the database. See the following notes:
Note 1019527.6 'TFTS CHECK FOR FOREIGN KEY LOCKING'
Note 33453.1 REFERENTIAL INTEGRITY AND LOCKING
Note 223303.1 Correction to 9.2.0 foreign key constraint locking behaviour, per documentation Bug:2546492 - When your application is using DBMS_PIPE extensively, your session can wait for CI locks. You should increase your shared pool.
- When statements like 'CREATE INDEX' and 'ALTER INDEX REBUILD' are issued, Oracle behave differently in Oracle7 compared to Oracle8i. To understand the benefit of the ONLINE option, you can find more information in Note 70120.1 Locking Behavior. During Index Creation or Index Rebuild
- When a table's INITRANS is set too low , the block is full with data, and there are many concurrent DML's occurring on rows within the block, one may see a Share Lock being requested when doing a DML. To my knowledge, this is only time we grab the SHARED lock. Instead of waiting for a lock, this process is waiting for some extra space or a release of an INITRANS within the transaction layer of the block. See Note 62354.1 TX Transaction locks - Example wait scenarios
- There are other systemwide locks that can be held at any given time.
SeeNote 102925.1 Tracing sessions: waiting on an enqueue - Distributed transactions also use locksSee Note 118219.1 Detecting and Resolving Distributed Locking Conflicts
How to use dbms_lock?
References
NOTE:1020010.6 - Script. Display SQL text from Locked TransactionsNOTE:1020012.6 - SCRIPT. TO RETURN MEDIUM DETAIL LOCKING INFO
NOTE:1020047.6 - Script. Display User Lock Information
NOTE:1020088.6 - Script. Report sessions waiting for Locks
NOTE:164760.1 - Detecting and Resolving Locking Conflicts using TopSessions
NOTE:166534.1 - Resolving locking issues using utllockt.sql script
NOTE:168438.1 - How to use the SQL*DBA Monitors screen to analyze locking problems
NOTE:198828.1 - Analysing locking issues with LOGMINER
NOTE:33453.1 - REFERENTIAL INTEGRITY AND LOCKING
NOTE:67680.1 - PACKAGE DBMS_LOCK Specification
NOTE:69831.1 - What happened to Lock Manager in OEM 2.0.4
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17252115/viewspace-742183/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Detecting iOSiOS
- Android FAQAndroid
- REFERENTIAL INTEGRITY AND LOCKING [ID 33453.1]
- squid官方faqUI
- Android Wear-Detecting Location on Android Wear,Requesting Permissions on Android WearAndroid
- Rust Reference Cycles: Resolving and Avoiding themRust
- Android 8.0 開發者 FAQAndroid
- Best Team With No Conflicts
- ORA-65122: Pluggable database GUID conflicts with the GUID of an existingDatabaseGUI
- ASM REACTING TO PARTITION ERRORS [ID 1062954.1]ASMReactError
- How Oracle Locking WorksOracle
- Modes of Locking (334)
- DataGridView常見用法和FAQ彙總View
- Listener Hanging -Get For Resolving or Troubleshooting [ID 230156.1]
- Script to Check for Foreign Key Locking Issues [ID 1019527.6]
- 淺談mysql innodb lockingMySql
- Explicit (Manual) Data Locking (364)
- Metric Collection ErrorsError
- oracle之errorsOracleError
- oracle 之errorsOracleError
- Docker FAQDocker
- Oracle FaqOracle
- Overview of Locking Mechanisms (310)View
- SERVICE_NAME Parameter - Resolving The ORA-12514 Error [ID 77640.1]Error
- Database Capture and Replay: Common Errors and Reasons (文件 ID 463263.1)DatabaseAPTError
- 《EARLY METHODS FOR DETECTING ADVERSARIAL IMAGES》閱讀筆記筆記
- Temporary failure resolving ‘archive.ubuntu.com‘AIHiveUbuntu
- Resolving ORA-600[3020] Raised During Recovery (Doc ID 361172.1)AI
- Android Oreo 常見問題 2.0 | Android 開發者 FAQ Vol.9Android
- Android Oreo 常見問題 3.0 | Android 開發者 FAQ Vol.11Android
- Android UI 及 API 優化指南|Android 開發者 FAQ Vol.10AndroidUIAPI優化
- 【MOS】Cluster Health Monitor (CHM) FAQ (文件 ID 1328466.1 ID 2062234.1)
- Android Oreo 常見問題 2.0 | Android 開發者 FAQ Vol.9Android
- MySQL 5.5 -- Metadata Locking Within TransactionsMySql
- ORA-00060的示例與若干場景
- Go Errors 詳解GoError
- slave-skip-errorsError
- HIbernate errors...Error