This article mainly introduces TM lock in Oracle, understand that when we access the same table object in the database through SQL statements, if more than one user operates on the same table object, it may result in inconsistent data and data inconsistency, please refer to the consistency and atomicity of database transactions. Oracle solves the problem of data inconsistency in multi-threaded situations, mainly through two kinds of locks, one is pessimistic lock, that is, I want to say, the other is optimistic lock, about the two kinds of lock introduction also refer to the consistency of database transactions and atomic analysis.
TM and TX locks are part of the pessimistic lock, so how does Oracle lock the TX lock to solve the problem of multiple users accessing the same object and ensuring data consistency.
The following table and text describe all of the Oracle TM locks
Table 1 TM Lock types for Oracle |
Lock mode |
Lock description |
Explain |
SQL operations |
0 |
None |
|
|
1 |
Null |
Empty |
Select |
2 |
SS (Row-s) |
Row-level shared locks, other objects can only query these data rows |
Select for UPDATE, lock for update, lock row share |
3 |
SX (Row-x) |
Row-level exclusive locks that do not allow DML operations before committing |
Insert, Update, Delete, Lock Row share |
4 |
S (Share) |
Shared locks |
Create Index, Lock share |
5 |
SSX (S/row-x) |
Shared row-level exclusive lock |
Lock Share Row Exclusive |
6 |
X (Exclusive) |
Exclusive lock |
Alter table, drop able, DROP index, Truncate table, Lock exclusive |
1. The SQL operation is: Select
When multiple users perform a select operation, Oracle does not make any lock-in, which means that there is no impact when other users access or modify one or more rows of data in the result set that the current select is working on, and Oracle returns the result set at the current moment. Therefore, the select operation does not perform any locking operations.
2. SQL operation: Select for update
Please refer to the difference between select for update and select for update wait and select for update nowait, using Select for Update to add a row-level shared lock to the result set, and other sessions to only query operations (The select operation is mentioned above, and the data set is not locked.)
3. The SQL operation is:
Oracle TM Lock and TX lock