ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【oracle 10g R2 新特性】Asynchronous Commit

【oracle 10g R2 新特性】Asynchronous Commit

原创 Linux操作系统 作者:victorymoshui 时间:2011-12-16 20:59:24 0 删除 编辑

对于Oracle的commit机制,相信大家都已经非常的熟悉了。Oracle对于commit采取了同步写事务log的方式,也就是说,一旦发出commit命令,那么必须等待事务相关的所有redo都已经从log buffer写出到redo logfile以后,才会控制权返回发出commit的进程。


同步commit有两个特点:

1.Immediate,发出commit命令后,立即将redo写出

2.Wait,在redo写出过程中,必须等待,等待事物相关的所有redo都已经从log buffer写出到redo logfile中。

但是,Oracle10gR2开始,一种新的commit机制被引入,这就是异步commit机制。也就是说,不必等到事务相关redo写出就可以返回了,异步commit也有两种特点:

1.Nowait,发出commit命令后,不管redo是否写出,立即返回控制权

2.Batch,redo的写出可以想buffer一样执行批量写出,以提高性能

当然,同步commit也可以batch,异步commit也可以将redo立即写出,所以上述四个特性可以自由组合。

 

   Initialization Parameter and COMMIT Options for Managing Commit Redo

Option Specifies that . . .

WAIT

The commit does not return as successful until the redo corresponding to the commit is persisted in the online redo logs (default).

NOWAIT

The commit should return to the application without waiting for the redo to be written to the online redo logs.

IMMEDIATE

The log writer process should write the redo for the commit immediately (default). In other words, this option forces a disk I/O.

BATCH

Oracle Database should buffer the redo. The log writer process is permitted to write the redo to disk in its own time.


这样,commit引入了新的语法:

COMMIT [WRITE [IMMEDIATE | BATCH] [WAIT | NOWAIT] ]

默认情况下,commit的机制和以前一样,也就是相当于

COMMIT WRITE IMMEDIATE WAIT;

当然,这个默认机制可以通过初始化参数修改,所以Oracle10gR2又引入了一个新的参数COMMIT_WRITE,可能的取值包括

COMMIT_WRITE='{ IMMEDIATE | BATCH } , { WAIT | NOWAIT }'
 

 

可以在初始化参数文件中设置commit机制为BATCH和NOWAIT

例:COMMIT_WRITE = BATCH, NOWAIT

也可以使用alter system在系统级别设置commit机制为BATCH和NOWAIT

例:ALTER SYSTEM SET COMMIT_WRITE = BATCH, NOWAIT

 
如果直接使用commit语句如下,即在commit后跟子句,可以忽略掉当前在初始化参数文件中设置的commit机制,而使用当前设置的新机制。
 
例:COMMIT WRITE BATCH NOWAIT
注意:在分布式事务中,不可以修改IMMEDIATEWAIT 参数。

 

Note that the specification of the NOWAIT and BATCH options allows a small window of vulnerability in which Oracle Database can roll back a transaction that your application view as committed. Your application must be able to tolerate the following scenarios:

  • The database host crashes, which causes the database to lose redo that was buffered but not yet written to the online redo logs.

  • A file I/O problem prevents log writer from writing buffered redo to disk. If the redo logs are not multiplexed, then the commit is lost.


异步commit由于不能确保事务的redo已经写出到redo logfile当中,一旦实例崩溃,可能导致已经commit的事务无法恢复,使用该特性的时候需要慎重考虑。

其他文件:

oracle分布式事务

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9390331/viewspace-713464/,如需转载,请注明出处,否则将追究法律责任。

下一篇: oracle分布式事务
请登录后发表评论 登录
全部评论

注册时间:2009-08-26

  • 博文量
    173
  • 访问量
    298993