Redo Log File(inactive、active)损坏,处理恢复对策
redolog的生命周期中共有四种状态:
current -> 正在使用的
active -> 非正在使用的,对应的Dirty Block还没有完全写入到数据文件中
inactive -> 非正在使用的,可以覆盖的,Dirty Block已经完全写入。
unused -> 没有使用过的
-- 查看redolog状态
SQL> select group#,status from v$log;
模拟三种状态下redolog丢失,处理方案:
一、inactive 情况 (Inactive表示Dirty Block已经完全写入。)
-- 查看redolog状态
SQL> select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 CURRENT
3 UNUSED
SQL>
col member for a45;
select group#,status,type,member from v$logfile;
GROUP# STATUS TYPE MEMBER
---------- ------- ------- ---------------------------------------------
3 ONLINE /home/oracle/app/oradata/orcl/redo03.log
2 ONLINE /home/oracle/app/oradata/orcl/redo02.log
1 ONLINE /home/oracle/app/oradata/orcl/redo01.log
--模拟 inactive 状态丢失
[oracle@11g orcl]$ rm -rf /home/oracle/app/oradata/orcl/redo01.log
-- inactive 丢失后的数据库症状
[oracle@11g trace]$ tail -f alert_orcl.log
Errors in file /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_m000_25727.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/home/oracle/app/oradata/orcl/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> alter system switch logfile; (多切几次日志后,会话hang住)
SQL> conn andy/andy (用户登录不进去)
ERROR:
ORA-00257: archiver error. Connect internal only, until freed.
Warning: You are no longer connected to ORACLE.
--处理流程
SQL> alter database clear logfile group 1 ;
alter database clear logfile group 1
*
ERROR at line 1:
ORA-00350: log 1 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 1 thread 1: '/home/oracle/app/oradata/orcl/redo01.log'
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 4 NO INACTIVE
2 5 NO INACTIVE
3 6 NO CURRENT
SQL> alter database clear unarchived logfile group 1;
Database altered.
-- 检查redo自否正常创建
[oracle@11g ~]$ cd /home/oracle/app/oradata/orcl/
[oracle@11g orcl]$ ll redo*
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 13:44 redo01.log
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 13:19 redo02.log
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 13:36 redo03.log
SQL> alter system switch logfile;
System altered.
SQL> /
SQL> /
SQL> /
SQL> select group#,sequence#,archived,status from v$log
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 10 YES INACTIVE
2 11 YES INACTIVE
3 12 NO CURRENT
数据库恢复正常,OK。
————————————————————————————————————————————————————————
二、 active 情况 (Active是说日志组已经不是当前日志组,但是Redo Log Entry对应的Dirty Block还没有完全写入到数据文件中。)
--切换日志直至 redolog 的 status 出现 ACTIVE
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 13 YES ACTIVE
2 14 NO CURRENT
3 12 YES ACTIVE
--模拟 ACTIVE 状态的 redolog 丢失
[oracle@11g orcl]$ rm -rf redo01.log
--数据库状态
[oracle@11g trace]$ tail -f alert_orcl.log
Errors in file /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_arc2_23552.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/home/oracle/app/oradata/orcl/redo01.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Master background archival failure: 313
SQL> alter system switch logfile; (多次切换redolog,发现多次以后会话 hang 住)
--处理过程
SQL> select group#,sequence#,archived,status from v$log;
GROUP# SEQUENCE# ARC STATUS
---------- ---------- --- ----------------
1 16 NO INACTIVE
2 17 NO INACTIVE
3 18 NO CURRENT
SQL> alter database clear unarchived logfile group 1;
--检查redolog是否正常生成
[oracle@11g orcl]$ ll redo*
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 14:31 redo01.log
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 14:32 redo02.log
-rw-r-----. 1 oracle oinstall 52429312 Mar 25 14:31 redo03.log
--多次切换日志,看数据库是否正常
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
OK,一切正常。