Oracle how to ensure the ACID principle of transactions -- oracle Core Technology Reading Note 2, acid -- oracle

Source: Internet
Author: User

Oracle how to ensure the ACID principle of transactions -- oracle Core Technology Reading Note 2, acid -- oracle

There are four general principles in the transaction that all databases must comply with, referred to as the ACID principle. The following briefly describes how oracle implements these four principles.


1. Atomicity: one transaction can be executed in full or not in all.

In oracle, when we make a change, the system will automatically create an undo record to describe how to cancel the change. That is to say, when executing a transaction, if other users want to access the data we have changed, they must use the undo record to view the old data before the change, that is, the changes made only after the transaction is committed can be seen by others. This ensures that other users can see either the changes we have made or any changes they have made. In another case, if this transaction fails, we can also roll back our modifications based on the information in the undo. Make sure that either all succeeded or all failed.


2. Consistency: the running of a transaction does not change the data Consistency in the database.

Assume that three update operations are required for a transaction, and two update operations are successfully performed at a certain time point. At this time, the data in the database is not in a consistent State, because the third update operation is not executed. If we see the results of the two successful update operations at this time, data consistency is broken. In oracle, due to the existence of undo, other users cannot see the incremental application of the transaction (that is, two successful update operations), that is, they cannot see this illegal temporary status. They can either see the old state or the new state without the intermediate state.


Iii. Independence (Isolation): one transaction cannot see the execution results of another uncommitted transaction.

From the first point, we can see that oracle uses undo to ensure that other users cannot see the changes made by our firm. Before we submit the changes. Other transactions can only look for old data from the undo, rather than the new data that our transaction has changed.


4. Durability: Once the transaction is successful, data modification is permanent.

This principle highlights the advantages of oracle redo logs. In oracle, once a transaction is committed, oracle writes the redo log to the redo log file in sequence. Instead of going to the disk to persist the changes made by our firm. For example, if a transaction modifies 100 data records and the 100 data records are randomly stored in different locations on the disk, once the transaction is committed, we have to spend a lot of time on the disk to find the data we need to modify and modify it. Oracle does not. Oracle only generates a series of redo logs (describing data modification) by itself, and then writes the redo log files to the disk in sequence. If the write is successful, the transaction is committed successfully, even if the modification has not been made permanently to the disk. Assume that the disk data has not been changed to the correct data because of the sudden power failure at this time, but the transaction has been successful. What should I do. Oracle will automatically read the redo log file at the next startup, and the modifications will not be made persistent to the disk. Then, the modifications will be made persistent to the database to ensure committed transactions, data is always modified.



How can I enable a transaction in oracle with such a command? When you enter a session, how do you know whether the current session is in a transaction?

BeginTrans is used to start a transaction; RollbackTrans is used to roll back the transaction; CommitTrans is used to submit all the transaction processing results, that is, to confirm the processing of the transaction

BeginTrans and CommitTrans are used to mark the start and end of a transaction. The statements between them are used as the statement for transaction processing.
 
In Oracle 9i, how does one view things, how does one view sessions, and if the answers are in order, the first answer is in the answer session,

Select * from v $ session;
Yes View session

Related Article

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.