每次以resetlogs选项打开数据库时一个新的数据库incarnation就会被创建。执行open resetlogs操作时就会对当前的联机重做日志文件进行归档。incarnation会将重做日志序列号设置为1,并且指联机重做日志一个新的时间戳。它也会增加incarnation的序号,它被用来唯一标记和识另重做日志流。

什么情况下使用
在使用了open resetlogs之后,但是想恢复到resetlogs之前的时间点的数据,这时可以使用ancestor incarnation。

incarnation(分身):就是数据库由于resetlogs之后,在不同时间点的版本

incarnation可能存在的几种关系
1.current incarnation是由那个incarnation执行open resetlog操作产生的,那个incarnation就是current incarnation的parent incarnation

2.parent incarnation和它parent incarnation的incarnation就叫作current incarnation的ancestor incarnations

3.如果两个incarnation共享相同的ancestor那么它们就是sibling incarnations

SQL> select * from v$database_incarnation;

INCARNATION# RESETLOGS_CHANGE# RESETLOGS_TI PRIOR_RESETLOGS_CHANGE# PRIOR_RESETL STATUS RESETLOGS_ID PRIOR_INCARNATION# FLASHBACK_DATABASE_ALLOWED


       1                 1 30-JUN-05                          0              PARENT     562360180                  0 NO2            446075 05-SEP-14                          1 30-JUN-05    PARENT     857466832                  1 NO3           2849317 27-JAN-15                     446075 05-SEP-14    PARENT     870102602                  2 NO4           2880152 27-JAN-15                    2849317 27-JAN-15    PARENT     870133266                  3 NO5           3017109 01-FEB-15                    2880152 27-JAN-15    PARENT     870550288                  4 NO6           3041066 01-FEB-15                    3017109 01-FEB-15    PARENT     870563157                  5 NO7           3041350 01-FEB-15                    3041066 01-FEB-15    PARENT     870564201                  6 YES8           3111834 03-FEB-15                    3041350 01-FEB-15    ORPHAN     870724654                  7 YES9           3111834 03-FEB-15                    3041350 01-FEB-15    ORPHAN     870726369                  7 YES10           3114665 03-FEB-15                    3041350 01-FEB-15    ORPHAN     870726883                  7 YES11           3114664 03-FEB-15                    3041350 01-FEB-15    CURRENT    870729934                  7 YES

11 rows selected.

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 1 TEST 2155613261 PARENT 1 30-JUN-05
2 2 TEST 2155613261 PARENT 446075 05-SEP-14
3 3 TEST 2155613261 PARENT 2849317 27-JAN-15
4 4 TEST 2155613261 PARENT 2880152 27-JAN-15
5 5 TEST 2155613261 PARENT 3017109 01-FEB-15
6 6 TEST 2155613261 PARENT 3041066 01-FEB-15
7 7 TEST 2155613261 PARENT 3041350 01-FEB-15
8 8 TEST 2155613261 ORPHAN 3111834 03-FEB-15
9 9 TEST 2155613261 ORPHAN 3111834 03-FEB-15
11 11 TEST 2155613261 CURRENT 3114664 03-FEB-15
10 10 TEST 2155613261 ORPHAN 3114665 03-FEB-15

使用current incarnation来执行按时间点恢复
使用current incarnation执行按时间点恢复时是使用的当前版本的控制文件。当执行按时间点恢复时,可以使用set until命令来设置恢复的目标时间,而不用对restotre和recover命令单独设置until子句从而避免出错。这能确保从备份中还原的数据文件的时间戳早于后续的recover操作。

使用ancestor incarnation执行按时间点恢复
使用ancestor incarnation执行按时间点恢复与使用current incarnation的不同之处在于需要设置数据库的incarnation.并且必须从包含恢复目标SCN的incarnation中还原控制文件。

不使用recover catalog的情况
比如我们要将数据库恢复到scott用户的emp表被删除之后的时间点,对older incarnation执行按时间点恢复的过程如下:

1.判断要使用的incarnation。可以使用list incarnation命令来找到恢复目标时间所对应的incarnation

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 1 TEST 2155613261 PARENT 1 2005-06-30 19:09:40
2 2 TEST 2155613261 PARENT 446075 2014-09-05 09:13:52
3 3 TEST 2155613261 PARENT 2849317 2015-01-27 15:10:02
4 4 TEST 2155613261 PARENT 2880152 2015-01-27 23:41:06
5 5 TEST 2155613261 PARENT 3017109 2015-02-01 19:31:28
6 6 TEST 2155613261 PARENT 3041066 2015-02-01 23:05:57
7 7 TEST 2155613261 PARENT 3041350 2015-02-01 23:23:21
8 8 TEST 2155613261 ORPHAN 3111834 2015-02-03 19:57:34
9 9 TEST 2155613261 ORPHAN 3111834 2015-02-03 20:26:09
11 11 TEST 2155613261 PARENT 3114664 2015-02-03 21:25:34
10 10 TEST 2155613261 ORPHAN 3114665 2015-02-03 20:34:43
12 12 TEST 2155613261 PARENT 3142278 2015-02-04 11:40:02
13 13 TEST 2155613261 PARENT 3144077 2015-02-04 13:09:03
14 14 TEST 2155613261 CURRENT 3144537 2015-02-04 13:32:41

当前的incarnation的Inc Key为14.通过下面的查询可以找到它之前的incarnation的Inc Key为13:

SQL> select prior_incarnation# from v$database_incarnation where status =‘CURRENT’;

PRIOR_INCARNATION#

2.将数据库启动到mount状态

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area 327155712 bytes

Fixed Size 1273516 bytes
Variable Size 138412372 bytes
Database Buffers 184549376 bytes
Redo Buffers 2920448 bytes

3.将数据库test的incarnation设置为incarnation号为13,也就是current incarnation的parent incarnation。

RMAN> reset database to incarnation 13;

database reset to incarnation 13

4.执行还原与恢复,设置恢复目标时间,如果没有配置相关通道设置通道。将数据库恢复到表emp删除之后的时间点(2015-02-04 13:30:01):

RMAN> run
2> {
3> set until time ‘2015-02-04 13:30:01’;
4> restore database;
5> recover database;
6> }

executing command: SET until clause

Starting restore at 2015-02-04 13:54:37
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/test/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/test01.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/test/testbak.dbf
channel ORA_DISK_1: reading from backup piece /u02/test_df870779983_s135_s1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u02/test_df870779983_s135_s1 tag=TAG20150204T111943
channel ORA_DISK_1: restore complete, elapsed time: 00:02:37
Finished restore at 2015-02-04 13:57:14

Starting recover at 2015-02-04 13:57:14
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u02/1_3_870729934.dbf
archive log thread 1 sequence 4 is already on disk as file /u02/1_4_870729934.dbf
archive log thread 1 sequence 1 is already on disk as file /u02/1_1_870781202.dbf
archive log filename=/u02/1_3_870729934.dbf thread=1 sequence=3
archive log filename=/u02/1_4_870729934.dbf thread=1 sequence=4
archive log filename=/u02/1_1_870781202.dbf thread=1 sequence=1
archive log filename=/u02/1_1_870786543.dbf thread=1 sequence=1
media recovery complete, elapsed time: 00:00:03
Finished recover at 2015-02-04 13:57:18

RMAN> alter database open resetlogs;

database opened

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 1 TEST 2155613261 PARENT 1 2005-06-30 19:09:40
2 2 TEST 2155613261 PARENT 446075 2014-09-05 09:13:52
3 3 TEST 2155613261 PARENT 2849317 2015-01-27 15:10:02
4 4 TEST 2155613261 PARENT 2880152 2015-01-27 23:41:06
5 5 TEST 2155613261 PARENT 3017109 2015-02-01 19:31:28
6 6 TEST 2155613261 PARENT 3041066 2015-02-01 23:05:57
7 7 TEST 2155613261 PARENT 3041350 2015-02-01 23:23:21
8 8 TEST 2155613261 ORPHAN 3111834 2015-02-03 19:57:34
9 9 TEST 2155613261 ORPHAN 3111834 2015-02-03 20:26:09
11 11 TEST 2155613261 PARENT 3114664 2015-02-03 21:25:34
10 10 TEST 2155613261 ORPHAN 3114665 2015-02-03 20:34:43
12 12 TEST 2155613261 PARENT 3142278 2015-02-04 11:40:02
13 13 TEST 2155613261 PARENT 3144077 2015-02-04 13:09:03
14 14 TEST 2155613261 ORPHAN 3144537 2015-02-04 13:32:41
15 15 TEST 2155613261 CURRENT 3144674 2015-02-04 13:58:43

使用recover catalog的情况
比如我们要将数据库恢复到scott用户的emp表被删除之后的时间点,对older incarnation执行按时间点恢复的过程如下:

1.判断要使用的incarnation。可以使用list incarnation命令来找到恢复目标时间所对应的incarnation

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 8 TEST 2168949517 PARENT 1 2010-04-19 10:22:46
1 2 TEST 2168949517 PARENT 383537 2015-02-04 17:44:49
1 102 TEST 2168949517 PARENT 415176 2015-02-04 18:22:16
1 188 TEST 2168949517 CURRENT 415481 2015-02-04 18:33:17

当前的incarnation的Inc Key为188.通过下面的查询可以找到它之前的incarnation的Inc Key为102:我们将数据库恢复到2015-02-04 18:22:30,也就是在SCN:415176和SCN:415481之间。

RMAN> list backup of controlfile;

List of Backup Sets

BS Key Type LV Size Device Type Elapsed Time Completion Time


75 Full 6.80M DISK 00:00:01 2015-02-04 18:11:38
BP Key: 77 Status: AVAILABLE Compressed: NO Tag: TAG20150204T181137
Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870804697_bf3w2t62_.bkp
Control File Included: Ckp SCN: 415111 Ckp time: 2015-02-04 18:11:37

BS Key Type LV Size Device Type Elapsed Time Completion Time


139 Full 6.80M DISK 00:00:02 2015-02-04 18:22:45
BP Key: 144 Status: AVAILABLE Compressed: NO Tag: TAG20150204T182243
Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870805363_bf3wqnyv_.bkp
Control File Included: Ckp SCN: 415288 Ckp time: 2015-02-04 18:22:43

BS Key Type LV Size Device Type Elapsed Time Completion Time


236 Full 6.80M DISK 00:00:03 2015-02-04 18:33:39
BP Key: 242 Status: AVAILABLE Compressed: NO Tag: TAG20150204T183336
Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870806016_bf3xd2wl_.bkp
Control File Included: Ckp SCN: 415765 Ckp time: 2015-02-04 18:33:36

从上面的控制文件备份信息可以看到要恢复到2015-02-04 18:22:30这个时间点应该使用控制文件备份是o1_mf_s_870805363_bf3wqnyv_.bkp

2.将数据库强制启动到nomount状态

RMAN> startup force nomount

Oracle instance started

Total System Global Area 327155712 bytes

Fixed Size 1273516 bytes
Variable Size 138412372 bytes
Database Buffers 184549376 bytes
Redo Buffers 2920448 bytes

3.将数据库test的incarnation设置为incarnation号为102,也就是current incarnation的parent incarnation。

RMAN> reset database to incarnation 102;

database reset to incarnation 102

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 8 TEST 2168949517 PARENT 1 2010-04-19 10:22:46
1 2 TEST 2168949517 PARENT 383537 2015-02-04 17:44:49
1 102 TEST 2168949517 CURRENT 415176 2015-02-04 18:22:16
1 188 TEST 2168949517 ORPHAN 415481 2015-02-04 18:33:17

4.执行还原与恢复,设置恢复目标时间,如果没有配置相关通道设置通道。还原控制文件,将数据库恢复到表emp删除之后的时间点(2015-02-04 18:22:30):

RMAN> restore controlfile;

Starting restore at 2015-02-04 18:44:23
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870805363_bf3wqnyv_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870805363_bf3wqnyv_.bkp tag=TAG20150204T182243
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u01/app/oracle/oradata/test/control01.ctl
output filename=/u01/app/oracle/oradata/test/control02.ctl
output filename=/u01/app/oracle/oradata/test/control03.ctl
Finished restore at 2015-02-04 18:44:29

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> restore database until time ‘2015-02-04 18:22:30’;

Starting restore at 2015-02-04 18:47:15
Starting implicit crosscheck backup at 2015-02-04 18:47:15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 2015-02-04 18:47:17

Starting implicit crosscheck copy at 2015-02-04 18:47:17
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2015-02-04 18:47:17

searching for all files in the recovery area
cataloging files…
cataloging done

List of Cataloged Files

File Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870805363_bf3wqnyv_.bkp
File Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_04/o1_mf_s_870806016_bf3xd2wl_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/test/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/TEST/backupset/2015_02_04/o1_mf_nnndf_TAG20150204T181037_bf3w0y1f_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/TEST/backupset/2015_02_04/o1_mf_nnndf_TAG20150204T181037_bf3w0y1f_.bkp tag=TAG20150204T181037
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 2015-02-04 18:48:32

将数据文件还原到2015-02-04 18:22:30这个时间点,下面执行恢复,要注意的是在执行恢复操作之前还需要执行reset database to incarnation 102否则会报错:

RMAN> recover database until time ‘2015-02-04 18:22:30’;

Starting recover at 2015-02-04 18:49:05
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 02/04/2015 18:49:05
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20011: target database incarnation is not current in recovery catalog

再次执行 reset database to incarnation 102;

RMAN> reset database to incarnation 102;

database reset to incarnation 102

RMAN> recover database until time ‘2015-02-04 18:22:30’;

Starting recover at 2015-02-04 18:49:21
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u02/1_3_870803089.dbf
archive log thread 1 sequence 4 is already on disk as file /u02/1_4_870803089.dbf
archive log thread 1 sequence 1 is already on disk as file /u02/1_1_870805336.dbf
archive log filename=/u02/1_3_870803089.dbf thread=1 sequence=3
archive log filename=/u02/1_4_870803089.dbf thread=1 sequence=4
archive log filename=/u02/1_1_870805336.dbf thread=1 sequence=1
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-02-04 18:49:24

RMAN> alter database open resetlogs;

database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> list incarnation;

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time


1 8 TEST 2168949517 PARENT 1 2010-04-19 10:22:46
1 2 TEST 2168949517 PARENT 383537 2015-02-04 17:44:49
1 102 TEST 2168949517 PARENT 415176 2015-02-04 18:22:16
1 308 TEST 2168949517 CURRENT 415183 2015-02-04 18:49:41
1 188 TEST 2168949517 ORPHAN 415481 2015-02-04 18:33:17

可以看到恢复完成之后当前的incarnation对应的reset scn号在415176与415481之间,达到了我们所期待的结果。

Oracle使用ancestor incarnation完成基于时间点的不完全恢复相关推荐

  1. oracle++dtcol,Oracle 中的 Incarnation 到底是个什么?实验操作篇

    对于"化身"Incarnation概念了解之后,本篇通过手工恢复实验来具体操作演示,加深对Incarnation的理解,来自于博客园AskScuti. 目录 1. 官方图示例 2. ...

  2. 基于SCN和时间点的不完全恢复

    完全恢复与不完全恢复是数据库的两种恢复方式,顾名思义,他们的区别就是恢复后数据没有没丢失,不完全恢复是指恢复后有部分数据丢失,而完全恢复没有. 完整恢复是由于Oracle应用了归档日志和联机重做日志中 ...

  3. python使用pandas基于时间条件查询多个oracle数据表

    python使用pandas基于时间条件查询多个oracle数据表 目录 python使用pandas基于时间条件查询多个orcale数据表 #orcale数据连接

  4. oracle能闪回多久,oracle 闪回基于时间的恢复

    下面这篇文章是闪会基于时间点的恢复,可以恢复误删除的数据,刚好今天有客户遇到这样的案例 Microsoft Windows [版本 5.2.3790] (C) 版权所有 1985-2003 Micro ...

  5. Oracle基于时间点的恢复(转载)

    Oracle基于时间点的恢复 2010-10-19 18:43 Oracle基于时间点的恢复能够精确到什么样的精度? 这是一个需要关心的问题. 以下测试用于进行一点说明. 1.首先做好冷备份 2.创建 ...

  6. Oracle database TSPITR(TableSpace Point-In-Time Recovery) 表空间基于时间点的恢复

     主要用于恢复人为的错误 需要有之前的backup. 适用场景 (1)恢复错误的dml语句 (2)恢复错误的ddl语句,比如说更改了表结构,这个时候无法使用flashback table (3)恢复d ...

  7. Oracle 19c VLDB and Partitioning Guide 第5章:管理和维护基于时间的信息 读书笔记

    本文为Oracle 19c VLDB and Partitioning Guide第5章Managing and Maintaining Time-Based Information的读书笔记. Or ...

  8. oracle optimizer_features_enable,Oracle Optimizer:迁移到使用基于成本的优化器—–系列2.1-数据库专栏,ORACLE...

    oracle optimizer:迁移到使用基于成本的优化器-–系列2.1 系列之二包含影响优化器选择执行计划的初始化参数和oracle内部隐藏参数,合理设置这些参数对于优化器是相当重要的. 6.影响 ...

  9. Oracle-12c新功能基于时间点recover table

    前言: Oracle12c退出了新功能基于时间点的recover table,可以从备份里面基于时间快速恢复表或者表分区,并且支持通过remap将恢复的表更换为其他表名或者将恢复的表通过expdp导出 ...

最新文章

  1. 解决VSCode终端中禁止运行脚本问题的一种方式
  2. 浅析搜索引擎对网站的抓取规则有哪些方面
  3. Oracle-锁解读
  4. linux ftp查看用户目录权限,linux 指定ftp用户 特定目录及权限
  5. H.264/AVC技术进展及其务实发展策略思考
  6. 数据结构—链表-单链表基本操作实现
  7. [IOI2005]Riv 河流
  8. WebService之Axis2快速入门(2): 传递复合类型的数据
  9. 在VBA中实现通过Outlook发送邮件
  10. 匹配表情emoji 正则_新版Emoji表情过滤
  11. html日期格式化标签,js日期格式化yyyymmdd
  12. 2015年2月8日工作日志------赵鑫
  13. Harbor未授权创建管理员漏洞(CVE-2019-16097)
  14. CSS性能优化的几个技巧
  15. 芒果改进YOLOv7系列:超越ConvNeXt结构,原创结合Conv2Former改进结构,Transformer 风格的卷积网络视觉基线模型,高效涨点
  16. D3D11的颜色处理
  17. discuz 3.1修改浏览器顶部标题 - Powered by Discuz!
  18. 1.《SQL必知必会》第五版 附录A样例表的添加
  19. php ltrim函数,php ltrim函数怎么用?
  20. CMemoryDC(是吕鑫写的版本)

热门文章

  1. 印象笔记的使用技巧总结
  2. Apache Hadoop KMS 部署
  3. 响应式布局的实现方法
  4. linux之cut命令的用法
  5. S3C22440 JTAG连接不上
  6. QQ表情包,动态的那种
  7. 王自如评价鸿蒙OS,王自如发表致歉声明 测评将加利益相关说明
  8. HTTPS访问Git远程仓库,上报SSL证书错误解决方法
  9. element-plus 源码学习——radio
  10. 详细讲解二极管的钳位电路和限幅电路