实习日志第16天---学习笔记---第九章:transaction

Transactions

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

事务的开始:以SQL语句开始。一条可执行SQL会调用到数据库实例

事务的结束·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.

·COMMIT语句,提交事务,永久的,同时消除该事务中所有的savepoint并释放事务锁

·ROLLBACK语句,将数据回滚到上次commitrollback后的状态。

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

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

Transaction Names

可选的,SET TRANSACTION ... NAME statement

V$TRANSACTION.

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

Savepoints divide a long transaction into smaller parts.

ROLLBACK TO SAVEPOINT after_banda_sal

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

RECO

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24005010/viewspace-687614/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值