首页 > Linux操作系统 > Linux操作系统 > 实习日志第16天---学习笔记---第九章:transaction


原创 Linux操作系统 作者:大米嗵嗵 时间:2011-02-21 15:25:34 0 删除 编辑


Introduction to Transactions

A transaction is a logical, atomic unit of work that contains one or more SQL statements.事务是包括1个或多个SQL语句的组成的逻辑操作单位。原子性(Atomic):每个事务是一个不可分割的整体,只有所有的单元执行成功,整个事务才成功;否则此次事务就失败,所有执行成功的操作单元必须撤销,

A transaction groups SQL statements so that they are either all committed, which means they are applied to the database, or all rolled back, which means they are undone from the database. 组成一个事务的SQL语句,要么全部提交,要么全部回滚(undone

transaction ID数据库会给每个事务分配一个唯一的标识符

事务有ACID 4特性:AtomicityConsistencyIsolationDurability

Structure of a Transaction

A database transaction consists of one or more statements. Specifically, a transaction consists of one of the following:

One or more data manipulation language (DML) statements that together constitute an atomic change to the database

One data definition language (DDL) statement


事务的结束·A user issues a COMMIT or ROLLBACK statement without a SAVEPOINT clause.

          ·A user runs a DDL command such as CREATE, DROP, RENAME, or ALTER.

          ·A user exits normally from most Oracle Database utilities and tools, causing the current transaction to be implicitly committed.

          ·A client process terminates abnormally, causing the transaction to be implicitly rolled back using metadata stored in the transaction table and the undo segment.

Statement-Level Atomicity

1.       该语句的失败不会影响到其它语句的成功提交或rollback

2.       rollback相当于该语句从没有运行过

System Change Numbers (SCNs)

SCNs order events that occur within the database, which is necessary to satisfy the ACID properties of a transaction.


Overview of Transaction Control

Transaction control is the management of changes made by DML statements and the grouping of DML statements into transactions.



ROLLBACK TO SAVEPOINT语句undoes the changes since the last savepoint

·SAVEPOINT语句,标识事务中可以在之后roll back的位置

Transaction Names

可选的,SET TRANSACTION ... NAME statement


Active Transactions

An active transaction has started but not yet committed or rolled back.

Before the transaction ends, the state of the data is as follows:

·Oracle Database has generated undo data information in the system global area (SGA).

·Oracle Database has generated redo in the online redo log buffer of the SGA.

·Changes have been made to the database buffers of the SGA

·The rows affected by the data change are locked


Savepoints divide a long transaction into smaller parts.


Enqueued Transactions等待排队事务

Rollback of Transactions

A rollback of an uncommitted transaction undoes any changes to data that have been performed by SQL statements within the transaction.

·Undoes all changes made by all the SQL statements in the transaction by using the

corresponding undo segments

·Releases all the locks of data held by the transaction

·Erases all savepoints in the transaction

·Ends the transaction

Committing Transactions

A commit ends the current transaction and makes permanent all changes performed in the transaction.

·A system change number (SCN) is generated for the COMMIT.

·The log writer (LGWR) process writes remaining redo log entries in the redo log buffers to the online redo log and writes the transaction SCN to the online redo log.

·Oracle Database releases locks held on rows and tables.

·Oracle Database deletes savepoints.

·Oracle Database performs a commit cleanout.

·Oracle Database marks the transaction complete.


Overview of Autonomous Transactions

autonomous transaction自治事务  main transaction.   autonomous transaction


Overview of Distributed Transactions

A distributed database is a set of databases in a distributed system that can appear to applications as a single data source. A distributed transaction is a transaction that includes one or more statements that update data on two or more distinct nodes of a distributed database, using a schema object called a database link.

Two-Phase Commit

The initiating node is called the global coordinator. The coordinator asks the other databases if they are prepared to commit. If all databases vote yes, then the coordinator broadcasts a message to make the commit permanent on each of the databases

In-Doubt Transactions


After the failure is repaired and communication is reestablished, the RECO process of each local Oracle database automatically commits or rolls back any in-doubt distributed transactions consistently on all involved nodes.


来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

下一篇: DBWR触发的易错点
请登录后发表评论 登录


  • 博文量
  • 访问量