Oracle Locking Mechanism
For more Tencent massive technical articles, please follow the Cloud Plus community: https://cloud.tencent.com/developer/column
Author. Cloud+ Community Users
1, oracle is a multi-user shared resources, when multiple users concurrently operate the same data row, then there will be multiple transactions in the Oracle database to operate a unified data row operations, if not control the concurrent operations, then these transactions may operate incorrect data and destroy the consistency of the database.
2, locking is a very important technique to achieve concurrency control of the database, when the transaction of a data object to operate, the general process is as follows:
a. First send a request to the system
b. In locking the data object
c, the last data operations, the process of the current data object only the current transaction (the current session) can be used, other transactions are not available until the current transaction to release the lock, other transactions can operate the current data object
3, Oracle basic lock types :
a. Exclusive locks (Exclusive locks) i.e. X locks
When an exclusive lock is placed on a data object, no other transaction can access or modify the data object.
b. Shared Locks (Share Locks) i.e. S locks
When a shared lock is placed on a data object, other transactions can access the data object, but cannot modify it.
The database provides concurrency control over database transactions through these two basic lock types
4, Oracle lock types
According to the object of lock protection, oralce locks can be divided into the following categories:
a. DML locks (data locks) data locks
b, DDL lock dictionary locks, dictionary locks used to protect the structure of database objects, such as the structure of the table, indexes, etc.
c. internal locks and latches, which protect the internal structure of the database.
5、DML locks (data locks) Data locks Introduction
DML locks in Oracle database is mainly to ensure data integrity in the case of concurrency, DML locks mainly include TM locks (table-level locks) and TX locks (row-level locks or transaction locks), the following is the locking process for executing DML statements in Oracle
a. The system automatically applies a lock of TM type on the table to be operated by DML, and the specific lock is determined by the operation statement.