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

相关推荐
QYRdata2 分钟前
Oracle云应用咨询服务驶入增长快车道:2026-2032年复合增长率达8.5%
数据库·oracle
AI办公探索者12 分钟前
多租户架构下数据隔离的三种实现方案对比
数据库·ai·oracle·架构
生戎马 平安京策1 小时前
SQL Transcation的一些总结
数据库·sql·oracle
施嘉伟2 小时前
KingbaseES V9 Oracle兼容版:SQL 调优实测
sql·oracle
梓沂5 小时前
Oracle 11g 跨平台迁移实战:从 Windows 到 CentOS 的完整记录
windows·oracle·centos
Leon-Ning Liu2 天前
【真实经验分享】ORA-12516 排查实录:共享服务器模式下 SHARED_SERVER_SESSIONS 不足引发的监听故障
运维·服务器·oracle
snpgroupcn2 天前
企业有必要做 SAP 数据归档吗?优势与价值分析
数据库·oracle
曹牧2 天前
Java:BeanListHandler
java·数据库·oracle
不想纳尼的青春3 天前
where = 的作用?会影响性能吗?count(*) 和 count()哪个快?
数据库·oracle