control中有三种SCN分别为,system SCN、datafile SCN、last SCN,数据文件头中有一种SCN start SCNsystem scn从视图v$database中获得,对应checkpoint_change#字段,datafile scn、last scn分别对应视图v$datafile中的checkpoint_change#,last_change#,而 start scn则从v$datafile_header中checkpoint_change#得到。数据库在正常启动后下,system scn,datafile scn,start scn会相等,而last scn会被置于无穷大,这里为null。正常关闭后(immediate,noraml,translate),上面四个scn会应执行full checkpoint 而相等。当系统在非正常关闭后,如shutdown abort,这个时候last scn依然为无穷大,那么当重新启动实例时,系统首先会比较start scn与system scn,如果一致,那么再比较start scn 与last scan是否一样大,因为是非正常关闭,这里会不一样大,那么就需要例程恢复。如果打开数据库时发现system scn>datafile scn,那么以为着使用旧的备份数据文件,也就是需要介质恢复如果是system scn<datafile scn,及控制文件scn是旧的,代表使用了老的控制文件,需要recover using backup controlfile进行恢复。
1、正常启动时SQL> select checkpoint_change# from v$database; --控制文件中的scn
CHECKPOINT_CHANGE#------------------5534071SQL> select file#,checkpoint_change# from v$datafile_header; --start scn
FILE# CHECKPOINT_CHANGE#---------- ------------------1 55340712 55340713 55340714 55340715 5534071SQL> select file#,checkpoint_change#,last_change# from v$datafile; --datafile scn & last scn
FILE# CHECKPOINT_CHANGE# LAST_CHANGE#---------- ------------------ ------------1 55340712 55340713 55340714 55340715 55340712、正常关闭后,然后在startup mount;SQL> shutdown immediate;数据库已经关闭。已经卸载数据库。ORACLE 例程已经关闭。SQL> startup mount;ORACLE 例程已经启动。
Total System Global Area 319888364 bytesFixed Size 453612 bytesVariable Size 192937984 bytesDatabase Buffers 125829120 bytesRedo Buffers 667648 bytes数据库装载完毕。SQL> select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#---------- ------------------1 55344852 55344853 55344854 55344855 5534485
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#------------------5534485
SQL> select file#,checkpoint_change#,last_change# from v$datafile;
FILE# CHECKPOINT_CHANGE# LAST_CHANGE#---------- ------------------ ------------1 5534485 55344852 5534485 55344853 5534485 55344854 5534485 55344855 5534485 5534485--发现start scn=last scn,证明系统是正常关闭
SQL> alter database open;
数据库已更改。
3、在正常打开状态下进行事务操作SQL> create table t(a number);
表已创建。
SQL> insert into t values (1);
已创建 1 行。
SQL> commit;
提交完成。
SQL> insert into t values(2);
已创建 1 行。
4、非正常关闭SQL> shutdown abort;ORACLE 例程已经关闭。SQL>
5、打开到mount状态下,观看scnSQL> startup mount;ORACLE 例程已经启动。
Total System Global Area 319888364 bytesFixed Size 453612 bytesVariable Size 192937984 bytesDatabase Buffers 125829120 bytesRedo Buffers 667648 bytes数据库装载完毕。SQL> select file#,checkpoint_change#,last_change# from v$datafile;
FILE# CHECKPOINT_CHANGE# LAST_CHANGE#---------- ------------------ ------------1 55344862 55344863 55344864 55344865 5534486
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#------------------5534486
SQL> select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#---------- ------------------1 55344862 55344863 55344864 55344865 5534486--这时发现start scn 与last scn不等,last scn为无穷大,需要例程恢复
6、改变数据库状态为open,并查看该阶段运行日志SQL> select * from wen.t;select * from wen.t*ERROR 位于第 1 行:ORA-01219: 数据库未打开: 仅允许在固定表/视图中查询
SQL> alter database open;
数据库已更改。SQL> select * from wen.t;
A----------1--发现没有提交的事务丢失。查看日志如下:Completed: ALTER DATABASE MOUNTWed May 17 21:35:46 2006alter database openWed May 17 21:35:46 2006Beginning crash recovery of 1 threads --会自动判断是否需要恢复,这里开始例程恢复Wed May 17 21:35:46 2006Started first pass scanWed May 17 21:35:47 2006Completed first pass scan206 redo blocks read, 90 data blocks need recoveryWed May 17 21:35:47 2006Started recovery atThread 1: logseq 167, block 271, scn 0.0Recovery of Online Redo Log: Thread 1 Group 2 Seq 167 Reading mem 0 --恢复用的在线重做日志Mem# 0 errs 0: D:ORACLEORADATADB1REDO02.LOGWed May 17 21:35:47 2006Ended recovery atThread 1: logseq 167, block 477, scn 0.555472490 data blocks read, 90 data blocks written, 206 redo blocks readCrash recovery completed successfully --恢复完成Wed May 17 21:35:47 2006LGWR: Primary database is in CLUSTER CONSISTENT modeThread 1 advanced to log sequence 168Thread 1 opened at log sequence 168Current log# 3 seq# 168 mem# 0: D:ORACLEORADATADB1REDO03.LOGSuccessful open of redo thread 1.Wed May 17 21:35:48 2006SMON: enabling cache recoveryWed May 17 21:35:48 2006ARC0: Evaluating archive log 2 thread 1 sequence 167ARC0: Beginning to archive log 2 thread 1 sequence 167Creating archive destination LOG_ARCHIVE_DEST_1: 'D:DBBKARC00167.001'ARC0: Completed archiving log 2 thread 1 sequence 167Wed May 17 21:35:48 2006Undo Segment 1 OnlinedUndo Segment 2 OnlinedUndo Segment 3 OnlinedUndo Segment 4 OnlinedUndo Segment 5 OnlinedUndo Segment 6 Onlined
原文地址