一、不同场景控制文件损坏时的恢复方法
场景 |
恢复方法 |
恢复条件 |
|
其中一个控制文件损坏 |
1.1 拷贝冗余的控制文件 |
1、具有多路冗余控制文件镜像 |
|
1.2 修改control_files参数去除损坏文件 |
同上、但不推荐该方法进行恢复 |
||
所有的控制文件损坏 |
有备份 |
2.1 通过rman备份控制文件进行完全恢复 |
1、通过rman备份了控制文件 |
2.2 通过rman备份控制文件进行不完全恢复 |
1、通过rman备份了控制文件 |
||
2.3 通过trace备份控制文件进行完全恢复 |
1、通过trace备份了控制文件 |
||
2.4 通过trace备份控制文件进行不完全恢复 |
1、通过trace备份了控制文件 |
||
无备份 |
2.5 通过手工重建控制文件进行恢复(noresetlogs) |
1、无有效的备份控制文件 |
|
2.6 通过手工重建控制文件进行恢复(resetlogs) |
1、无有效的备份控制文件 |
||
2.7 通过SNAPSHOT CONTROLFILE文件进行恢复 |
此处为记录一个恢复控制文件的方法(不常使用) |
二、不同场景控制文件损坏的恢复思路及演示
2.1 其中一个控制文件损坏恢复思路
A. shutdown abort 关闭数据库(控制文件损坏后不能正常关闭数据库,只能使用abort强制关闭)
B. 拷贝其中一个完好的控制文件(推荐)或者修改control_files参数去除损坏文件(不推荐)
C. startup启动数据库
2.2 其中一个控制文件损坏恢复演示
SQL> show parameter control_files
NAME TYPE VALUE
---------------------------------------------------------- ------------------------------
control_files string /u/app/oracle/oradata/racdg/control01.ctl,/u/app/oracle/ora
data/racdg/control02.ctl
SQL> !mv/u/app/oracle/oradata/racdg/control02.ctl /u/app/oracle/oradata/racdg/control02.ctl.bak
SQL> shutdown immediate; --无正常关闭数据库,需要abort强制关闭
ORA-00210: cannot open the specifiedcontrol file
ORA-00202: control file:'/u/app/oracle/oradata/racdg/control02.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file ordirectory
Additional information: 3
SQL> shutdown abort; --只能shutdown abort强制关闭
ORACLE instance shut down.
SQL> startup; --启动数据库
ORACLE instance started.
ORA-00205: error in identifying controlfile, check alert log for more info --启动报错,找不到指定的控制文件,在告警日志文件alert_sid.log中可以看到如下报错:
ORA-00210: cannot open the specifiedcontrol file
ORA-00202: control file:'/u/app/oracle/oradata/racdg/control02.ctl'
SQL> !pwd
/u/app/oracle/oradata/racdg
SQL> !cp control01.ctl control02.ctl
--或者:
SQL>alter system set control_files=’ /u/app/oracle/oradata/racdg/control01.ctl’scope=both; --不建议,因为这样一来就只剩一份控制文件了,起不到冗余作用,再此次发生丢失,恢复就变得麻烦了。
SQL> alter database mount;
Database altered.
使用ASM存放控制文件,其中一个控制文件损坏恢复演示
SQL> show parameter control_files;NAME TYPE VALUE----------------------------------------------- ------------------------------control_files string +DATA/racdb/controlfile/current.256.935676497, +DATA/racdb/c ontrolfile/current.478.957977179 SQL> shutdown abort; --这里我是为了演示才直接关闭数据的,因为在线情况下asm的文件是不能删除的ORACLE instance shut down. SQL> !su - grid -c "asmcmd -p rm +DATA/racdb/controlfile/current.478.957977179"Password: SQL> startup nomount; --将数据库启动到nomount状态ORACLE instance started. SQL> !rman target / --这里使用rman来恢复,当然使用之前的两种方法拷贝和去除也是可以的 Recovery Manager: Release 11.2.0.4.0 -Production on Sat Oct 21 16:53:15 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDB (notmounted) RMAN> restore controlfile from'+DATA/racdb/controlfile/current.256.935676497'; --其实这里就是拷贝的方式 Starting restore at 2017/10/21 16:54:18using target database control file insteadof recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=143 instance=racdb1device type=DISK channel ORA_DISK_1: copied control filecopyoutput filename=+DATA/racdb/controlfile/current.256.935676497output filename=+DATA/racdb/controlfile/current.478.957977659Finished restore at 2017/10/21 16:54:22 RMAN> sql 'alter database mount'; sql statement: alter database mountreleased channel: ORA_DISK_1
说明一下,这里我分了文件系统和ASM存储存放控制文件的情况,其恢复原理都是一样的,无论是在线或者关闭数据库后损坏了其中部分控制文件,恢复方法都是一样的。
2.3所有的控制文件损坏,有备份场景
2.3.1通过rman备份控制文件进行完全恢复思路
A. 若在线损坏,shutdown abort关闭数据库;若关闭数据库后损坏,到第二步
B. startup nomount启动数据库到nomount状态。
C. 使用rman从备份中恢复控制文件:restorecontrolfile from '/path';
D. alter database mount;启动数据库到mount状态
E. recover database using backupcontrolfile until cancel; 应用归档文件
F. 再执行recover databaseusing backup controlfile; 应用未归档的redo文件
G. alter database open resetlogs; 以resetlogs的方式打开数据库
2.3.2通过rman备份控制文件进行完全恢复演示
SQL> show parameter control_files;NAME TYPE VALUE---------------------------------------------------------- ------------------------------control_files string /u/app/oracle/oradata/racdg/control01.ctl,/u/app/oracle/oradata/racdg/control02.ctl, /u/app/oracle/oradata/racdg/control03.ctlSQL> !rm control01.ctl control02.ctlcontrol03.ctl --删除所有的控制文件,模拟控制文件丢失 SQL> shutdown abort; --强制关闭数据库ORACLE instance shut down.SQL> startup; --启动数据到nomount状态ORACLE instance started. ORA-00205: error in identifying controlfile, check alert log for more info --报错,同时查看告警日志,会发现所有控制文件都已经丢失。 SQL> !rman target / --此前有做过RMAN控制文件备份,使用rman进行恢复 Recovery Manager: Release 11.2.0.4.0 -Production on Sat Oct 21 17:24:11 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDG (notmounted) RMAN> restore controlfile from'/u/app/oracle/zwdir/RACDG_20171021_0fshj32i_1_1.ctl'; --恢复控制文件 Starting restore at 2017/10/21 17:24:57using target database control file insteadof recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=135 devicetype=DISK channel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete,elapsed time: 00:00:03output filename=/u/app/oracle/oradata/racdg/control01.ctloutput filename=/u/app/oracle/oradata/racdg/control02.ctloutput filename=/u/app/oracle/oradata/racdg/control03.ctlFinished restore at 2017/10/21 17:25:01 RMAN> sql 'alter database mount'; --将数据库启动到mount状态 sql statement: alter database mountreleased channel: ORA_DISK_1 RMAN> exit Recovery Manager complete. SQL> recover database using backupcontrolfile until cancel; ORA-00279: change 1041001 generated at10/21/2017 16:04:25 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_6_957480185.dbfORA-00280: change 1041001 for thread 1 isin sequence #6 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}autoORA-00279: change 1041011 generated at10/21/2017 16:20:36 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_7_957480185.dbfORA-00280: change 1041011 for thread 1 isin sequence #7ORA-00278: log file'/u/app/oracle/oradata/arch/1_6_957480185.dbf' no longer needed for thisrecovery ORA-00279: change 1041019 generated at10/21/2017 16:20:36 needed for thread 1ORA-00289: suggestion : /u/app/oracle/oradata/arch/1_8_957480185.dbfORA-00280: change 1041019 for thread 1 isin sequence #8ORA-00278: log file'/u/app/oracle/oradata/arch/1_7_957480185.dbf' no longer needed for thisrecovery ORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_8_957480185.dbf'ORA-27037: unable to obtain file status --缺少序号为8的归档,这是因为redo还存在归档未切换Linux-x86_64 Error: 2: No such file ordirectoryAdditional information: 3 ORA-01547: warning: RECOVER succeeded butOPEN RESETLOGS would get error belowORA-01194: file 1 needs more recovery to beconsistentORA-01110: data file 1:'/u/app/oracle/oradata/racdg/system01.dbf' SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER---------- ---------- ------------------------------------------------------------------------------------------------ 1 4 YES INACTIVE /u/app/oracle/oradata/racdg/redo01.log 3 6NO CURRENT /u/app/oracle/oradata/racdg/redo03.log --当前未归档的redo文件 2 5 YES INACTIVE /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile; --再次执行,应用未归档的redo文件ORA-00279: change 1041019 generated at10/21/2017 16:20:36 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_8_957480185.dbfORA-00280: change 1041019 for thread 1 isin sequence #8 --这里看到未归档的redo文件,归档序号为6,而这里需要恢复序列为8的归档,所以应该是应用/u/app/oracle/oradata/racdg/redo02.log这个redo文件。 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}/u/app/oracle/oradata/racdg/redo02.logLog applied.Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式打开数据库 Database altered.
resetlogs与noresetlogs的区别说明:
norestlogs控制文件的scn是来自当前日志的highscn,而resetlogs控制文件的scn是来自数据文件。
noresetlogs会继续使用已经存在,且有效的logfiles,而resetlogs会初始化logs,重置log sequence号,创建一个新的incarnation
2.3.3通过rman备份控制文件进行不完全恢复思路
A. 若在线损坏,shutdown abort关闭数据库;若关闭数据库后损坏,到第二步
B. startup nomount启动数据库到nomount状态。
C. 使用rman从备份中恢复控制文件:restorecontrolfile from '/path';
D. alter database mount;启动数据库到mount状态
E. recover database using backupcontrolfile until cancel; 应用尽可能多的归档文件
G. 若丢失redo文件:
shutdown immediate并启动到startupnomount状态
alter database backup controlfile to traceas ‘/u/app/oracle/zwdir/controlfile.sql’; 生成创建控制文件的脚本
使用resetlogs方式创建控制文件
若未归档的redo文件可用:直接recover database,选用未归档的redo应用,alter database open resetlogs方式打开数据库
若未归档的redo文件不可用:设置隐含参数_allow_resetlogs_corruption=true跳过一致性检查,alterdatabase open resetlogs方式打开数据库
F. 若丢失归档文件:
shutdown immediate并启动到startupnomount状态
alter database backup controlfile to traceas ‘/u/app/oracle/zwdir/controlfile.sql’; 生成创建控制文件的脚本
使用noresetlogs方式创建控制文件
recover database using backup controlfileuntil cancel; 应用redo文件
alter database open resetlogs; 以resetlogs的方式打开数据库
若备份控制文件之后,数据库结构发生了变化,如新增了表空间或数据文件,需要进行不完全恢复
2.3.4通过rman备份控制文件进行不完全恢复演示
这里模拟演示模拟备份控制文件之后,新增表空间,归档文件全部丢失的不完全恢复的情况,丢失redo的情况,请看下一节“oracle数据库恢复系列之redo文件恢复”
[oracle@iscsi-asmzwdir]$ rman target / RMAN> backup current controlfile format'/u/app/oracle/zwdir/use_this_%U.ctl' tag='ctl'; --备份当前的控制文件 Starting backup at 2017/10/29 17:03:31using target database control file insteadof recovery catalogpiecehandle=/u/app/oracle/zwdir/use_this_08si88j3_1_1.ctl tag=CTL comment=NONEchannel ORA_DISK_1: backup set complete,elapsed time: 00:00:01Finished backup at 2017/10/29 17:03:33 [oracle@iscsi-asm racdg]$ sqlplus / assysdba SQL> create tablespace t_del_archdatafile '/u/app/oracle/oradata/racdg/t_del_arch01.dbf' size 20m; --新增表空间 Tablespace created. SQL> create user t_arch identified bypassword default tablespace t_del_arch; --新建用户 User created. SQL> grant resource,connect to t_arch; --授权 Grant succeeded. SQL> alter system switch logfile; --切换归档日志 System altered. SQL> create table t_arch.t1 as select *from dba_objects where rownum<1000; --新建表,并插入数据 Table created. SQL> alter system switch logfile; --切换归档日志 System altered. SQL> select count(*) from t_arch.t1; COUNT(*)---------- 999 SQL> insert into t_arch.t1 select * fromt_arch.t1; --新增数据 999 rows created. SQL> commit; Commit complete. SQL> alter system switch logfile; --切换日志 System altered. SQL> select count(*) from t_arch.t1; --记录当前的数据,用作恢复的数据对比 COUNT(*)---------- 1998 SQL> archive log list; --当前归档的序号Database log mode Archive ModeAutomatic archival EnabledArchive destination /u/app/oracle/oradata/archOldest online log sequence 5Next log sequence to archive 7Current log sequence 7 SQL> shutdown abort; --关闭数据库ORACLE instance shut down.SQL> !rm control01.ctl control02.ctl --模拟控制文件丢失 SQL> !mv/u/app/oracle/oradata/arch/*.dbf /u/app/oracle/oradata/arch/tmp --模拟归档文件全部丢失 SQL> startup nomount;ORACLE instance started. SQL> !rman target / Recovery Manager: Release 11.2.0.4.0 -Production on Sun Oct 29 17:19:33 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDG (notmounted) RMAN> restore controlfile from'/u/app/oracle/zwdir/use_this_08si88j3_1_1.ctl'; --通过旧备份控制文件进行恢复 Starting restore at 2017/10/29 17:19:44using target database control file insteadof recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=10 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete,elapsed time: 00:00:01output filename=/u/app/oracle/oradata/racdg/control01.ctloutput filename=/u/app/oracle/oradata/racdg/control02.ctlFinished restore at 2017/10/29 17:19:46 RMAN> exit Recovery Manager complete. SQL> alter database mount; Database altered. SQL> alter database backup controlfileto trace as '/u/app/oracle/zwdir/controlfile.sql'; Database altered. --此时归档文件已经丢失了,无法通过应用归档文件进行恢复,所以通过trc新建控制文件的方式进行恢复。 SQL> shutdown abort; --关闭数据库ORACLE instance shut down.SQL> STARTUP NOMOUNT --启动到nomount状态ORACLE instance started. SQL> CREATE CONTROLFILE REUSE DATABASE"RACDG" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292LOGFILE GROUP 1 '/u/app/oracle/oradata/racdg/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '/u/app/oracle/oradata/racdg/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '/u/app/oracle/oradata/racdg/redo03.log' SIZE 50M BLOCKSIZE 512-- STANDBY LOGFILEDATAFILE '/u/app/oracle/oradata/racdg/system01.dbf', '/u/app/oracle/oradata/racdg/sysaux01.dbf', '/u/app/oracle/oradata/racdg/undotbs01.dbf', '/u/app/oracle/oradata/racdg/users01.dbf'CHARACTER SET WE8MSWIN1252; --以上新建控制文件的内容就是通过/u/app/oracle/zwdir/controlfile.sql里面的记录来进行新建的,里面共有两种方式,一种是noresetlogs,另一种是resetlogs的方式。这里因为redo文件是没有丢失的,所以使用nosesetlogs的方式。 Control file created. SQL> selectb.sequence#,a.member,b.status from v$logfile a, v$log b wherea.group#=b.group#; --查询redo信息 SEQUENCE# MEMBER STATUS------------------------------------------------------- -------------------------------- 7 /u/app/oracle/oradata/racdg/redo01.log CURRENT 5 /u/app/oracle/oradata/racdg/redo02.log INACTIVE 6 /u/app/oracle/oradata/racdg/redo03.log INACTIVE SQL> select file#,name,status fromv$datafile; --查询数据文件信息,此时数据文件都是需要恢复 FILE# NAME STATUS------------------------------------------------------- -------------- 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 2 /u/app/oracle/oradata/racdg/sysaux01.dbf RECOVER 3 /u/app/oracle/oradata/racdg/undotbs01.dbf RECOVER 4 /u/app/oracle/oradata/racdg/users01.dbf RECOVER SQL> recover database using backupcontrolfile until cancel; --恢复数据库,应用redo日志ORA-00279: change 932267 generated at10/29/2017 17:07:56 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_6_958668721.dbfORA-00280: change 932267 for thread 1 is insequence #6 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}/u/app/oracle/oradata/racdg/redo03.logORA-00279: change 932300 generated at10/29/2017 17:09:10 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_7_958668721.dbfORA-00280: change 932300 for thread 1 is insequence #7ORA-00278: log file'/u/app/oracle/oradata/racdg/redo03.log' no longer needed for this recovery Specify log: {<RET>=suggested |filename | AUTO | CANCEL}/u/app/oracle/oradata/racdg/redo01.logLog applied.Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式打开数据库 Database altered. SQL> select file#,name,status fromv$datafile; --查看数据文件的状态,备份控制文件之后的表空间对应的数据文件需要进一步恢复。 FILE# NAME STATUS-------------------------------------------------------------- -------------- 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 3 /u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 5/u/app/oracle/product/11.2.0/db_1/dbs/MISSING00005RECOVER SQL> alter database datafile 5 offline; --先将数据文件offline Database altered. SQL>alter database rename file'/u/app/oracle/product/11.2.0/db_1/dbs/MISSING00005' to'/u/app/oracle/oradata/racdg/t_del_arch01.dbf'; --重命名数据文件 Database altered. SQL> alter tablespace t_del_arch online; ---尝试将表空间online,报错alter tablespace t_del_arch online*ERROR at line 1:ORA-01190: control file or data file 5 isfrom before the last RESETLOGSORA-01110: data file 5: '/u/app/oracle/oradata/racdg/t_del_arch01.dbf' SQL> alter system set"_allow_resetlogs_corruption"=true scope=spfile; --修改参数,忽略SCN一致性校验 System altered. SQL> startup force; --再将数据库重新启动ORACLE instance started. Total System Global Area 830930944 bytesFixed Size 2257800 bytesVariable Size 536874104 bytesDatabase Buffers 285212672 bytesRedo Buffers 6586368 bytesDatabase mounted.Database opened. SQL> selectts#,file#,name,status,checkpoint_change# from v$datafile; --查询数据文件的情况 TS# FILE# NAME STATUS CHECKPOINT_CHANGE#---------- ---------- ----------------------------------------------------------- ------------------ 0 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 953040 1 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 953040 2 3 /u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 953040 4 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 953040 6 5/u/app/oracle/oradata/racdg/t_del_arch01.dbf RECOVER 0 SQL> alter session set events 'immediatetrace name adjust_scn level 1'; --通过设置adjust_scn使数据文件的CHECKPOINT_CHANGE#一致 Session altered. SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SQL> startup mount; --启动到mount状态ORACLE instance started. Total System Global Area 830930944 bytesFixed Size 2257800 bytesVariable Size 536874104 bytesDatabase Buffers 285212672 bytesRedo Buffers 6586368 bytesDatabase mounted.SQL> recover until cancel; --恢复数据库,注意这里不是usingcontrolfile的方式Media recovery complete. SQL> alter database datafile 2,3,4,5online; ---将所有的数据文件online,记得千万不用漏了 Database altered. SQL> alter database open resetlogs; --以resetlogs的方式打开数据库 Database altered. SQL> selectts#,file#,name,status,checkpoint_change# from v$datafile; --查询数据文件的情况 TS# FILE#NAME STATUS CHECKPOINT_CHANGE#---------- ------------------------------------------------------- -------------- ------------------ 0 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 953040 1 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 953040 2 3/u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 953040 4 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 953040 6 5 /u/app/oracle/oradata/racdg/t_del_arch01.dbf ONLINE 953040 SQL> select count(*) from t_arch.t1; --对比数据,发现存在数据丢失,出现这种情况,只能把损失降到最小 COUNT(*)---------- 999 SQL> alter tablespace temp add tempfile'/u/app/oracle/oradata/racdg/temp01.dbf' reuse; --重建temp表空间 Database altered.
2.3.4通过trace备份控制文件进行完全恢复思路
A.备份控制文件到trace:alterdatabase backup controlfile to trace as '/path/controlfile.sql';
B.若在线损坏,直接alterdatabase backup controlfile to 'file';之后重启数据库
C.若关闭数据库后损坏,shutdownabort关闭数据库后,startup nomount启动数据库到nomount状态
D.使用备份到trace里创建控制文件的语句,以noresetlogs方式创建控制文件
E.recover database恢复数据库,恢复完后通过alterdatabase open打开数据库
F.重建temp表空间:altertablespace temp add tempfile '/path/temp01.dbf' reuse;
2.3.5通过trace备份控制文件进行完全恢复演示
oracle数据库提供了多种对控制文件的备份方式:rman、alterdatabase backup controlfile to trace、alter databasebackup controlfile to filename 这里只演示在线损坏时通过alter database backup controlfile to filename 的恢复,因为通过trace备份的恢复演示在“2.3.4通过rman备份控制文件进行不完全恢复演示”章节已经写了。
SQL> select open_mode from v$database; OPEN_MODE----------------------------------------READ WRITE SQL> !rm control01.ctl control02.ctl --这种情况主要是数据库还在运行状态,手贱误删的恢复 SQL> alter database backup controlfileto '/u/app/oracle/oradata/racdg/control01.ctl.bak'; --备份成二进制文件 Database altered. SQL> shutdown abort;ORACLE instance shut down. SQL> !cp control01.ctl.bak control01.ctl�C直接拷贝使用 SQL> !cp control01.ctl.bak control02.ctl SQL> startup mount; --启动到mount状态ORACLE instance started. Total System Global Area 830930944 bytesFixed Size 2257800 bytesVariable Size 536874104 bytesDatabase Buffers 285212672 bytesRedo Buffers 6586368 bytesDatabase mounted. SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER---------- ---------- --------------------- ---------------------------------------- 1 1 NO CURRENT /u/app/oracle/oradata/racdg/redo01.log 3 0 YES UNUSED /u/app/oracle/oradata/racdg/redo03.log 2 0 YES UNUSED /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile until cancel;ORA-00279: change 932699 generated at10/31/2017 19:25:50 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_1_958850748.dbfORA-00280: change 932699 for thread 1 is insequence #1 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}/u/app/oracle/oradata/racdg/redo01.log �C应用redo文件Log applied.Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式开启数据库 Database altered.
2.3.6通过trace备份控制文件进行不完全恢复思路
A.备份控制文件到trace:alterdatabase backup controlfile to trace as '/path/controlfile.sql';
B.shutdown abort关闭数据库后,startupnomount启动数据库到nomount状态
C. 若丢失redo文件,归档未丢失:
使用备份到trace里创建控制文件的语句,以resetlogs方式创建控制文件
alter database mount;启动数据库mount状态
若未归档的redo文件可用:直接recover database,选用未归档的redo应用,alter database open resetlogs方式打开数据库
若未归档的redo文件不可用:设置隐含参数_allow_resetlogs_corruption=true跳过一致性检查,alterdatabase open resetlogs方式打开数据库
D. 若丢失归档文件,redo未丢失:
使用备份到trace里创建控制文件的语句,以resetlogs方式创建控制文件
alter database mount;启动数据库mount状态
recover database using backup controlfileuntil cancel; 应用redo文件
alter database open resetlogs; 以resetlogs的方式打开数据库
若备份控制文件之后,数据库结构发生了变化,如新增了表空间或数据文件,需要进行不完全恢复
E. 若归档文件和redo文件都丢失:
步骤与若丢失归档文件,redo未丢失的恢复步骤一样,主要是以resetlogs方式创建控制文件
F.重建temp表空间:altertablespace temp add tempfile '/path/temp01.dbf' reuse;
2.3.7通过trace备份控制文件进行不完全恢复演示
请参照“2.3.4通过rman备份控制文件进行不完全恢复演示”,主要注意以下几点:
A.trace备份的控制文件并不是实时的备份,可能不是最新的,备份之后数据库结构可能发生了变化
B.对于此类恢复一定需要谨慎,恢复完之后马上做个全备,尽量将数据丢失降低到最小。
2.4所有的控制文件损坏,无备份场景
2.4.1通过手工重建控制文件进行恢复(noresetlogs)思路
A.shutdown abort关闭数据库后,startupnomount启动数据库到nomount状态
B.手工构造控制文件,以noresetlogs方式
C. alter database mount;启动数据库到mount状态
D. recover database using backupcontrolfile until cancel; 应用归档文件
E. 再执行recover databaseusing backup controlfile; 应用未归档的redo文件
F. alter database open resetlogs; 以resetlogs的方式打开数据库
2.4.2通过手工重建控制文件进行恢复(resetlogs)思路
A.shutdown abort关闭数据库后,startupnomount启动数据库到nomount状态
B.手工构造控制文件,以resetlogs方式
C. alter database mount;启动数据库到mount状态
D. recover database using backupcontrolfile until cancel; 应用归档文件(不考虑归档文件丢失)
E. 再执行recover databaseusing backup controlfile; 应用未归档的redo文件(不考虑redo文件丢失)
F. alter database open resetlogs; 以resetlogs的方式打开数据库
2.4.3通过手工重建控制文件进行恢复(resetlogs)演示
这里不作非常具体的演示了,前面的章节已经演示过了,就说明一下需要注意的几点:
因为是手动构建,所以在构建的过程中一定要仔细检查数据库清除数据库有多少文件,构建脚本如下:
CREATE CONTROLFILE REUSE DATABASE"RACDG" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292LOGFILE GROUP 1 '/u/app/oracle/oradata/racdg/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '/u/app/oracle/oradata/racdg/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '/u/app/oracle/oradata/racdg/redo03.log' SIZE 50M BLOCKSIZE 512-- STANDBY LOGFILEDATAFILE '/u/app/oracle/oradata/racdg/system01.dbf', '/u/app/oracle/oradata/racdg/sysaux01.dbf', '/u/app/oracle/oradata/racdg/undotbs01.dbf', '/u/app/oracle/oradata/racdg/users01.dbf', '/u/app/oracle/oradata/racdg/t_del_arch01.dbf'CHARACTER SET WE8MSWIN1252;
一定要都存放文件的路径下去ls �Cltr列一下有哪些文件,千万不要把某个文件漏了。
B. 手动构建控制文件是存在一定的数据丢失风险的,一定得细心,细心,再细心。
2.4.4通过SNAPSHOTCONTROLFILE文件进行恢复思路
A.shutdown abort关闭数据库后,startupnomount启动数据库到nomount状态
B.直接拷贝snapshot controlfile成control file或通过rman恢复:restore controlfile from '$ORACLE_HOME/dbs/snapcf_@.f';
C. alter database mount;启动数据库到mount状态
D. recover database using backupcontrolfile until cancel; 应用归档文件(不考虑归档文件丢失)
E. 再执行recover databaseusing backup controlfile; 应用未归档的redo文件(不考虑redo文件丢失)
F. alter database open resetlogs; 以resetlogs的方式打开数据库
2.4.5通过SNAPSHOTCONTROLFILE文件进行恢复演示
RMAN> show snapshot controlfile name; --查看快照控制文件配置 using target database control file insteadof recovery catalogRMAN configuration parameters for databasewith db_unique_name RACDG are:CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f'; # default--如果是RAC,一般建议将该配置文件配置在ASM或ACFS等共享存储上。 SQL> !rm control01.ctl control02.ctl --模拟控制文件丢失 SQL> shutdown abort; --强制关闭数据库ORACLE instance shut down. SQL> startup nomount; --启动数据库到mount状态ORACLE instance started. SQL> !cp/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f control01.ctl --直接拷贝快照控制文件 SQL> !cp/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f control02.ctl SQL> !ls -ltr control*.ctl-rw-r----- 1 oracle oinstall 9748480Nov 1 18:48 control01.ctl-rw-r----- 1 oracle oinstall 9748480Nov 1 18:48 control02.ctl --或者使用RMAN进行恢复:restorecontrolfile from ‘/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f’; SQL> alter database mount; --启动数据库到mount状态 Database altered. SQL> recover database using backupcontrolfile until cancel; --应该归档文件ORA-00279: change 948557 generated at10/31/2017 22:00:44 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_2_958851405.dbfORA-00280: change 948557 for thread 1 is insequence #2 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}autoORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_4_958851405.dbf'ORA-27037: unable to obtain file statusLinux-x86_64 Error: 2: No such file or directoryAdditional information: 3 ORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_4_958851405.dbf'ORA-27037: unable to obtain file statusLinux-x86_64 Error: 2: No such file ordirectoryAdditional information: 3 ORA-01547: warning: RECOVER succeeded butOPEN RESETLOGS would get error belowORA-01194: file 1 needs more recovery to beconsistentORA-01110: data file 1:'/u/app/oracle/oradata/racdg/system01.dbf' SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER---------- ---------- -------------------------- ------------------------------------------------ 1 1 YES INACTIVE /u/app/oracle/oradata/racdg/redo01.log 3 0 YES UNUSED /u/app/oracle/oradata/racdg/redo03.log 2 2 NO CURRENT /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile until cancel; --应用redo文件ORA-00279: change 948625 generated at11/01/2017 18:41:13 needed for thread 1ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_4_958851405.dbfORA-00280: change 948625 for thread 1 is insequence #4 Specify log: {<RET>=suggested |filename | AUTO | CANCEL}/u/app/oracle/oradata/racdg/redo01.logLog applied.Media recovery complete.SQL> alter database open resetlogs; --以resetlogs的方式开启数据库 Database altered.
总结:
1、从上可以说是涉及到各个场景控制文件的损坏恢复,相对是比较全面的,但生产环境下的恢复情况要比我们预想的复杂的多,应根据各种情况,尽量将损失降低到最小。
2、还有个在linux环境未关库情况下,造成控制文件误删,可通过/proc进程号恢复,这边就不做介绍了。
3、最后得强调一下,有效的备份重于一切,对生产环境存敬畏之心,千万不要存侥幸心理,墨菲定律就在我们身边。
本文出自 “以前,以后” 博客,谢绝转载!