(Les16 执行数据库恢复)-重做日志文件恢复

丢失重做日志文件
        丢失了重做日志文件组中的某个成员,并且组中至少还有一个成员:
            -不会影响实例的正常操作。
            -预警日志中会收到一条信息,通知您无法找到某个成员
            -可以通过删除丢失的重做日志成员并添加新成员来恢复丢失的日志文件
            -如果包含丢失日志文件的组已归档,您可以清除日志组来重新创建丢失的文件
 
恢复步骤:
       1.确定是否有缺失的日志文件
        2.恢复丢失的文件时,先删除丢失的重做日志成员
            ALTER DATABASE DROP LOGFILE MEMBER '+DATA/orcl/onlinelog/group_1.261.691672257';
        3.然后添加新成员来替代丢失的日志成员
            ALTER DATABASE ADD LOGFILE MEMBER '+DATA' TO GROUP 2;
        4.如果介质故障是由于磁盘或控制器缺失而造成的,需重命名丢失文件。
        5.如果重做日志组已归档,或者处于NOARCHIVELOG模式下,则可选择在清除日志组后重新创建缺失来解决问题,
            ALTER DATABASE CLEAR LOGFILE GROUP n;
        注意:清除未归档的日志组,应立即对整个数据库执行完全备份,否则,在发生其它故障的情况下,会导致数据丢失。
            ALTER DATABASE CLEAR UNARCHIVED  LOGFILE GROUP #;
 
 
 
测试环境中先新增3组,每组2个成员
 
alter database  add logfile group 4  ('/u01/app/oracle/oradata/xiocpt0/p_redo04_01.log','/u01/app/oracle/oradata/xiocpt0/p_redo04_02.log') size 128M;
alter database  add logfile group 5  ('/u01/app/oracle/oradata/xiocpt0/p_redo05_01.log','/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log') size 128M;
alter database  add logfile group 6  ('/u01/app/oracle/oradata/xiocpt0/p_redo06_01.log','/u01/app/oracle/oradata/xiocpt0/p_redo06_02.log') size 128M;

 

 
 
 
set pagesize 600
 
select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
col member format a50
 
select group#,status,member from v$logfile;
 
 
SQL> set pagesize 600
 
select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;--查看重做日志成员状态信息
 
col member format a50
 
 
SQL> SQL>
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1          4                50          1 YES INACTIVE
         2          5                50          1 NO  CURRENT
         3          3                50          1 YES INACTIVE
         4          0               128          2 YES UNUSED
         5          0               128          2 YES UNUSED
         6          0               128          2 YES UNUSED
 
6 rows selected.
 
SQL> select group#,status,member from v$logfile;--查看重做日志成员,物理路径,这里存储方式为文件系统
 
    GROUP# STATUS  MEMBER
---------- ------- --------------------------------------------------
         1 STALE   /u01/app/oracle/oradata/xiocpt0/redo01.log
         3 STALE   /u01/app/oracle/oradata/xiocpt0/redo03.log
         2         /u01/app/oracle/oradata/xiocpt0/redo02.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_01.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_02.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_01.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_01.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_02.log
 
9 rows selected.
 
手动删除group 1的物理文件
 
SQL> !rm /u01/app/oracle/oradata/xiocpt0/redo01.log
 
group 1的状态以归档,INACTIVE
 
SQL> select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1          4                50          1 YES INACTIVE
         2          5                50          1 NO  CURRENT
         3          3                50          1 YES INACTIVE
         4          0               128          2 YES UNUSED
         5          0               128          2 YES UNUSED
         6          0               128          2 YES UNUSED
 
6 rows selected.
 
验证物理文件已被删除
 
SQL> !ls -l  /u01/app/oracle/oradata/xiocpt0/redo01.log
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo01.log: No such file or directory
 
针对已归档的重做日志文件组,可以使用clear命令进行恢复
 
alter database clear logfile group 1;
 
SQL> alter database clear logfile group 1;
 
Database altered.
 
验证物理文件已恢复完成
 
SQL> !ls -l  /u01/app/oracle/oradata/xiocpt0/redo01.log
-rw-r----- 1 oracle dba 52429312 May 22 13:42 /u01/app/oracle/oradata/xiocpt0/redo01.log

 

 
 

 

 
 
切换重做日志文件
 
alter system switch logfile;
alter system checkpoint;
 
 
测试删除重做日志文件组中单个成员
 
SQL>  select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
 
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1          6                50          1 YES INACTIVE
         2          5                50          1 YES INACTIVE
         3          3                50          1 YES INACTIVE
         4          7               128          2 YES INACTIVE
         5          8               128          2 YES INACTIVE
         6          9               128          2 NO  CURRENT
 
 
删除group 5中的 02成员
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
-rw-r----- 1 oracle dba 134218240 May 22 13:42 /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
 
SQL> !rm /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
ls: cannot access /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log: No such file or directory
 
SQL> alter system switch logfile;
 
System altered.
SQL> /
SQL> /
SQL> /
SQL> /
 
SQL>  alter system checkpoint;
 
System altered.
 
 
oracle预警日志文件中提示/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log以不存在,因为重做日志group 5有2个成员,数据依旧正常。
 
 
 
Errors in file /u01/app/oracle/diag/rdbms/xiocpt0/xiocpt0/trace/xiocpt0_arc0_1460.trc:
ORA-00313: open failed for members of log group 5 of thread 1
ORA-00312: online log 5 thread 1: '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Errors in file /u01/app/oracle/diag/rdbms/xiocpt0/xiocpt0/trace/xiocpt0_arc0_1460.trc:
ORA-00313: open failed for members of log group 5 of thread 1
ORA-00312: online log 5 thread 1: '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
 
 
对group有多个成员的,单成员进行修复
 
alter database drop logfile member '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log';
 
alter database add logfile member '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log' to group 5;
 
先将丢失的成员从group中进行删除
SQL> alter database drop logfile member '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log';
 
Database altered.
 
SQL>  select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1         12                50          1 YES INACTIVE
         2         11                50          1 YES INACTIVE
         3         16                50          1 NO  CURRENT
         4         13               128          2 YES INACTIVE
         5         14               128          1 YES INACTIVE
         6         15               128          2 YES INACTIVE
 
6 rows selected.
 
 
再新增成员
SQL> alter database add logfile member '/u01/app/oracle/oradata/xiocpt0/p_redo05_02.log' to group 5;
 
Database altered.
 
SQL>  select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1         12                50          1 YES INACTIVE
         2         11                50          1 YES INACTIVE
         3         16                50          1 NO  CURRENT
         4         13               128          2 YES INACTIVE
         5         14               128          2 YES INACTIVE
         6         15               128          2 YES INACTIVE
 
6 rows selected.
 
 
也可以对整个group 进行clear,但需注意此group 必须已归档
 
SQL> !rm /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
ls: cannot access /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log: No such file or directory
 
SQL> alter database clear logfile group 5;
 
Database altered.
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
-rw-r----- 1 oracle dba 134218240 May 22 13:51 /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
 

 

 
 
丢失当前重做日志文件
        alter database clear unarchived logfile group  #;
 
SQL>  select group#,sequence#,bytes/(1024*1024),members,archived,status from v$log;
 
    GROUP#  SEQUENCE# BYTES/(1024*1024)    MEMBERS ARC STATUS
---------- ---------- ----------------- ---------- --- ----------------
         1         12                50          1 YES INACTIVE
         2         11                50          1 YES INACTIVE
         3         16                50          1 NO  CURRENT
         4         13               128          2 YES INACTIVE
         5          0               128          2 YES UNUSED
         6         15               128          2 YES INACTIVE
 
6 rows selected.
 
SQL>
SQL> select group#,status,member from v$logfile;
 
    GROUP# STATUS  MEMBER
---------- ------- --------------------------------------------------
         1         /u01/app/oracle/oradata/xiocpt0/redo01.log
         3         /u01/app/oracle/oradata/xiocpt0/redo03.log
         2         /u01/app/oracle/oradata/xiocpt0/redo02.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_01.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_02.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_01.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_01.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_02.log
 
9 rows selected.
 
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/redo03.log
 
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo03.log
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo03.log: No such file or directory
 
SQL> alter system switch logfile;
 
System altered.
 
SQL>  alter system  checkpoint;
 
System altered.
 
SQL> alter database clear unarchived logfile group 3;
 
Database altered.
 
SQL>  select group#,status,member from v$logfile;
 
    GROUP# STATUS  MEMBER
---------- ------- --------------------------------------------------
         1         /u01/app/oracle/oradata/xiocpt0/redo01.log
         3         /u01/app/oracle/oradata/xiocpt0/redo03.log
         2         /u01/app/oracle/oradata/xiocpt0/redo02.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_01.log
         4         /u01/app/oracle/oradata/xiocpt0/p_redo04_02.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_01.log
         5         /u01/app/oracle/oradata/xiocpt0/p_redo05_02.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_01.log
         6         /u01/app/oracle/oradata/xiocpt0/p_redo06_02.log
 
9 rows selected.
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo03.log
-rw-r----- 1 oracle dba 52429312 May 22 13:52 /u01/app/oracle/oradata/xiocpt0/redo03.log
 

 

 
posted @ 2018-05-22 14:24  请点..头像  阅读(307)  评论(0编辑  收藏  举报