18, oracle database transactions


18.1 Introduction of things:

1, is composed of a set of things dml statements and commit / rollback composition, change the database is the smallest logical unit, such as the commit, the data representing storage,

If a rollback, it expressed cancel all dml operations;

2, things ended commit, rollback, ddl statement is automatically submitted commit;

3, the beginning of things is a thing of the end is the beginning of the next thing;

4, oracle must be submitted otherwise data will not be into the library;

5, the characteristics of things:

(1) atom of (Atomicity): transaction procedures involved either all succeed to modify the operation of the database, or all fail;

(2) Consistency (Consistency): transactions executed before and after the implementation of the source and destination balance;

(3) isolation (Isolation): concurrent transactions are isolated from each phase independently of each other;

(4) persistent (Durubility): Once the transaction successfully submitted, should ensure the integrity of data exists;


18.2, ORACLE database transaction isolation levels:

1, transaction isolation level: the degree of isolation of a transaction with another transaction to modify the database in parallel;

2, two concurrent transactions access the same database table rows, the following three problems may exist:

(1) Dirty read : A transaction B reads the data transaction uncommitted updates, then B rollback, then A dirty read data transactions;

(2) non-repeatable read: Transaction A reads the same data multiple times, and transaction B updates made during the transaction data submitted A read many times, resulting in a transaction A reads the same data multiple times, the results are inconsistent;

(3) Reading Magic: The system administrator A database of results from specific scores for all students instead ABCDE level, but the system administrator B would insert a specific record score at this time and submitted,

After the end of the system administrator A change found that there is a record no change overnight, just like happened as hallucinations, this is called phantom read;

(4) Summary: non-repeatable reads and phantom reads are easily confused, non-repeatable read focused on the modification, phantom reads focused on adding or deleting, solve the problem of non-repeatable read lock just rows meet the conditions, to solve the phantom read need to lock table;

3, in order to solve the problem oracle database concurrency things occurring, set the level of things following:

(1) The higher the level, the worse the concurrency:

(2) Oracle database to support both READ COMMITTED and SERIALIZABLE transaction isolation level, so Oracle does not support dirty read;

The default transaction isolation level (3) SQL standard definition is SERIALIZABLE, but Oracle is used by default READ COMMITTED;

(4) Set isolation levels SET TRANSACTION ISOLATION LEVEL [READ COMMITTED | SERIALIZABLE]

(5) For example: if the isolation level of the database is provided READ COMMITTED time, now if there are two transactions T1 and T2, T1 are now added to a database

Data but uncommitted transactions, then T2 T1 at this time can not access the contents of the change. Only after submitting the transaction T1, T2 can see the changes to the database. T1 equivalent to commit the transaction

Previously, data on the changes added a lock, other transactions can not see!


18.3 lock:

1, an exclusive lock (x Lock):

When there DML statement is executed, the design of the line will add exclusive lock, other things can not be modified until commit or rollback release it;

2, a shared lock (s Lock):

Plus a shared lock data, can be read by other things, but can not be modified;

3, the table shared locks s, x plus an exclusive lock on the line;

ATM:automatic teller machine


18.4, the consequences of things not submitted:

1, the operation of other things he can not see, you can see;

2, plus table and row lock will not release, other things can block the operation;

3, the operation of the data it can be restored to a previous state;












Guess you like

Origin www.cnblogs.com/LiuChang-blog/p/12315870.html