incarnation在英文中是“化身”的意思。

那么在oracle中,它又是什么意思呢?有什么作用呢?

我们看一些基本概念

Current Incarnation(当前化身):数据库当前正在使用的化身。

Parent Incarnation(父化身):数据库当前化身的上一个化身。在父化身以 OPEN RESETLOGS 打开后,就生成当前化身。

Ancestor Incarnation(祖辈化身):在父化身之前,辗转生成父化身的各个化身。

Direct Ancestral Path(直接祖辈路径 / 宗谱):由数据库的起始化身辗转生成至当前化身的分支路径,包含数据库的历代祖辈及父化身。

Orphan Incarnation(孤儿化身):不在数据库当前化身的宗谱上的数据库其它化身。

Orphaned Backups(孤儿备份):不是数据库当前化身的宗谱上生成的数据库备份。当前化身不能使

首先,我们可以来看一张图,来对incarnation有个基本的了解

转 LIST INCARNATION OF DATABASE_完全恢复


如图,SCN1到SCN1000过程中,数据库属于incarnation 1,一直发展到横向的SCN 2000,做了不完全恢复到了SCN 1000,此时SCN1000之后到横向的SCN2000的便是(孤儿化身)。而SCN1000向上面的SCN2000发展形成incarnation 2。incarnation 1便是incarnation 2的(父辈化身)。

而SCN2000往上继续发展到SCN3000时,又做了不完全恢复到SCN2000,SCN2000继续横向发展到SCN3000,形成incarnation 3.所以incarnation 1便是incarnation 3的(祖辈化身),incarnation 2便是incarnation 1的(祖辈化身)。

所有incarnation 1到 incarnation 3 的这条灰色轨迹便是Direct Ancestral Path。

Incarnation 1 中 SCN 1000 之后的所有备份 和Incarnation 2 中 SCN 2000 之后的所有备份便是孤儿备份。

自此应该能够对Incarnation又大概的了解了吧。

下面我们来通过实验来了解下

RMAN> backup as compressed backupset database plus archivelog delete all input;

RMAN> list incarnation;

List of Database Incarnations

DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1 1 ORCL 1446008355 PARENT 1 18-SEP-11

2 2 ORCL 1446008355 PARENT 787897 26-JUL-16

3 3 ORCL 1446008355 PARENT 885125 03-AUG-16

4 4 ORCL 1446008355 PARENT 886406 13-AUG-16

5 5 ORCL 1446008355 CURRENT 906785 15-AUG-16


[oracle@linfan ~]$ sqlplus / as sysdba


SQL> grant dba to scott;


Grant succeeded.


SQL> begin

for i in 1 .. 10 loop

insert into test select current_scn from v$database;

commit;

end loop;

end; 2 3 4 5 6

7 /


SQL> select * from test;


CUR_SCN

----------

1400123

1400126

1400129

1400132

1400135

1400138

1400141

1400144

1400147

1400150


10 rows selected.

rman target /

RMAN> run {

startup mount force;

set until scn 1400138;

restore database;

recover database;

alter database open resetlogs;

}

查看数据,发现还原成功

SQL> select * from test;


CUR_SCN

----------

1400123

1400126

1400129

1400132

1400135

查看以下incarnation

RMAN> list incarnation ;

List of Database Incarnations

DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1 1 ORCL 1446008355 PARENT 1 18-SEP-11

2 2 ORCL 1446008355 PARENT 787897 26-JUL-16

3 3 ORCL 1446008355 PARENT 885125 03-AUG-16

4 4 ORCL 1446008355 PARENT 886406 13-AUG-16

5 5 ORCL 1446008355 PARENT 906785 15-AUG-16

6 6 ORCL 1446008355 CURRENT 1400139 05-DEC-16

发现诞生了DB为6的incarnation,5号已经成为PARENT


再次执行之前的存储过程

SQL> select * from test;


CUR_SCN

----------

1400123

1400126

1400129

1400132

1400135

1400972

1400975

1400978

1400981

1400984

1400987


CUR_SCN

----------

1400990

1400993

1400995

1400999


15 rows selected.


再次进行不完全恢复

RMAN> run {

startup mount force;

set until scn 1400990;

restore database;

recover database;

alter database open resetlogs;

}

恢复成功,演化出了DB为7的incarnation

RMAN> list incarnation ;


List of Database Incarnations

DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1 1 ORCL 1446008355 PARENT 1 18-SEP-11

2 2 ORCL 1446008355 PARENT 787897 26-JUL-16

3 3 ORCL 1446008355 PARENT 885125 03-AUG-16

4 4 ORCL 1446008355 PARENT 886406 13-AUG-16

5 5 ORCL 1446008355 PARENT 906785 15-AUG-16

6 6 ORCL 1446008355 PARENT 1400139 05-DEC-16

7 7 ORCL 1446008355 CURRENT 1400991 05-DEC-16

查看test表

SQL> select * from test;


CUR_SCN

----------

1400123

1400126

1400129

1400132

1400135

1400972

1400975

1400978

1400981

1400984

1400987


11 rows selected.

此时,我们若是想还原到1400132的状态,可以实现吗?

注:1400132是DB为5的incarnation下的SCN

RMAN> run {

startup mount force;

set until scn 1400132;

restore database;

recover database;

alter database open resetlogs;

}

很遗憾地,爆出了RMAN-20208的错误。

Starting restore at 05-DEC-16

using target database control file instead of recovery catalog

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of restore command at 12/05/2016 17:10:14

RMAN-20208: UNTIL CHANGE is before RESETLOGS change

那么怎么解决RMAN-20208的错误呢

要回到DB为5的incarnation,再进行恢复

RMAN> reset database to incarnation 5;


database reset to incarnation 5

RMAN> run {

startup mount force;

set until scn 1400132;

restore database;

recover database;

alter database open resetlogs;

}

RMAN> list incarnation ;

List of Database Incarnations

DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1 1 ORCL 1446008355 PARENT 1 18-SEP-11

2 2 ORCL 1446008355 PARENT 787897 26-JUL-16

3 3 ORCL 1446008355 PARENT 885125 03-AUG-16

4 4 ORCL 1446008355 PARENT 886406 13-AUG-16

5 5 ORCL 1446008355 PARENT 906785 15-AUG-16

8 8 ORCL 1446008355 CURRENT 1400133 05-DEC-16

6 6 ORCL 1446008355 ORPHAN 1400139 05-DEC-16

7 7 ORCL 1446008355 ORPHAN 1400991 05-DEC-16

SQL> select * from test;


CUR_SCN

----------

1400123

1400126

1400129

由此可见,数据已经还原到之前状态,演化出DB为8的化身,DB为6和7的化身变成了孤儿化身(ORPHAN),数据库恢复成功。


总结:如果想要恢复到之前 incarnation 的 scn,就需要先切换到之前的 incarnation