解决方案:
1. 先将控制文件二进制备份。
2. 新建表空间tbs1。
3. 异常关闭数据库,控制文件trace,Recover database 打开数据库。
4. 异常关闭数据库,丢失tbs1数据文件!
5. 应用二进制备份控制文件,还原各个控制文件!
6. 启动mount数据库,并应用恢复控制文件,再恢复数据文件!
7. 更改unnamed的数据文件到tbs1,应用日志并恢复!
8. resetlogs数据库!
实验步骤:
1) SQL>alter database backup controlfile to '/tmp/ctl.bak';
2) SQL>select to_char(CONTROLFILE_CREATED,'yyyy-mm-dd hh24:mi:ss'),CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE# from v$database;(查看当前SCN)
3) SQL>select FILE#,status,CHECKPOINT_CHANGE#,name from v$datafile;(查看控制文件信息)
4) SQL>select dbms_flashback.get_system_change_number scn from dual;(当前SCN)
5) SQL> create tablespace tbs01 datafile '/tmp/tbs01.dbf' size 10m;(新建表空间)
6) select to_char(CONTROLFILE_CREATED,'yyyy-mm-dd hh24:mi:ss'),CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE# from v$database;(验证控制文件的创建时间和系统检查点SCN没有变化,但是控制文件的SCN发生变化)
7) SQL> select FILE#,status,CHECKPOINT_CHANGE#,name from v$datafile; (控制文件的datafilecheckpoint scn;验证新建文件的检查点SCN就是控制文件的SCN);
8) SQL> create table t1 (scn int) tablespace tbs01;
SQL> insert into t1
2 select dbms_flashback.get_system_change_number
3 from (select rownum from dba_objects where rownum <= 100) a,
4 (select rownum from dba_objects where rownum <= 100) b;(表空间tbs01 模拟DML) ;
9) SQL> alter system checkpoint;
10) SQL> select to_char(CONTROLFILE_CREATED,'yyyy-mm-dd hh24:mi:ss'),CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE# from v$database; (控制文件SCN和数据文件的系统检查点都更新最新)
11) SQL> shutdown abort(异常关闭数据库)
12) SQL> STARTUP NOMOUNT
13) SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 908
7 LOGFILE
8 GROUP 1 '/opt/app/oracle/oradata/orcl/redo01.log' SIZE 200M,
9 GROUP 2 '/opt/app/oracle/oradata/orcl/redo02.log' SIZE 200M,
10 GROUP 3 '/opt/app/oracle/oradata/orcl/redo03.log' SIZE 200M
11 DATAFILE
12 '/opt/app/oracle/oradata/orcl/system01.dbf',
13 '/tmp/test.dbf',
14 '/opt/app/oracle/oradata/orcl/sysaux01.dbf',
15 '/opt/app/oracle/oradata/orcl/users01.dbf',
16 '/opt/app/oracle/oradata/orcl/undotbs01.dbf',
17 '/tmp/tbs01.dbf'
18 CHARACTER SET ZHS16GBK
19 ;(模拟控制文件丢失,用trace脚本创建控制文件)
14) SQL> recover database ;
Media recovery complete.
SQL> alter database open;
Database altered.(控制文件恢复,数据库正常打开)
15) SQL> select to_char(CONTROLFILE_CREATED,'yyyy-mm-dd hh24:mi:ss'),CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE# from v$database;(控制文件创建时间发生变化)
16) SQL> select name from v$datafile where CREATION_TIME < (select CONTROLFILE_CREATED from V$database); (所有数据文件的创建时间都早于控制文件创建时间,控制文件无法create datafile的)
17) SQL> SHUTDOWN ABORT;(再次异常关闭数据库)
18) SQL> host mv /tmp/tbs01.dbf /tmp/tbs01.bak(文件丢失)
19) SQL> startup mount(启动)
20) SQL> alter database create datafile
2 '/tmp/tbs01.dbf';(tbs01的创建时间<控制文件创建时间,创建不成功!)
21) SQL> show parameter control_files(查看控制文件的镜像有多个)
22) SQL> ! cp /tmp/ctl.bak /opt/app/oracle/oradata/orcl/control01.ctl
SQL> ! cp /tmp/ctl.bak /opt/app/oracle/oradata/orcl/control02.ctl
SQL> ! cp /tmp/ctl.bak /opt/app/oracle/oradata/orcl/control03.ctl (使用最早做二进制备份还原回去)
23) SQL> startup force mount
ORACLE instance started.
Total System Global Area 1258291200 bytes
Fixed Size 778660 bytes
Variable Size 367271516 bytes
Database Buffers 889192448 bytes
Redo Buffers 1048576 bytes
ORA-01991: invalid password file '/opt/app/oracle/product/10.1.0/db_1/dbs/orapworcl' (mount备份的控制文件,控制文件重置过,因此报错!)
24) SQL> select to_char(CONTROLFILE_CREATED,'yyyy-mm-dd hh24:mi:ss'),CONTROLFILE_CHANGE#,CHECKPOINT_CHANGE# from v$database;(控制文件备份时的SCN)!
25) SQL> alter database create datafile '/tmp/tbs01.dbf';
alter database create datafile '/tmp/tbs01.dbf'
*
ERROR at line 1:
ORA-01516: nonexistent log file, datafile, or tempfile "/tmp/tbs01.dbf"(不能直接创建数据文件信息,控制文件没有此文件的任何信息)!
26) SQL> select FILE#,checkpoint_change#,recover, fuzzy from v$datafile_header;(验证需要先恢复控制文件,在恢复数据文件,两者的SCN数据文件大)
27) SQL> recover database using backup controlfile ;
ORA-00279: change 5970417298930 generated at 09/29/2011 16:39:29 needed for thread 1
ORA-00289: suggestion : /opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_09_29/o1_mf_1_16_%u_.arc
ORA-00280: change 5970417298930 for thread 1 is in sequence #16
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to controlfile by media recovery
ORA-01110: data file 6: '/tmp/tbs01.dbf' (恢复控制文件,并确定出现unnamed数据文件)
28) SQL> select name from v$datafile where CREATION_TIME > (select CONTROLFILE_CREATED from V$database);
NAME
-------------------------------------------------------
/opt/app/oracle/oradata/orcl/undotbs01.dbf
/opt/app/oracle/product/10.1.0/db_1/dbs/UNNAMED00006
29) SQL> alter database create datafile 'UNNAMED00006' as '/tmp/tbs01.dbf';(修改unnamed的数据文件信息)!
30) SQL> recover database using backup controlfile;
ORA-00279: change 5970417320227 generated at 09/29/2011 17:05:05 needed for thread 1
ORA-00289: suggestion : /opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_09_29/o1_mf_1_17_%u_.arc
ORA-00280: change 5970417320227 for thread 1 is in sequence #17
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/opt/app/oracle/oradata/orcl/redo01.log
Log applied.
Media recovery complete.(应用日志文件信息)
31) SQL> alter database open resetlogs;
Database altered.
SQL> select count(*) from t1;
COUNT(*)
----------
10000(resetlogs数据库)
32) 恢复完成