oracle数据库文件恢复 如何从完好的数据文件恢复oracle数据库

关于在CDB闪回后恢复已删除的PDB

方法适用于·Oracle 12.1.0.1、12.1.0.2版本数据库

目的
如果CDB闪回已经完成,那么有机会找到之前删除的PDB数据文件处于offline状态。

恢复原因:
在过去某个PDB已经被drop掉后,可能现在闪回的数据库下存在被删除的PDB相关数据文件处于offline状态下。

 

解决方法:

场景:

  • 数据库备份时的scn大致在4700000
  • PDB3是在SCN 4800000时被drop掉的
  • 闪回数据库CDB到scn 4810629。

可以找到处于offline状态的数据文件(这些是被drop的PDB相关的文件)

select file#,name from v$datafile;

在闪回后,我们会发现UNNAMED00017和UNNAMED00018两个文件处于offline状态。

/u01/app/oracle/product/12.1.0.2/db_1/dbs/UNNAMED00017
/u01/app/oracle/product/12.1.0.2/db_1/dbs/UNNAMED00018

查看alert日志

Flashback Restore Start
Flashback: Added pluggable database #5: 'PDB3' to the control file.
Flashback: created tablespace #0: 'SYSTEM' of pdb #5 in the controlfile.
Flashback: created OFFLINE file 'UNNAMED00017' for tablespace #0 of pdb #5 in the controlfile.
Filename was:
'/u01/app/oracle/oradata/CDBPRODS/4F88781C447A496AE0533B20B80AAF00/datafile/o1_mf_system_dkl7nplc_.dbf' when dropped.
File will have to be restored from a backup and recovered.
Flashback: created tablespace #1: 'SYSAUX' of pdb #5 in the controlfile.
Flashback: created OFFLINE file 'UNNAMED00018' for tablespace #1 of pdb #5 in the controlfile.
Filename was:
'/u01/app/oracle/oradata/CDBPRODS/4F88781C447A496AE0533B20B80AAF00/datafile/o1_mf_sysaux_dkl7npld_.dbf' when dropped.
File will have to be restored from a backup and recovered.
Flashback: created tablespace #2: 'TEMP' of pdb #5 in the controlfile.
Flashback Restore Complete
Flashback Media Recovery Start

如何从备份中恢复这些文件呢?

Step 1) 在恢复时,使用until scn命令项恢复数据库文件

RMAN> run {
set until scn 4810629;
set newname for datafile 17 to '/u01/app/oracle/oradata/CDBPRODS/datafile/datafile171.dbf';
set newname for datafile 18 to '/u01/app/oracle/oradata/CDBPRODS/datafile/datafile181.dbf';
restore pluggable database pdb3;
}

Step 2) switch datafiles to copy (对UNNAMED000xx命名的文件重命名)
(在本例中数据文件17和18被恢复出来了 )

RMAN> switch datafile 17 to copy;
RMAN> switch datafile 18 to copy;

检查PDB

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 READ WRITE NO
5 PDB3 MOUNTED

Step 3) 将offline的数据文件online (默认情况下闪回会将数据文件保持在offline状态)

SQL> alter session set container=pdb3;
SQL> alter database datafile '/u01/app/oracle/oradata/CDBPRODS/datafile/datafile171.dbf' online;
SQL> alter database datafile '/u01/app/oracle/oradata/CDBPRODS/datafile/datafile181.dbf' online;

Step 4) recover your PDB files  
以下recover操作将会建立辅助实例并对数据文件进行恢复

RMAN> run {
set until scn 4810629;
recover pluggable database pdb3;
}

step 5) 以resetlogs方式打开PDB

RMAN> alter pluggable database pdb3 open resetlogs;

你可能感兴趣的:(Oracle,Oracle,12c,recovery,oracle学习)