深入理解incarnation
10g引入了一个很重要的功能,就是可以跨越resetlogs进行数据恢复。这就需要我们比较深入的了解一个概念,incarnation。
我们通过下面的几个实验,来说明什么是incarnation,希望能对大家有所帮助。
一 准备实验环境
Version 10.2.0.1.0
Platform winxp
1.1进行一次全备份
Rman target /
backup database include current controlfile;;
1.2以scott建立测试表t,并且插入数据
conn scott/tiger
create table t (tscn number(10));
begin
for i in 1 .. 10 loop
insert into t values(dbms_flashback.get_system_change_number);
commit;
end loop;
end;
/
SQL> select * from t;
TSCN
----------
886010
886013
886015
886017
886019
886020
886022
886024
886026
886027
已选择10行。
二、测试不完全恢复后的完全恢复
2.1 进行一次基于scn的不完全恢复
Rman target /
run {
startup mount force;
set until scn 886019;
restore database;
recover database;
alter database open resetlogs;
}
SQL> select * from t;
TSCN
----------
886010
886013
886015
886017
-- 并不包括886019数据,说明until scn的恢复,并不包括该scn。
2.2 继续插入数据
SQL> begin
2 for i in 1 .. 10 loop
3 insert into t values(dbms_flashback.get_system_change_number);
4 commit;
5 end loop;
6 end;
7 /
SQL> select * from t order by 1;
TSCN
----------
886010
886013
886015
886017
886245
886247
886249
886251
886252
886254
886256
886258
886260
886262
已选择14行。
2.3使用restlogs之前的备份进行完全恢复
run {
startup mount force;
restore database;
recover database;
alter database open ;
}
数据库如愿open;
三、测试再次不完全恢复
再次做不完全恢复,恢复点在上次resetlog点之后
run {
startup mount force;
set until scn 886262;
restore database;
recover database;
alter database open resetlogs;
}
open 没有问题
SQL> select * from t order by 1;
TSCN
----------
886010
886013
886015
886017
886245
886247
886249
886251
886252
886254
886256
886258
886260
已选择13行。
四、尝试恢复到第一次resetlog之前
4.1希望恢复到第一次resetlog之前 scn 886019之前
run {
startup mount force;
set until scn 886013;
restore database;
recover database;
alter database open resetlogs;
}
4.2遇到错误rman-20208
遇到错误
rman>list incarnation;
4.3反清复明,回到incarnation 7.成功open数据库;
reset database to incarnation 7;
run {
startup mount force;
set until scn 886013;
restore database;
recover database;
alter database open resetlogs;
}
成功打开数据库
SQL> select * from t ;
TSCN
----------
886010
rman>list incarnation
4.4总结分析
每一次resetlogs就会使incarnation + 1;
如果想要恢复到之前incarnation的scn,就需要先恢复到之前的incarnation;
至于oracle为什么这么设计,我们通过后面的实验,就能够理解了;
以上实验的过程如下图所示:
rman>list incarnation
五、模拟不完全恢复后再次不完全恢复
5.1重新模拟环境
Delete backup;
Backup database include current controlfile;
Truncate table t;
begin
for i in 1 .. 10000 loop
insert into t values(dbms_flashback.get_system_change_number);
commit;
end loop;
end;
/
SQL> select min(tscn),max(tscn) from t;
MIN(TSCN) MAX(TSCN)
---------- ----------
886422 905307
5.2模拟错误的不完全恢复
我希望恢复到scn 900000 ,可是我现在错误的恢复到890000。看是否还能恢复到900000
rman>list incarnation
run {
startup mount force;
set until scn 890000;
restore database;
recover database;
alter database open resetlogs;
}
SQL> select min(tscn),max(tscn) from t;
MIN(TSCN) MAX(TSCN)
---------- ----------
886422 889997
发现并没有找回我们所希望的数据
5.3再次进行不完全恢复
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
908431
尝试恢复到900000
run {
startup mount force;
set until scn 900000;
restore database;
recover database;
alter database open resetlogs;
}
SQL> select min(tscn),max(tscn) from t;
MIN(TSCN) MAX(TSCN)
---------- ----------
886422 889997
依然并没有恢复到我希望的情况;
5.4反清复明后再进行恢复
rman>list incarnation
startup mount force;
reset database to incarnation 11;
run {
set until scn 900000;
restore database;
recover database;
alter database open resetlogs;
}
SQL> select min(tscn),max(tscn) from t;
MIN(TSCN) MAX(TSCN)
---------- ----------
886422 899997
已经恢复到我所希望的情况了;
5.5总结分析
我之前一直无法理解oracle设置incarnation这个东西干什么用,通过这个实验,我们就能够理解incarnation的作用了;
Incarnation 11 and 12都包括scn 900000 的spot
所以当incarnation 12 做 until scn的时候,是恢复到当前incarcation 的 scn;
但是根据我们的需要,我们需要的是incarnation 11的scn 900000;
所以就需要使用reset database to incarnation 11才能找回我们需要的数据;
rman>list incarnation
后记:
通过以上几个实验,我们能够基本理解incarnation了;
如果实际中需要进行不完全恢复,一定要小心谨慎,因为可能出现更加复杂的情况。比如数据结构不同,控制文件丢失等等都会造成更加混乱的局面,但是只要思路清晰,相信这些都不是问题。
最后,本实验只是出于我个人的理解。如果有什么不正确,以及疑问,欢迎发送邮件到oraclerlee@sohu.com共同讨论学习进步。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14876437/viewspace-580335/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/14876437/viewspace-580335/