Oracle TM Lock and TX lock

Source: Internet
Author: User
Tags create index

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.