7.5.3 案例3 (控制文件的恢复)
7.5.3.1 场景1 控制文件没有全坏,有一个是好的
step 1: 查看控制文件记录的序列号,控制文件和数据文件的SCN
|
|
step 2: 模拟事故,删除一个control文件
|
|
step 3: 用好的control文件来,替换换掉的文件。
|
|
7.5.3.2 场景2 所有控制文件都坏了,但损坏前有备份(二进制)
step 1: 备份control文件为二进制格式,并查看控制文件和数据文件的SCN
|
|
step 2: 插入新的数据,并提交,并查看控制文件和数据文件的SCN,发现SNC没有变化
|
|
step 3: 将所有的数据变化,写入到disk,发现SNC有变化
12345678910111213141516171819202122232425262728293031323334353637 -- Specify CHECKPOINT to explicitly force Oracle Database to perform a checkpoint,-- ensuring that all changes made by committed transactions are written to datafiles on disk.SQL> alter system checkpoint;System altered.SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1157349SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11573492 11573493 11573494 11573495 11573496 11573496 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11573492 11573493 11573494 11573495 11573496 11573496 rows selected.step 4: 模拟事故,删除所有的control file
123456789101112131415 [oracle@hzvscmdb mmpdb3]$ mv control01.ctl control01.ctl-bak[oracle@hzvscmdb mmpdb3]$ mv control02.ctl control02.ctl-bakSQL> shutdown abort;ORACLE instance shut down.SQL> startup;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 3456107936 bytesDatabase Buffers 3187671040 bytesRedo Buffers 18194432 bytesORA-00205: error in identifying control file, check alert log for more infostep 5: copy 备份的control file 二进制文件到默认相应的目录,然后开启数据库发现错误,查看数据文件记录的SCN与控制文件记录的SCN不一致。
123456789101112131415161718192021222324252627282930313233343536373839404142434445 [oracle@hzvscmdb mmpdb3]$ cp -a /home/oracle/dbbak/control.bin control01.ctl[oracle@hzvscmdb mmpdb3]$ cp -a /home/oracle/dbbak/control.bin /home/oracle/app/oracle/fast_recovery_area/mmpdb3/control02.ctlSQL> startup;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 3456107936 bytesDatabase Buffers 3187671040 bytesRedo Buffers 18194432 bytesDatabase mounted.ORA-01589: must use RESETLOGS or NORESETLOGS option for database openSQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1152702SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11527022 11527023 11527024 11527025 11527026 11527026 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11573492 11573493 11573494 11573495 11573496 11573496 rows selected.step 6: 进行恢复
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 SQL> alter database open noresetlogs;alter database open noresetlogs*ERROR at line 1:ORA-01610: recovery using the BACKUP CONTROLFILE option must be doneSQL> recover database using backup controlfile until cancelORA-00275: media recovery has already been startedSQL> recover database using backup controlfile until cancelORA-00279: change 1157117 generated at 11/15/2016 23:37:55 needed for thread 1ORA-00289: suggestion : /home/oracle/app/oracle/fast_recovery_area/MMPDB3/archivelog/2016_11_16/o1_mf_1_11_%u_.arcORA-00280: change 1157117 for thread 1 is in sequence #11Specify log: {<RET>=suggested | filename | AUTO | CANCEL}/home/oracle/app/oracle/oradata/mmpdb3/redo01.logORA-00328: archived log ends at change 1146901, need later change 1157117ORA-00334: archived log: '/home/oracle/app/oracle/oradata/mmpdb3/redo01.log'ORA-10879: error signaled in parallel recovery slaveORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error belowORA-01194: file 1 needs more recovery to be consistentORA-01110: data file 1: '/home/oracle/app/oracle/oradata/mmpdb3/system01.dbf'SQL> alter database recover cancel;Database altered.SQL> select GROUP#, STATUS, ARCHIVED, MEMBERS, FIRST_CHANGE#, to_char(NEXT_CHANGE#, 9999999999999999999) from v$log;GROUP# STATUS ARC MEMBERS FIRST_CHANGE# TO_CHAR(NEXT_CHANGE#---------- ---------------- --- ---------- ------------- --------------------1 INACTIVE YES 1 1127994 11469023 INACTIVE YES 1 1095072 11279942 CURRENT NO 1 1146902 281474976710655-- Note: You can specify the name of an online CURRENT redo logSQL> recover database using backup controlfile until cancelORA-00279: change 1157117 generated at 11/15/2016 23:37:55 needed for thread 1ORA-00289: suggestion : /home/oracle/app/oracle/fast_recovery_area/MMPDB3/archivelog/2016_11_16/o1_mf_1_11_%u_.arcORA-00280: change 1157117 for thread 1 is in sequence #11Specify log: {<RET>=suggested | filename | AUTO | CANCEL}/home/oracle/app/oracle/oradata/mmpdb3/redo02.logLog applied.Media recovery complete.SQL> alter database open resetlogs;Database altered.SQL> select GROUP#, STATUS, ARCHIVED, MEMBERS, FIRST_CHANGE#, to_char(NEXT_CHANGE#, 9999999999999999999) from v$log;GROUP# STATUS ARC MEMBERS FIRST_CHANGE# TO_CHAR(NEXT_CHANGE#---------- ---------------- --- ---------- ------------- --------------------1 CURRENT NO 1 1157419 2814749767106552 UNUSED YES 1 0 03 UNUSED YES 1 0 0SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1157422SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11574222 11574223 11574224 11574225 11574226 11574226 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 11574222 11574223 11574224 11574225 11574226 11574226 rows selected.
7.5.3.3 场景3 所有控制文件都坏了,但损坏前有备份(文本)
step 1: 备份control文件为文本,并查看控制文件和数据文件的SCN
12345678910111213141516171819202122232425262728293031323334353637383940414243 SQL> alter database backup controlfile to trace as '/home/oracle/dbbak/control.txt';Database altered.SQL> insert into mp.T_LOAD_DATA values(1888, 't888');1 row created.SQL> commit;Commit complete.SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1875087SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 18750872 18750873 18750874 18750875 18750876 18750876 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 18750872 18750873 18750874 18750875 18750876 18750876 rows selected.step 2: 模拟事故,删除control 文件
12345678910111213 [oracle@hzvscmdb mmpdb3]$ rm -rf control01.ctlSQL> shutdown abort;ORACLE instance shut down.SQL> startup;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 3724543392 bytesDatabase Buffers 2919235584 bytesRedo Buffers 18194432 bytesORA-00205: error in identifying control file, check alert log for more infostep 3: 利用备份的control文件,来恢复
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 STARTUP NOMOUNTCREATE CONTROLFILE REUSE DATABASE "MMPDB3" NORESETLOGS ARCHIVELOGMAXLOGFILES 16MAXLOGMEMBERS 3MAXDATAFILES 100MAXINSTANCES 8MAXLOGHISTORY 292LOGFILEGROUP 1 '/home/oracle/app/oracle/oradata/mmpdb3/redo01.log' SIZE 50M BLOCKSIZE 512,GROUP 2 '/home/oracle/app/oracle/oradata/mmpdb3/redo02.log' SIZE 50M BLOCKSIZE 512,GROUP 3 '/home/oracle/app/oracle/oradata/mmpdb3/redo03.log' SIZE 50M BLOCKSIZE 512-- STANDBY LOGFILEDATAFILE'/home/oracle/app/oracle/oradata/mmpdb3/system01.dbf','/home/oracle/app/oracle/oradata/mmpdb3/sysaux01.dbf','/home/oracle/app/oracle/oradata/mmpdb3/undotbs01.dbf','/home/oracle/app/oracle/oradata/mmpdb3/users01.dbf','/home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf','/home/oracle/app/oracle/oradata/mmpdb3/tab02.dbf'CHARACTER SET WE8ISO8859P1;SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1875087SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 18750872 18750873 18750874 18750875 18750876 18750876 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 18750872 18750873 18750874 18750875 18750876 18750876 rows selected.SQL> alter database open;alter database open*ERROR at line 1:ORA-01113: file 1 needs media recoveryORA-01110: data file 1: '/home/oracle/app/oracle/oradata/mmpdb3/system01.dbf'SQL> recover database;Media recovery complete.SQL> ALTER SYSTEM ARCHIVE LOG ALL;System altered.SQL> ALTER DATABASE OPEN;Database altered.
7.5.3.4 场景4 备份控制文件的恢复,控制文件中不包含数据文件,但联机日志中有
step 1: 先备份control文件为二进制,然后创建新的表空间,并查看控制文件与数据文件的SCN,发现新创建的表空间tab03 CHECKPOINT_CHANGE# 与其它的不一致。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 SQL> alter database backup controlfile to '/home/oracle/dbbak/control.ctl';Database altered.SQL> create tablespace tab03 datafile '/home/oracle/app/oracle/oradata/mmpdb3/tab03.dbf' size 10m;Tablespace created.SQL> select file#,name from v$datafile;FILE# NAME---------- ------------------------------------------------------------1 /home/oracle/app/oracle/oradata/mmpdb3/system01.dbf2 /home/oracle/app/oracle/oradata/mmpdb3/sysaux01.dbf3 /home/oracle/app/oracle/oradata/mmpdb3/undotbs01.dbf4 /home/oracle/app/oracle/oradata/mmpdb3/users01.dbf5 /home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf6 /home/oracle/app/oracle/oradata/mmpdb3/tab02.dbf7 /home/oracle/app/oracle/oradata/mmpdb3/tab03.dbfSQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1900834SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19008342 19008343 19008344 19008345 19008346 19008347 19011997 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19008342 19008343 19008344 19008345 19008346 19008347 19011997 rows selected.SQL> create table mp.t03(id number(10), name varchar(10)) tablespace tab03;Table created.SQL> insert into mp.t03 values(1,'t1');1 row created.SQL> commit;Commit complete.step 2: 模拟事故,删除控制文件。
1234 [oracle@hzvscmdb mmpdb3]$ mv control01.ctl control01.ctl-bakSQL> shutdown abort;ORACLE instance shut down.step 3: copy备份的control 文件到默认的目录,启动数据库。
123456789101112131415161718192021222324252627282930313233343536373839404142434445 [oracle@hzvscmdb mmpdb3]$ cp -a /home/oracle/dbbak/control.ctl /home/oracle/app/oracle/oradata/control01.ctl[oracle@hzvscmdb mmpdb3]$ cp -a /home/oracle/dbbak/control.ctl /home/oracle/app/oracle/fast_recovery_area/mmpdb3/control02.ctlSQL> startup;ORACLE instance started.Total System Global Area 6664212480 bytesFixed Size 2239072 bytesVariable Size 3724543392 bytesDatabase Buffers 2919235584 bytesRedo Buffers 18194432 bytesDatabase mounted.ORA-01589: must use RESETLOGS or NORESETLOGS option for database openSQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1900834SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19008342 19008343 19008344 19008345 19008346 19008346 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19008342 19008343 19008344 19008345 19008346 19008346 rows selected.step 4: 利用redo log 进行不完全恢复。
12345678910111213141516171819202122 SQL> select GROUP#, ARCHIVED, STATUS, to_char(NEXT_CHANGE#, 99999999999999999) from v$log;GROUP# ARC STATUS TO_CHAR(NEXT_CHANG---------- --- ---------------- ------------------1 YES INACTIVE 18998443 YES INACTIVE 18750872 NO CURRENT 281474976710655SQL> recover database using backup controlfile;ORA-00279: change 1900834 generated at 11/17/2016 05:40:17 needed for thread 1ORA-00289: suggestion : /home/oracle/app/oracle/fast_recovery_area/MMPDB3/archivelog/2016_11_17/o1_mf_1_167_%u_.arcORA-00280: change 1900834 for thread 1 is in sequence #167Specify log: {<RET>=suggested | filename | AUTO | CANCEL}/home/oracle/app/oracle/oradata/mmpdb3/redo02.logORA-00283: recovery session canceled due to errorsORA-01244: unnamed datafile(s) added to control file by media recoveryORA-01110: data file 7: '/home/oracle/app/oracle/oradata/mmpdb3/tab03.dbf'ORA-01112: media recovery not startedstep 5: 发现redo log里面记录的数据文件‘tab03’不存在, 查看v$datafile发现名字不一致,将其重命名后,进行恢复
123456789101112131415161718192021222324252627282930313233343536373839404142 SQL> select file#, CHECKPOINT_CHANGE#, name from v$datafile;FILE# CHECKPOINT_CHANGE# NAME---------- ------------------ ------------------------------------------------------------1 1900834 /home/oracle/app/oracle/oradata/mmpdb3/system01.dbf2 1900834 /home/oracle/app/oracle/oradata/mmpdb3/sysaux01.dbf3 1900834 /home/oracle/app/oracle/oradata/mmpdb3/undotbs01.dbf4 1900834 /home/oracle/app/oracle/oradata/mmpdb3/users01.dbf5 1900834 /home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf6 1900834 /home/oracle/app/oracle/oradata/mmpdb3/tab02.dbf7 1901198 /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00007SQL> alter database rename file '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00007'to '/home/oracle/app/oracle/oradata/mmpdb3/tab03.dbf';Database altered.SQL> select file#, CHECKPOINT_CHANGE#, name from v$datafile;FILE# CHECKPOINT_CHANGE# NAME---------- ------------------ ------------------------------------------------------------1 1900834 /home/oracle/app/oracle/oradata/mmpdb3/system01.dbf2 1900834 /home/oracle/app/oracle/oradata/mmpdb3/sysaux01.dbf3 1900834 /home/oracle/app/oracle/oradata/mmpdb3/undotbs01.dbf4 1900834 /home/oracle/app/oracle/oradata/mmpdb3/users01.dbf5 1900834 /home/oracle/app/oracle/oradata/mmpdb3/tab01.dbf6 1900834 /home/oracle/app/oracle/oradata/mmpdb3/tab02.dbf7 1901198 /home/oracle/app/oracle/oradata/mmpdb3/tab03.dbf7 rows selected.SQL> recover database using backup controlfile;ORA-00279: change 1901199 generated at 11/17/2016 05:43:21 needed for thread 1ORA-00289: suggestion : /home/oracle/app/oracle/fast_recovery_area/MMPDB3/archivelog/2016_11_17/o1_mf_1_167_%u_.arcORA-00280: change 1901199 for thread 1 is in sequence #167Specify log: {<RET>=suggested | filename | AUTO | CANCEL}/home/oracle/app/oracle/oradata/mmpdb3/redo02.logLog applied.Media recovery complete.step 6: 查看系统检查点,数据文件与控制文件的SCN,发现系统检查点与数据文件SCN,不一致,用resetlogs的方式打开数据库。
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1900834SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19016102 19016103 19016104 19016105 19016106 19016107 19016107 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19016102 19016103 19016104 19016105 19016106 19016107 19016107 rows selected.SQL> alter database open resetlogs;Database altered.SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#------------------1901614SQL> select File#, checkpoint_change# from v$datafile;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19016142 19016143 19016144 19016145 19016146 19016147 19016147 rows selected.SQL> select file#, checkpoint_change# from v$datafile_header;FILE# CHECKPOINT_CHANGE#---------- ------------------1 19016142 19016143 19016144 19016145 19016146 19016147 19016147 rows selected.