对于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机制为BATCH和NOWAIT
例:COMMIT_WRITE = BATCH, NOWAIT
也可以使用alter system在系统级别设置commit机制为BATCH和NOWAIT
例:ALTER SYSTEM SET COMMIT_WRITE = BATCH, NOWAIT
|
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:
|
异步commit由于不能确保事务的redo已经写出到redo logfile当中,一旦实例崩溃,可能导致已经commit的事务无法恢复,使用该特性的时候需要慎重考虑。
其他文件:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9390331/viewspace-713464/ ,如需转载,请注明出处,否则将追究法律责任。