更多精彩内容尽在 www.leonarding.com
首先我们先看看Active日志特点
Active:表示日志是活动的但不是当前正在使用的redolog,active意味着checkpoint动作尚未完成(脏数据还没有完全刷到磁盘上)or 归档模式下该日志的内容还没有完全归档,这两种情况下都会让日志为active状态,在实例恢复时也会用到此日志文件,因此该日志文件不能被覆盖。
Active和Currentredolog日志有一个共同之处就是实例恢复时会用到这个日志文件 ,它们都是checkpoint检查点还没有完成时保护数据安全的最后屏障,如果它们损坏or勿删除了会导致数据的丢失,这是非常危险的,就算有RMAN备份也不能恢复current 状态的数据。
有的朋友会很奇怪不是说有全库备份就可以完事大吉了嘛!这是一种完美主义,没有一种四海皆准的备份,如果你在RMAN备份时候仔细查看了备份日志就会发现一个惊奇的秘密,RMAN是不会备份
Redolog的,但会备份archivelog,redolog是用多路复用方式镜像备份的,因此如果删除了current 重做日志那么就会丢失数据,我们要警惕这种场景,做一名优秀的DBA!
注:基本上,如果是当前在线日志受损坏,很难不丢数据。但最差的情况下是可以恢复到上一个可用的归档日志时间点的。
恢复方法:
A 使用镜像文件来恢复,不会丢失数据
B 隐含参数_allow_resetlogs_corruption=TRUE 进行不一致性恢复,会丢失数据
C RMAN不完全恢复,有全备,有归档,可以保证数据的一致性,会丢失数据
###################################################################################
A 使用镜像文件来恢复,不会丢失数据
SYS@LEO1>selectgroup#,members,bytes,archived,sequence#,status from v$log;
GROUP# MEMBERS BYTES ARC SEQUENCE# STATUS
-------------------- ---------- --- ---------- ----------------
1 2 52428800 YES 7 INACTIVE
2 2 52428800 NO 9 CURRENT
5 2 52428800 YES 8 INACTIVE
第二组为当前正在使用的redo组
[oracle@leonarding1LEO1]$ mv redo02.log redo02.log.bak 我们改个名字
SYS@LEO1>shutdownabort 我们强制关库,按理说应该使用current log进行实例恢复,但current log备我们删除了,连库都起不来,如何恢复呢
SYS@LEO1>startup 启动的时候是可以正常启动的,但在告警日志里面会报错
ORACLE instancestarted.
Total SystemGlobal Area 471830528 bytes
Fixed Size 2214456 bytes
Variable Size 171967944 bytes
DatabaseBuffers 289406976 bytes
Redo Buffers 8241152 bytes
Database mounted.
Database opened.
DDE:Problem Key 'ORA 313' was flood controlled (0x1) (no incident)
ORA-00313:open failed for members of log group 2 of thread 1
ORA-00313:open failed for members of log group 2 of thread 1
我们很奇怪为什么我们可以启动呢?
SYS@LEO1>selectgroup#,member,status from v$logfile;
GROUP# MEMBER STATUS
------------------------------------------------------------ -------
1/u02/app/oracle/oradata/LEO1/redo01.log
2 /u02/app/oracle/oradata/LEO1/redo02.log INVALID
5 /u02/app/oracle/oradata/LEO1/redo05.log
1/u02/app/oracle/oradata/LEO1/disk2/redo01_b.log
2/u02/app/oracle/oradata/LEO1/disk2/redo02_b.log
5/u02/app/oracle/oradata/LEO1/disk2/redo05_b.log
哦原来第二组有2个成员互为镜像如果第一个成员不可用时oracle就会标记为invalid,把redo数据写入到redo02_b.log第二个成员中继续支持oracle正常运行
SYS@LEO1>altersystem switch logfile;
System altered.
SYS@LEO1>selectgroup#,members,bytes,archived,sequence#,status from v$log;
GROUP# MEMBERS BYTES ARC SEQUENCE# STATUS
-------------------- ---------- --- ---------- ----------------
1 2 52428800 YES 16 INACTIVE
2 2 52428800 NO 18 CURRENT
5 2 52428800 YES 17 ACTIVE
看还可以正常切换,正常使用,但目前只有一个成员可用,也是非常危险的,我们要恢复原状
SYS@LEO1>alterdatabase drop logfile member '/u02/app/oracle/oradata/LEO1/redo02.log';
Database altered.
SYS@LEO1>alterdatabase add logfile member '/u02/app/oracle/oradata/LEO1/redo02.log' to group2;
Database altered.
我们先删除在创建,然后多切换几次,redolog就恢复了
SYS@LEO1>altersystem switch logfile;
System altered.
SYS@LEO1>selectgroup#,member,status from v$logfile;
GROUP# MEMBER STATUS
------------------------------------------------------------ -------
1/u02/app/oracle/oradata/LEO1/redo01.log
2/u02/app/oracle/oradata/LEO1/redo02.log
5 /u02/app/oracle/oradata/LEO1/redo05.log
1/u02/app/oracle/oradata/LEO1/disk2/redo01_b.log
2/u02/app/oracle/oradata/LEO1/disk2/redo02_b.log
5/u02/app/oracle/oradata/LEO1/disk2/redo05_b.log
小结:使用镜像文件来恢复,不会丢失数据,因为没有影响到oracle正常的运行
################################################################################
B 隐含参数_allow_resetlogs_corruption=true 进行不一致性恢复,会丢失数据
第二种方法,我把所有的current log全部改名,看看能否恢复
SYS@LEO1>shutdownabort 强制关库
ORACLE instanceshut down.
[oracle@leonarding1LEO1]$ mv redo02.log redo02.log.bak 修改第一个成员
[oracle@leonarding1disk2]$ mv redo02_b.log redo02_b.log.bak 修改第二个成员
SYS@LEO1>startup 启动库
ORACLE instancestarted.
Total SystemGlobal Area 471830528 bytes
Fixed Size 2214456 bytes
Variable Size 171967944 bytes
DatabaseBuffers 289406976 bytes
Redo Buffers 8241152 bytes
Database mounted.
ORA-00313: openfailed for members of log group 2 of thread 1 打开redo日志失败
ORA-00312: onlinelog 2 thread 1: '/u02/app/oracle/oradata/LEO1/redo02.log' 指明哪个日志
ORA-27037: unableto obtain file status 获取不到日志状态
Linux-x86_64Error: 2: No such file or directory 因为没有这个文件
Additional information:3
ORA-00312: onlinelog 2 thread 1:
'/u02/app/oracle/oradata/LEO1/disk2/redo02_b.log' 第一个成员找不到我们看看第二个成员有没有
ORA-27037: unableto obtain file status
Linux-x86_64Error: 2: No such file or directory 也是没有这个文件对吧
Additionalinformation: 3
SYS@LEO1>selectstatus from v$instance; 现在实例正在处于mount状态
STATUS
------------
MOUNTED
我们可以使用隐含参数_allow_resetlogs_corruption=true 进行不一致恢复,这是oracle给予我们提供的一种临时急救方法,一般不到万不得已不建议使用,因为这样会丢失数据的,而丢失数据是不能接受的。我们继续
SYS@LEO1>altersystem set "_allow_resetlogs_corruption"=true scope=spfile; 静态修改需重启生效
System altered.
SYS@LEO1>shutdownimmediate
ORA-01109:database not open
Databasedismounted.
ORACLE instanceshut down.
SYS@LEO1>startupmount 启动到mount状态
ORACLE instancestarted.
Total SystemGlobal Area 471830528 bytes
Fixed Size 2214456 bytes
Variable Size 171967944 bytes
DatabaseBuffers 289406976 bytes
Redo Buffers 8241152 bytes
Database mounted.
SYS@LEO1>recoverdatabase until cancel;
until cancel:一直恢复到数据库能够恢复的最后一个日志,尽最大努力恢复
场景:current/active log有丢失情况下或者有归档日志丢失的情况下,一直可恢复到丢失前的最后一个日志,则中止。
SYS@LEO1>recoverdatabase until cancel;
ORA-00279: change1056653 generated at 04/30/2013 08:35:09 needed for thread 1
ORA-00289:suggestion : /u02/app/oracle/archdata/1_19_813790699.dbf
ORA-00280: change1056653 for thread 1 is in sequence #19
Specify log:{<RET>=suggested | filename | AUTO | CANCEL}
cancel 这时需手工输入cancel
ORA-10879: errorsignaled in parallel recovery slave
ORA-01547:warning: RECOVER succeeded but OPEN RESETLOGS wouldget error below
ORA-01194: file 1needs more recovery to be consistent
ORA-01110: datafile 1: '/u02/app/oracle/oradata/LEO1/system01.dbf'
需要resetlogs方式开打数据库,也就是非一致性打开
Resetlogs做的几件事:
1)数据文件头scn号为准,同步控制文件和在线日志文件scn号
2)重新创建redolog日志(创建一个空日志),重置为unused
3)重置归档日志序号从1开始编码
-rw-r----- 1oracle asmadmin 222720 Apr 26 21:051_1_813790699.dbf
-rw-r----- 1oracle asmadmin 7168 Apr 30 10:25 1_1_814098124.dbf
4)让数据库重新进入一个新的生命周期
SYS@LEO1>alterdatabase open resetlogs;
alter databaseopen resetlogs
*
ERROR at line 1:
ORA-00603: ORACLEserver session terminated by fatal error 当前会话被终止
ORA-00600:internal error code, arguments: [2662], [0], [1056672], [0],
[1056735],[12583120], [], [], [], [], [], []
ORA-00600:internal error code, arguments: [2662], [0], [1056671], [0],
[1056735],[12583120], [], [], [], [], [], []
ORA-01092: ORACLEinstance terminated. Disconnection forced
ORA-00600:internal error code, arguments: [2662], [0], [1056668], [0],
[1056735],[12583120], [], [], [], [], [], []
Process ID: 9651
Session ID: 125Serial number: 5
SYS@LEO1>startup
ORACLE instancestarted.
Total SystemGlobal Area 471830528 bytes
Fixed Size 2214456 bytes
Variable Size 171967944 bytes
DatabaseBuffers 289406976 bytes
Redo Buffers 8241152 bytes
Database mounted.
Database opened.
SYS@LEO1>selectstatus from v$instance;
STATUS
------------
OPEN
SYS@LEO1>colmember for a50
SYS@LEO1>selectgroup#,member,status from v$logfile;
GROUP# MEMBER STATUS
------------------------------------------------------------ -------
1/u02/app/oracle/oradata/LEO1/disk2/redo01_b.log
2/u02/app/oracle/oradata/LEO1/disk2/redo02_b.log
5/u02/app/oracle/oradata/LEO1/redo05.log
1 /u02/app/oracle/oradata/LEO1/redo01.log
2 /u02/app/oracle/oradata/LEO1/redo02.log
5 /u02/app/oracle/oradata/LEO1/disk2/redo05_b.log
6 rows selected.
SYS@LEO1>selectgroup#,members,bytes,archived,sequence#,status from v$log;
GROUP# MEMBERS BYTES ARC SEQUENCE# STATUS
-------------------- ---------- --- ---------- ----------------
1 2 52428800 YES 1 INACTIVE
2 2 52428800 NO 2 CURRENT
5 2 52428800 YES 0 UNUSED
小结:这种方式打开后的数据库要立刻全备一次,之前的备份已经无效,保证数据的安全性
C RMAN不完全恢复,有全备,有归档,可以保证数据的一致性,会丢失数据,这种方法我们在下面的实验中证明
Leonarding
2013.4.30
天津 &spring
分享技术~成就梦想
Blog:www.leonarding.com