视图

v$log
v$v$logfile
分为两种场景恢复
1.数据实例还在运行尚未崩溃
2.数据库实例已经关闭

1.数据实例还在运行尚未崩溃

1.1inactive / unused状态下丢失redo文件 处理方式

  1. alter database clear logfile group 3;

1.2.active状态下丢失redo文件 处理方式

1.切换损坏redo文件到inactive
2将数据刷新到数据文件。
3.重建日志文件

  1. alter system switch logfile;
  2. alter system checkpoint;
  3. alter database clear logfile group 3;

1.3.current状态下丢失redo文件 处理方式

1.切换损坏redo文件到inactive
2将数据刷新到数据文件。
3.重建日志文件,因为系统判断之前丢失redo文件尚未归档,所以需要使用unarchived进行清除重建,重建之后归档日志变为不连续,所以需要进行全备,注意之前所有备份都不能在使用。

  1. alter system switch logfile;
  2. alter system checkpoint;
  3. SQL> alter database clear unarchived logfile group 2;

2.数据库已经崩溃恢复

2.1 inactive / unused状态下丢失redo文件 处理方式

  1. shutdown abort;模拟数据库崩溃
  2. startup mount ;
  3. alter database clear logfile group 3;
  4. alter database open;

2.2active状态下丢失redo文件处理方式

模拟环境
1.创建测试表

  1. create table t as select * from dba_objects;

2.使用视图v$log,查看redo日志组,

  1. select * from v$log;

3.切换redo日志使当前 group 组 current变为active状态,

  1. alter system switch logfile;

4.查询当前数据总数

  1. select count(1) from t;
  2. 74544

5.删除一些数据,记录删除后的数据总数。

  1. delete from t where rownum<1001;
  2. commit
  3. 在查询数据总数
  4. select count(1) from t;
  5. 72544

6.在此查看v$log,记录当前current日志组。

  1. select * from v$log;

5.模拟数据库崩溃丢失active文件
1.shutdown abort;关闭数据库
2.删除组1 active redo文件

  1. SQL> shutdown abort;
  2. ORACLE instance shut down.
  3. [oracle@instance-ej1hspdt alert]$ rm -rf /opt/oracle/oradata/ORCLCDB/redo01.log

6.尝试启动数据库

  1. SQL> startup
  2. ORACLE instance started.
  3. Total System Global Area 838857584 bytes
  4. Fixed Size 8901488 bytes
  5. Variable Size 679477248 bytes
  6. Database Buffers 142606336 bytes
  7. Redo Buffers 7872512 bytes
  8. Database mounted.
  9. ORA-00313: open failed for members of log group 1 of thread 1
  10. ORA-00312: online log 1 thread 1: '/opt/oracle/oradata/ORCLCDB/redo01.log'
  11. ORA-27037: unable to obtain file status
  12. Linux-x86_64 Error: 2: No such file or directory
  13. Additional information: 7

7.使用数据库崩溃之前ative状态redo归档日志恢复
注意:根据网上教程这一步之后可以加隐藏参数,强制启动数据库,但是这样会丢失数据。
之前current日志保存的delete操作无法恢复。

  1. SQL> recover database until cancel;
  2. ORA-00279: change 6998785 generated at 09/11/2019 16:36:26 needed for thread 1
  3. ORA-00289: suggestion :
  4. /opt/oracle/fast_recovery_area/ORCLCDB/archivelog/2019_09_11/o1_mf_1_1_gqkfp4dd_
  5. .arc
  6. ORA-00280: change 6998785 for thread 1 is in sequence #1
  7. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  8. AUTO
  9. ORA-00279: change 7000664 generated at 09/11/2019 16:56:36 needed for thread 1
  10. ORA-00289: suggestion :
  11. /opt/oracle/fast_recovery_area/ORCLCDB/archivelog/2019_09_11/o1_mf_1_2_%u_.arc
  12. ORA-00280: change 7000664 for thread 1 is in sequence #2
  13. ORA-00278: log file
  14. '/opt/oracle/fast_recovery_area/ORCLCDB/archivelog/2019_09_11/o1_mf_1_1_gqkfp4dd
  15. _.arc' no longer needed for this recovery
  16. ORA-00308: cannot open archived log
  17. '/opt/oracle/fast_recovery_area/ORCLCDB/archivelog/2019_09_11/o1_mf_1_2_%u_.arc'
  18. ORA-27037: unable to obtain file status
  19. Linux-x86_64 Error: 2: No such file or directory
  20. Additional information: 7
  21. ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
  22. ORA-01194: file 1 needs more recovery to be consistent
  23. ORA-01110: data file 1: '/opt/oracle/oradata/ORCLCDB/system01.dbf'

8.最后使用数据库崩溃之前current状态redo归档日志恢复

  1. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  2. /opt/oracle/oradata/ORCLCDB/redo02.log
  3. Log applied.
  4. Media recovery complete.

9.resetlogs打开面数据库

  1. SQL> alter database open resetlogs;
  2. Database altered.

10.查看数据是否完全恢复为数据库崩溃前状态
记录为73544,说明在数据库崩溃之前,至此恢复完毕。

  1. SQL> select count(1) from t;
  2. COUNT(1)
  3. ----------
  4. 73544