CDB 中某个PDB的datafile 丢失 没有备份过也可恢复 需要来回切换CDB PDB

Applies To

All Users

Summary

NOTE: In the images and/or the document content below, the user information and environment data used represents fictitious data from the Oracle sample schema(s), Public Documentation delivered with an Oracle database product or other training material. Any similarity to actual environments, actual persons, living or dead, is purely coincidental and not intended in any manner.

For the purposes of this document, the following fictitious environment is used as an example to describe the procedure:

CDB name:CDB1

PDB name: pdbtest

CDB1 path:/cdb1/cdb1

PDBTEST path: /cdb1/cdb1/pdbtest

PDBTEST tablespace name: TEST

PDBTEST tablespace test datafile: /cdb1/cdb1/pdbtest/sh.dbf

PDBTEST TNS connect string: pdbtest

RMAN backup location: /cdb1

PDB$SEED path:/cdb1/cdb1/pdbseed

*****************************

The Goal of this article is do a restore and recovery of a datafile From PDB when one or couple of datafiles associated with PDB are corrupted or lost.

Before we start Please understand the following Terms used in 12c.

What is a multitenant container database ?

A 12c database is either a non-Container Database or a Container Database - referred to as non-CDB or CDB respectively.

A CDB is an Oracle database that includes zero, one, or many customer-created Containers or Pluggable Databases referred to as PDB.

The CDB has:

  • one ROOT container (CDB$ROOT) containing SYSTEM, SYSAUX, UNDO, and TEMP tablespaces, Controlfiles and Redologs
  • one SEED container (PDB$SEED) containing SYSTEM, SYSAUX, TEMP, EXAMPLE tablespaces, used as a template to create new PDBs

What is a Pluggable Database?

A pluggable Database (PDB) is a user-created container holding the data for any application.

A PDB would have its SYSTEM, SYSAUX, TEMP tablespaces.It can also contains other user created tablespaces in it.

Change done to Pdb database would be written to the Undo /redo present in the CDB$ROOT.

By Default When you Connect as sysdba without any service name you connect to Root Container

% rman target /

Solution

In this example, we are using CDB1 for the container database name and pdbtest for the pluggable database name.

CDB: CDB1

PDB: PDBTEST

List of Permanent Datafiles

===========================

File Size(MB) Tablespace RB segs Datafile Name


1 790 SYSTEM *** /cdb1/cdb1/system01.dbf -----------> Root Container database CDB1 datafile

3 1000 SYSAUX *** /cdb1/cdb1/sysaux01.dbf -----------> Root Container database CDB1 datafile

4 240 UNDOTBS1 *** /cdb1/cdb1/undotbs01.dbf -----------> Root Container database CDB1 datafile

5 260 PDBSEED:SYSTEM \*\*\* /cdb1/cdb1/pdbseed/system01.dbf -----\> System datafile for PDBSEED

6 5 USERS *** /cdb1/cdb1/users01.dbf ------------> User created datafile for Root Container database CDB1

7 670 PDB$SEED:SYSAUX *** /cdb1/cdb1/pdbseed/sysaux01.dbf

17 260 PDBTEST:SYSTEM *** /cdb1/cdb1/pdbtest/system01.dbf ---> System datafile for PDBTEST

18 720 PDBTEST:SYSAUX *** /cdb1/cdb1/pdbtest/sysaux01.dbf -----> Sysaux datafile for PDBTEST

19 4 PDBTEST:USERS *** /cdb1/cdb1/pdbtest/userpdbtest.dbf

20 2 PDBTEST:TEST *** /cdb1/cdb1/pdbtest/sh.dbf ==============> Restoring datafile 20 from PDBTEST

List of Temporary Files

=======================

File Size(MB) Tablespace Maxsize(MB) Tempfile Name


1 88 TEMP 32767 /cdb1/cdb1/temp01.dbf

2 87 PDB$SEED:TEMP 32767 /cdb1/cdb1/pdbseed/pdbseed_temp01.dbf

3 20 PDBTEST:TEMP 32767 /cdb1/cdb1/pdbtest/pdbtest_temp01.dbf

Step1 :- Check the status of the file

Check the status of the file you want to restore and recovery in the PDB.

In this example the file number is 20

SQL> Connect / as sysdba ================> Connects to Root Container (CDB1)

SQL> select * from v$recover_file;

FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME CON_ID


20 OFFLINE OFFLINE 2334347 01-JUL-13 3

Here we see the datafile belongs to CON_ID =3 .

Run the below query to find the PDB name for this container

SQL> select con_id,open_mode,name from v$pdbs ;

CON_ID OPEN_MODE NAME


2 READ ONLY PDB$SEED

3 READ WRITE PDBTEST =====================> Confirmed that this file belongs to PDB database PDBTEST

If the datafile Is online and has some Corruption in it and you plan to restore it from backup then ensure you take the datafile offline before restore.

Datafile can be taken offline only when connecting to the PDB database that it belongs to (PDBTEST in this case) Else it will report the error below

SQL> alter database datafile 20 offline ;

alter database datafile 20 offline

*

ERROR at line 1:

ORA-01516: nonexistent log file, data file, or temporary file "20"

Connect to the PDB database pdbtest

SQL> conn sys/<password>@pdbtest as sysdba

Connected.

SQL> show parameter con_id

3 ------------> This confirms we have connect to correct PDB

SQL> alter database datafile 20 offline;

Database altered.

SQL> Spool off

Step 2 :- Restore the datafile 20 from backup.

Connect to the Root Container database (CDB1)

rman target / ==========> By Default contains to Root container

RMAN> restore datafile 20;
..
creating datafile file number=20 name=/cdb1/cdb1/pdbtest/sh.dbf
Finished restore at 01-JUL-13

In the above example NO backup existed for this datafile, so RMAN will create a empty datafile with creations scn of the datafile and apply the archive log from the creation time till current time.
If backup exist Rman would restore the datafile from backup and apply the required archivelogs .

Step 3 : Recover the datafile

RMAN> recover datafile 20;

Starting recover at 01-JUL-13

using channel ORA_DISK_1

starting media recovery

......

media recovery complete, elapsed time: 00:00:01

Finished recover at 01-JUL-13

RMAN> exit

Connect to PDBTEST in sqlplus

SQL> conn sys/<password>@PDBTEST as sysdba

SQL> alter database datafile 20 online;

SQL>Select * from v$recover_file;

No rows

相关推荐
2501_942389552 小时前
特斯拉的车辆摄像头每四天为AI训练集采集的数据量
人工智能·hadoop·zookeeper·oracle·时序数据库·memcache
山峰哥3 小时前
数据库工程与SQL优化实战指南‌
数据库·sql·oracle·深度优先·宽度优先
宠友信息6 小时前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app
—Miss. Z—8 小时前
计算机二级MySQL选择题考点Ⅱ
数据库·mysql·oracle
Irene19919 小时前
数据迁移,源端探查(以 Oracle 为例)的三种实现层次:工具化(MTK)、脚本化(最主流方式)和手工查询(测试学习)
oracle·数据迁移·源端探查
矜持的左手9 小时前
硬件故障后数据文件大小不对故障处理—Oracle碎片扫描恢复
数据库·oracle
欢呼的太阳17 小时前
数据库设计Step by Step (10)——范式化
服务器·数据库·oracle
多巴胺梦想家1 天前
数据库恢复技术:当灾难来临
网络·数据库·oracle
oradh1 天前
Oracle DG主备架构的基本维护操作总结
数据库·oracle·架构·dg主备架构的基本维护操作总结
Albert Tan1 天前
Oracle EBS 12.2 Create RFQ
oracle