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）
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.
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
可选的，SET TRANSACTION ... NAME statement
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.
ROLLBACK TO SAVEPOINT after_banda_sal
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
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.
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
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博客 ” ，链接：http://blog.itpub.net/24005010/viewspace-687614/，如需转载，请注明出处，否则将追究法律责任。