实验环境:red hat 5.8
oracle环境:11.2.0.3
历史日志没有被覆盖,只坏一个文件。
非归档模式,不能offline数据文件,即不能用高可用模式,只能转储,恢复,开库并进行恢复。
1、确认数据库是否为归档模式,如果是,则改为非归档模式。
sys@TEST0910> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 53
Next log sequence to archive 55
Current log sequence 55
sys@TEST0910> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TEST0910> startup mount;
ORACLE instance started.
Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 587203928 bytes
Database Buffers 1895825408 bytes
Redo Buffers 20078592 bytes
Database mounted.
sys@TEST0910> alter database noarchivelog;
Database altered.
sys@TEST0910> alter database open;
Database altered.
sys@TEST0910> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 53
Current log sequence 55
sys@TEST0910> select log_mode from v$database;
LOG_MODE
------------
NOARCHIVELOG
2、重新备份,非归档模式下,只能做冷备份。
冷备份脚本参考:http://blog.csdn.net/rlhua/article/details/11850445
sys@TEST0910> @/u01/app/oracle/bak/cold_bak.sql
host cp /u01/app/oracle/oradata/test0910/disk1/users01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/example01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/lxtb01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/sysaux01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/system01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/testtb.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/undotbs01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/fast_recovery_area/test0910/control02.ctl /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/control01.ctl /u01/app/oracle/bak/cold_bak
Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.
Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 587203928 bytes
Database Buffers 1895825408 bytes
Redo Buffers 20078592 bytes
Database mounted.
Database opened.
3、插入三次数据,分别是提交切换日志,提交不切日志,不提交不切日志。
sys@TEST0910> select count(*) from scott.test5;
COUNT(*)
----------
14
sys@TEST0910> insert into scott.test5 select * from scott.emp;
14 rows created.
sys@TEST0910> commit;
Commit complete.
sys@TEST0910> alter system switch logfile;
System altered.
sys@TEST0910> select count(*) from scott.test5;
COUNT(*)
----------
28
sys@TEST0910> insert into scott.test5 select * from scott.emp;
14 rows created.
sys@TEST0910> commit;
Commit complete.
sys@TEST0910> select count(*) from scott.test5;
COUNT(*)
----------
42
sys@TEST0910> insert into scott.test5 select * from scott.emp;
14 rows created.
sys@TEST0910> select count(*) from scott.test5;
COUNT(*)
----------
56
4、模拟断电
sys@TEST0910> shutdown abort;
ORACLE instance shut down.
5、删除文件
[oracle@rtest ~]$ rm /u01/app/oracle/oradata/test0910/disk1/users01.dbf
[oracle@rtest ~]$ ls /u01/app/oracle/oradata/test0910/disk1/users01.dbf
ls: /u01/app/oracle/oradata/test0910/disk1/users01.dbf: No such file or directory
6、起库,报错,查询丢失的数据文件
sys@TEST0910> startup;
ORACLE instance started.
Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 587203928 bytes
Database Buffers 1895825408 bytes
Redo Buffers 20078592 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/test0910/disk1/users01.dbf'
sys@TEST0910> select file#,error from v$recover_file;
FILE# ERROR
---------- -----------------------------------------------------------------
4 FILE NOT FOUND
7、转储数据文件
[oracle@rtest ~]$ cp /u01/app/oracle/bak/cold_bak/users01.dbf /u01/app/oracle/oradata/test0910/disk1/users01.dbf
8、恢复,开库
Media recovery complete.
sys@TEST0910> alter database open;
Database altered.
sys@TEST0910> select count(*) from scott.test5;
COUNT(*)
----------
42