Database Incarnations

数据库转世与重置日志
数据库在经历完整恢复、DBPITR或使用备份控制文件恢复后,需使用OPEN RESETLOGS打开,创建新的转世以避免redo流混淆。OPEN RESETLOGS会更新数据文件、归档在线重做日志并初始化控制文件记录。重置日志SCN确保了数据文件不会应用不匹配的归档日志,防止数据库损坏。不同数据库转世间存在当前、父代和祖先关系,RMAN在OPEN RESETLOGS操作中处理相关事务。孤儿备份是在非直接祖先路径中的备份,可用于恢复到非当前路径的SCN。

INCARNATION可以翻译为转世

在使用数据库的时间点恢复或使用备份控制文件恢复后必须使用OPEN RESETLOGS

After complete recovery, you can resume normal operations without an OPEN RESETLOGS . After a DBPITR or recovery with a backup control file, however, you must open the database with the RESETLOGS option, thereby creating a new incarnation of the database.

The database requires a new incarnation to avoid confusion when two different redo streams have the same SCNs, but occurred at different times. If you apply the wrong redo to your database, then you corrupt it.

  • RMAN OPEN RESETLOGS Operations

RMAN performs certain actions when you open the database with the RESETLOGS option.

The action performed are as follows:

  1. Archives the current online redo logs (if they are accessible) and then erases the contents of the online redo logs and resets the log sequence number to 1.
  2. Creates the online redo log files if they do not currently exist.
  3. Initializes redo thread records and online redo log records in the control file to the beginning of the new database incarnation.
  4. Updates all current data files and online redo logs and all subsequent archived redo logs with a new RESETLOGS SCN and time stamp.

RESETLOGS SCN保证了数据文件不会应用不匹配的归档日志

Because the database does not apply an archived redo log to a data file unless the RESETLOGS SCN and time stamps match, the RESETLOGS requirement prevents you from corrupting data files with archived logs that are not from direct parent incarnations of the current incarnation.

没必要在OPEN RESETLOGS后进行全备

In previous releases, it was recommended that you back up the database immediately after the OPEN RESETLOGS. Because you can now easily recover a pre-RESETLOGS backup like any other backup, making a new database backup is optional.

  • Relationship Among Database Incarnations

Database incarnations can stand in the following relationships to each other:

  1. The current incarnation is the one in which the database is currently operating.
  2. The incarnation from which the current incarnation branched following an OPEN RESETLOGS operation is the parent incarnation of the current incarnation.
  3. The parent of the parent incarnation is an ancestor incarnation. Any parent of an ancestor incarnation is also an ancestor of the current incarnation.
  4. The direct ancestral path of the current incarnation begins with the earliest incarnation and includes only the branches to an ancestor of the current incarnation, the parent incarnation, or the current incarnation. 直接祖先路径只包含当前及父、第一个祖先

An incarnation number is used to uniquely tag and identify a stream of redo. 

Figure 14-1 illustrates a database that goes through several incarnations, each with a different incarnation number.

Incarnation 1 of the database starts at SCN 1 and continues through SCN 1000 to SCN 2000. Suppose that at SCN 2000 in incarnation 1, you perform a point-in-time recovery back to SCN 1000, and then open the database with the RESETLOGS option. Incarnation 2 now begins at SCN 1000 and continues to SCN 3000. In this example, incarnation 1 is the parent of incarnation 2.

Suppose that at SCN 3000 in incarnation 2, you perform a point-in-time recovery to SCN 2000 and open the database with the RESETLOGS option. In this case, incarnation 2 is the parent of incarnation 3. Incarnation 1 is an ancestor of incarnation 3.

The RESET DATABASE TO INCARNATION command is required when you use FLASHBACK, RESTORE, or RECOVER to return to an SCN in a noncurrent database incarnation. However, RMAN executes the RESET DATABASE TO INCARNATION command implicitly with Flashback

Incarnation的相关命令

  1. 查看incarnation

RMAN> list incarnation;

V$database_incarnation包含所有incarnations, v$database只包含当前及上个incarnation

V$DATABASE_INCARNATION displays information about all database incarnations. Records about the current and immediately previous incarnation are also contained in the V$DATABASE view.

SQL> select INCARNATION#, RESETLOGS_TIME,STATUS, PRIOR_INCARNATION#, FLASHBACK_DATABASE_ALLOWED from V$DATABASE_INCARNATION;

  1. 切换incarnation:

RMAN> reset database to incarnation 11;    --数据库mount状态

  • Incarnations of PDBs

A pluggable database (PDB) incarnation is a subincarnation of the multitenant container database (CDB) and is expressed as (database_incarnation, pdb_incarnation).

For example, if the CDB is incarnation 5, and a PDB is incarnation 3, then the fully specified incarnation number of the PDB is (5, 3). The initial incarnation of a PDB is 0. Subsequent incarnations are unique but not always sequential numbers.

The V$PDB_INCARNATION view contains information about all PDB incarnations. Use the following query to display the current incarnation of a PDB:

SELECT PDB_INCARNATION# FROM V$PDB_INCARNATION

   WHERE STATUS = 'CURRENT' AND CON_ID = PDB_container_id;

  • Orphaned Backups

不在direct ancestral path的备份称为孤立备份Orphaned backup. 未在direct ancestral path的incarnations称为abandoned incarnations或orphaned incarnations

When a database goes through multiple incarnations, some backups can become orphaned backups. Orphaned backups are backups created during incarnations of the database that are not in the direct ancestral path.

Assume the scenario shown in Figure 14-1. If incarnation 3 is the current incarnation, then the following backups are orphaned:

All backups from incarnation 1 after SCN 1000

All backups from incarnation 2 after SCN 2000

In contrast, the following backups are not orphaned because they are in the direct ancestral path:

All backups from incarnation 1 before SCN 1000

All backups from incarnation 2 before SCN 2000

All backups from incarnation 3

RMAN可以直接使用direct ancestral path中备份恢复到任意子incarnation

You can use orphaned backups when you intend to restore the database to an SCN not in the direct ancestral path. RMAN can restore backups from parent and ancestor incarnations and recover to the current time, even across OPEN RESETLOGS operations, if a continuous path of archived logs exists from the earliest backups to the point to which you want to recover.

如果还原了direct ancestral path的控制文件就可以使用orphaned backups

If you restore a control file from an incarnation in which the changes represented in the backups had not been abandoned, then RMAN can also restore and recover orphaned backups.

  • Orphaned PDB Backups

Orphan PDB backups can result when you perform point-in-time recovery on a pluggable database (PDB) and then open the PDB using the RESETLOGS option.

Orphan PDB backups are backups that were created when the SCN or time value was between the SCN or time to which the PDB was recovered and the SCN or time at which the PDB was opened in RESETLOGS mode.

The END_RESETLOGS_SCN column of the V$PDB_INCARNATION view contains the SCN at which the PDB is opened in RESETLOGS mode.

  • Flashback and Database Point-in-Time Recovery Scenarios

闪回数据库与数据库的时间点恢复均可以回到任意incarnations,详见各文档说明

  1. 闪回数据库可回到direct ancestral path中,不需要执行RESET DATABASE TO INCARNATION
  2. 闪回数据库如果想回到abandoned incarnations才执行RESET DATABASE TO INCARNATION
  3. 数据库时间点恢复到非当前incarnations均要执行RESET DATABASE TO INCARNATION
  4. 数据库时间点恢复还需要还原相应incarnation的控制文件

如下图所示,如果想从incarnation 3 scn 3000回到incarnation 1 scn 500时,闪回直接flashback database to scn 500即可,而DBPITR则要执行reset database to incarnation 1

如果想从incarnation 3 scn 3000回到incarnation 1 scn 1500时,闪回与数据库均需要先执行reset database to incarnation 1然后执行flashback database to scn 1500或run{set until scn 1500; restore controlfile; alter database mount; restore database; recover database; }

<think>好的,我现在需要解决用户遇到的RMAN-20207错误。根据用户提供的引用内容,这个错误通常是因为指定的恢复时间点或恢复窗口在RESETLOGS操作之前,导致无法恢复。用户想了解如何解决这个问题,以及相关的用法和注意事项。 首先,我要回忆一下Oracle RMAN恢复的基本流程。当进行不完全恢复时,需要使用UNTIL TIME或RECOVERY WINDOW来指定恢复的时间点。但如果数据库之前有过RESETLOGS操作,那么恢复的时间点必须在最近的RESETLOGS之后,否则RMAN会报20207错误。这是因为RESETLOGS会重置日志序列号,并创建一个新的数据库化身(incarnation)。 用户提供的引用中提到,可以通过查看数据库的化身列表(list incarnation)来确认当前的化身情况。正确的恢复时间应该是在当前化身的RESETLOGS时间之后。如果用户错误地指定了之前的化身的时间点,就会导致这个错误。因此,解决方法可能包括检查并选择正确的化身,或者调整恢复时间点。 另外,引用中还提到用户可能在尝试多次恢复,比如先恢复EMP表,再恢复用户,这可能导致多次RESETLOGS操作,需要特别注意每次RESETLOGS后的时间点是否正确。例如,如果第一次恢复后执行了RESETLOGS,那么后续的恢复必须基于这个新的化身的时间点。 接下来,我需要整理解决这个错误的具体步骤。首先应该使用LIST INCARNATION命令查看所有数据库化身,确定当前的化身和对应的RESETLOGS时间。然后,在恢复时指定正确的化身,或者调整恢复时间到当前化身的RESETLOGS之后。如果恢复时间确实需要到之前的化身,可能需要使用RESET DATABASE TO INCARNATION命令切换到旧的化身,再进行恢复。 同时,用户可能需要了解如何正确指定时间格式,确保时间参数无误,避免因格式问题导致误判。此外,还需要注意归档日志的完整性,确保所需的日志文件在恢复期间可用,否则即使时间正确,恢复也可能失败。 最后,应该总结常见原因和解决方案,比如检查化身信息、调整恢复时间、切换化身等,并给出示例命令,帮助用户实际操作。还要提醒用户进行恢复前备份当前数据库状态,避免数据丢失。</think>### RMAN-20207错误解决方案及用法解析 #### 一、错误原因分析 RMAN-20207错误表明**指定的`UNTIL TIME`或`RECOVERY WINDOW`时间点早于最近一次`RESETLOGS`操作的时间**[^1]。Oracle通过`RESETLOGS`重置日志序列号并创建新的数据库化身(Incarnation),恢复操作只能在当前化身的时间范围内进行。 --- #### 二、核心解决步骤 1. **查看数据库化身历史** ```sql RMAN> LIST INCARNATION OF DATABASE; ``` 输出示例: ``` List of Database Incarnations DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time 1 2 ORCL 1234567890 PARENT 100000 2023-01-01 10:00:00 1 3 ORCL 1234567890 CURRENT 200000 2023-06-01 15:30:00 ``` **关键字段**: - `Reset Time`:最后一次`RESETLOGS`的时间 - `STATUS=CURRENT`:当前有效化身 2. **调整恢复时间点** 确保`UNTIL TIME`晚于当前化身的`Reset Time`: ```sql RMAN> RUN { SET UNTIL TIME "TO_DATE('2023-06-02 08:00:00', 'YYYY-MM-DD HH24:MI:SS')"; RESTORE DATABASE; RECOVER DATABASE; } ``` 3. **跨化身恢复(需谨慎)** 若必须恢复到旧化身的时间点: ```sql RMAN> RESET DATABASE TO INCARNATION 2; -- 指定旧化身的Inc Key RMAN> RUN { SET UNTIL TIME "TO_DATE('2023-01-02 09:00:00', 'YYYY-MM-DD HH24:MI:SS')"; RESTORE DATABASE; RECOVER DATABASE; } ``` --- #### 三、关键注意事项 1. **时间格式必须精确** 使用`TO_DATE`明确指定时间格式,避免因时区或格式歧义导致错误[^2]: ```sql SET UNTIL TIME "TO_DATE('2023-06-01 16:00:00', 'YYYY-MM-DD HH24:MI:SS')"; ``` 2. **归档日志完整性验证** 恢复前确认所需归档日志存在: ```sql RMAN> CROSSCHECK ARCHIVELOG ALL; ``` 3. **恢复前备份当前状态** 不完全恢复后必须执行`OPEN RESETLOGS`,此时建议立即备份: ```sql RMAN> BACKUP DATABASE PLUS ARCHIVELOG; ``` --- #### 四、应用场景示例 **场景**:数据库在2023-06-01 15:30:00执行`RESETLOGS`,需恢复到2023-06-01 16:00:00删除表前的状态。 **操作**: ```sql RMAN> LIST INCARNATION; -- 确认当前化身的Reset Time RMAN> RUN { SET UNTIL TIME "TO_DATE('2023-06-01 16:00:00', 'YYYY-MM-DD HH24:MI:SS')"; RESTORE DATABASE; RECOVER DATABASE; } ALTER DATABASE OPEN RESETLOGS; -- 恢复后必须执行 ``` --- #### 五、常见问题排查表 | 现象 | 可能原因 | 解决方案 | |------|----------|----------| | RMAN-20207 | 恢复时间早于RESETLOGS | 使用`LIST INCARNATION`检查当前化身时间 | | ORA-01547 | 恢复后未执行OPEN RESETLOGS | 执行`ALTER DATABASE OPEN RESETLOGS` | | RMAN-06053 | 缺失归档日志 | 通过`CROSSCHECK`验证日志完整性 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值