【RMAN】redo文件损坏各种场景恢复

redo文件损坏涉及到多种多样场景,具体场景可以分四大部分:

  1. 按照redo的状态可以分为currentactiveinactive
  2. 按照数据库归档模式可以分为归档和非归档;
  3. 按照脏块有没写入数据文件可以分为有和无;
  4. 按照损坏时数据库的状态可以分为在线和关闭;

按照redo状态维度来介绍各种场景的恢复方法

一、current redo文件恢复介绍:

二、active redo文件恢复介绍:

 

 三、inactive redo文件恢复介绍:

 

 模拟几种恢复方法的操作

   下面主要选取 “current的redo文件在归档模式下采用不正常关闭数据库时还有脏块没有写入数据文件时的损坏” 和 “current的redo文件在非归档模式下数据库在线时还有脏块没有写入数据文件时的损坏” 这两个场景来模拟和恢复,其他场景的恢复请参考上面的恢复操作。

一、current的redo文件在归档模式下采用不正常关闭数据库时还有脏块没有写入数据文件时的损坏模拟恢复:

1、创建一张测试表

SQL> create table test(name varchar2(10));

Table created.

SQL> insert into test values('redo01');

1 row created.

SQL> commit;

2、切换redo

SQL> alter system switch logfile;

3、查看当前redo

SQL>  select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME     CON_ID
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- ----------
         1          1          7  209715200        512          1 NO  CURRENT          2764560       28-JUL-21   1.8447E+19                    0
         2          1          5  209715200        512          1 YES INACTIVE         2764551       28-JUL-21      2764557 28-JUL-21          0
         3          1          6  209715200        512          1 YES INACTIVE         2764557       28-JUL-21      2764560 28-JUL-21          0

4、插入数据,强制关闭数据库

SQL> insert into test values('redo02');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test;

NAME
----------
redo01
redo02

SQL> shutdown abort

5、删除当前redo

[oracle@T1 T1]$ rm -rf /u01/app/oracle/oradata/T1/redo01.log

6、启动到mount,尝试打开数据库会报错

alter database open
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/T1/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7


SQL> alter database clear logfile group 1;
alter database clear logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance T1 (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/T1/redo01.log'


SQL>  alter database clear unarchived logfile group 1;
 alter database clear unarchived logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance T1 (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/T1/redo01.log'


SQL> recover database until cancel;
ORA-00279: change 2764835 generated at 07/28/2021 10:53:21 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle_archive/1_10_1079086598.dbf
ORA-00280: change 2764835 for thread 1 is in sequence #10


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00308: cannot open archived log '/u01/app/oracle_archive/1_10_1079086598.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7


ORA-00308: cannot open archived log '/u01/app/oracle_archive/1_10_1079086598.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7


ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/T1/system01.dbf'


SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/T1/system01.dbf'
View Code

7、设置隐含参数_allow_resetlogs_corruptiontrue,并重启数据库

SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;

System altered.

SQL> shutdown immediate

SQL> startup mount

8、resetlogs方式打开数据库

SQL> alter database open resetlogs;

9、验证数据

SQL> select * from test;

NAME
----------
redo01

-------可以看出数据已经丢失

 

二、current的redo文件在非归档模式下数据库在线时还有脏块没有写入数据文件时的损坏模拟恢复:

1、关闭归档

SQL> archive log list;
Database log mode             No Archive Mode
Automatic archival            Disabled
Archive destination           /u01/app/oracle_archive
Oldest online log sequence    1
Current log sequence          1

2、查看当前redo状态

SQL>  select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME     CON_ID
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- ----------
         1          1          4  209715200        512          1 NO  CURRENT          2764560       28-JUL-21   1.8447E+19                    0
         2          1          2  209715200        512          1 NO  INACTIVE         2764551       28-JUL-21      2764557 28-JUL-21          0
         3          1          3  209715200        512          1 NO  INACTIVE         2764557       28-JUL-21      2764560 28-JUL-21          0

3、创建测试数据

SQL> insert into test values('redo02');

1 row created.

SQL> commit;

Commit complete.

4、删除current的redo01.log文件

[oracle@T1 T1]$ rm -rf /u01/app/oracle/oradata/T1/redo01.log

5、尝试直接通过不归档等方式初始化redo01.log文件,无法初始化current的redo文件

SQL> alter database clear unarchived logfile group 1;
alter database clear unarchived logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance T1 (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/T1/redo01.log'


SQL> alter database clear logfile group 1;
alter database clear logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance T1 (thread 1)
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/T1/redo01.log'
View Code

6、通过将current状态切换到active状态,并初始化redo01.log文件

SQL> alter system switch logfile;

System altered.

SQL> alter database clear logfile group 1;

Database altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME     CON_ID
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- ----------
         1          1          0  209715200        512          1 NO  UNUSED           2764560       28-JUL-21      2764560 28-JUL-21          0
         2          1          5  209715200        512          1 NO  CURRENT          2764551       28-JUL-21   1.8447E+19                    0
         3          1          3  209715200        512          1 NO  INACTIVE         2764557       28-JUL-21      2764560 28-JUL-21          0

7、验证数据,并没有丢失

SQL> select * from test;

NAME
----------
redo01
redo02

 

参考作者:https://blog.csdn.net/liaocongyuan1314

posted @ 2021-07-28 11:28  蟹Bro  阅读(422)  评论(0编辑  收藏  举报