Oracle Locking
Oracle Locking
Oracle Locking
RX RX RX RS
RS RX S SRX X
RS: row share RX: row exclusive S: share SRX: share row exclusive X: exclusive
More restrictive than a share table lock. A share row exclusive table lock is acquired for a table as follows: LOCK TABLE <table> IN SHARE ROW EXCLUSIVE MODE;
Permitted Operations: Only one transaction at a time can acquire a share row exclusive table lock on a given table. A share row exclusive table lock held by a transaction allows other transactions to query or lock specific rows using SELECT with the FOR UPDATE clause, but not to update the table. Prohibited Operations: Prevents other transactions from obtaining row exclusive table locks and modifying the same table. A share row exclusive table lock also prohibits other transactions from obtaining share, share row exclusive, and exclusive table locks.
Protects the definition of an object while being used by a DDL operation. Recall that a DDL statement implicitly commits. Create Procedure will automatically acquire DDL locks for all schema objects referenced in the procedure definition. The DDL locks prevent objects referenced in the procedure from being altered/dropped before the compile is complete. Cannot explicitly request DDL locks. Individual schema objects that are modified or referenced are locked during DDL operations; the whole data dictionary is never locked. Three categories: exclusive DDL locks, share DDL locks, and breakable parse locks.
Oracle Latches
Latches are low-level serialization mechanisms to protect shared data structures in the system global area (SGA). Latches protect the oracle lists like list of users currently accessing the database and protect the data structures describing the blocks in the buffer cache. A server or background process acquires a latch for a very short time while manipulating or looking at one of these structures. The implementation of latches is operating system dependent, particularly in regard to whether and how long a process will wait for a latch.
Oracle automatically converts a table lock of lower restrictiveness to one of higher restrictiveness as appropriate. For example, assume that a transaction uses a SELECT statement with the FOR UPDATE clause to lock rows of a table. As a result, it acquires the exclusive row locks and a row share table lock for the table. If the transaction later updates one or more of the locked rows, the row share table lock is automatically converted to a row exclusive table lock.
Deadlocks
Oracle automatically detects deadlock situations and resolves them by rolling back one of the statements involved in the deadlock. This releases one set of the conflicting row locks. A corresponding message also is returned to the transaction that undergoes the rollback. Deadlocks often occur when transactions override Oracle default locking. Oracle itself does no lock escalation and does not use read locks for queries and does not use page-level locking, deadlocks rarely occur in Oracle. Deadlocks can usually be avoided if transactions accessing the same tables lock those tables in the same order, either through implicit or explicit locks and when a sequence of locks for one transaction are required, you should consider acquiring the most exclusive (least compatible) lock first Always close explicit cursors when finished to free locks.
CREDITS
Oracle Metalink White Paper 70120 Oracle 8.1.7 Documentation My own knowledge and experience using Oracle
?? QUESTIONS ??