前言:接上一篇Oracle Database Instance - Oracle 实例篇3
Oracle Database Instance - Oracle 实例篇3 http://blog.csdn.net/u010993297/article/details/9931677
1. Instance Recovery
<<----instance recovery: applying records (online redo log—data file), conditions(checkpoint) ---->>
Instance recovery is the process of applying records in the online redo log to data files to reconstruct changes made after the most recent checkpoint. Instance recovery occurs automatically when an administrator attempts to open a database that was previously shut down inconsistently.
1.1 Purpose of instance recovery
<<---- 实例恢复保证数据库始终是一致性的状态,当实例发生故障后。---->>
Instance recovery ensures that the database is in a consistent state after an instance failure. The files of a database can be left in an inconsistent state because of how Oracle Database manages database changes.
<<---- Redo thread 记录来自实例产生的所以改变的记录。Single-instance—one redo thread;RAC –multiple redo threads---->>
A redo thread is a record of all of the changes generated by an instance. A single-instance database has one thread of redo, whereas an Oracle RAC database has multiple redo threads, one for each database instance.
<<----1.transaction commit :LGWR(redo entries&transacction SCN-online redo log;DBWn(modify data blocks-data files)). 2.transaction uncommit:temporarily exist-data files ---->>
When a transaction is committed,log writer(LGWR) writes both the remaining redo entries in memory and the transaction SCN to the online redo log. However, the database writer(DBWn) process writes modified data blocks to the data files whenever it is most efficient. For this reason, uncommitted changes may temporarily exist in the data files while committed changes do not yet exist in the data files.
<<----shutdown abort&abnormal termination:1.data blocks commit-only online redo log.2.data files uncommit—roll back ---->>
If an instance of an open database fails, either because of a shutdown abort statement or abnormal termination, then the following situations can result:
>>Data blocks committed by a transaction are not written to the data files and appear only in the online redo log. These changes must be reapplied to the database.
>>The data files contains changes that had not been committed when the instance failed. These changes must be rolled back to ensure transactional consistency.
Instance recovery uses only online redo log files and current online data files to synchronize the data files and ensure that they are consistent.
1.2 When oracle database performs instance recovery
<<----instance recovery—state of the redo threads(正常情况下,数据库实例只读只写模式打开,redo thread 在控制文件中标识为open或数据库实例正常关闭,redo thread 在控制文件中标志位close;如果反之,redo threads在控制文件里面标识为open,而实例确是失效的,这时就需要instance recovery)---->>
Whether instance recovery is required depends on the state of the redo threads. A redo thread is marked open in the control file when a database instance opens in read/write mode, and is marked closed when the instance is shut down consistently. If redo threads are marked open in the control file, but nolive instanceshold the thread enqueues corresponding to these threads, then the database requires instance recovery.
<<----instance recovery automatically(1.crash recovery(recover the online redo threads of the terminated instances),single-instance&RAC.2.some of the RAC(creash recovery)).3.SMON performs instance recovery.--->>
Oracle Database performs instance recovery automatically in the following situations:
>>The database opens for the first time after the failure of a single-instance database or all instances of an Oracle RAC database. This form of instance recovery is also calledcrash recovery. Oracle Database recovers the online redo threads of the terminated instances together.
>>Some but not all instances of an Oracle RAC database fail. Instance recovery is performed automatically by a surviving instance in the configuration.
The SMON background process performs instance recovery, applying online redo automatically. No user intervention is required.
1.3 Importance of checkpoints for instance recovery
如下图所示:
图 1 checkpoint Position in Online Redo Log
Instance recovery uses checkpoints to determine which changes must be applied to the data files. The checkpoint position guarantees that every committed change with an SCN lower than the checkpoint SCN is saved to the data files. –实例恢复依赖于检查点的位置。
During instance recovery, the database must apply the changes that occur between the checkpoint position and the end of the redo thread. As shown in 图 1, some changes may already have been written to the data files. However, only changes with SCNs lower than the checkpoint position are guaranteed to be on disk.
1.4 Instance recovery phases
<<---The first: rolling forward(regenerates the corresponding undo segments):(commit&uncommit&records(online redo log& cache recovery))
The second: rolling back(transaction recovery): (checkpoint position--undo blocks)
)-->>
The first phase of instance recovery is called cache recovery or rolling forward, and involves reapplying all of the changes recorded in the online redo log to the data files. Because rollback data is recorded in the online redo log, rolling forward also regenerates the corresponding undo segments.
Rolling forward proceeds through as many online redo log files as necessary to bring the database forward in time. After rolling forward, the data blocks contain all committed changes recorded in the online redo log files. These files could also contain uncommitted changes that were either saved to the data files before the failure, or were recorded in the online redo log and introduced during cache recovery.
After the roll forward, any changes that were not committed must be undone. Oracle Database uses the checkpoint position, which guarantees that every committed change with an SCN lower than the checkpoint SCN issaved on disk. Oracle Database applies undo blocks to roll back uncommitted changes in data blocks that were written before the failure or introduced during cache recovery. This phase is called rolling back or transaction recovery.
图2 illustrates rolling forward and rolling back, the two steps necessary to recover from database instance failure.
图 2 Basic Instance Recovery Steps: Rolling Forward and Rolling Back
<<--- terminated transactions –new transaction roll back---->>
Oracle Database can roll back multiple transactions simultaneously as needed. All transactions that were active at the time of failure are marked as terminated. Instead of waiting for the SMON process to roll back terminated transactions, new transactions can roll back individual blocks themselves to obtain the required data.
待续。。。。