Saturday, August 15, 2020

 


Oracle 12cR2: SEED (PDB$SEED) pluggable database is in unusable state? Here's how you can recover/recreate it.


PDB$SEED pluggable database recover methods.


Part 1. Recover PDB$SEED using backup

Part 2. Recover PDB$SEED using existing PDB (without backup)

Part 3. Recover PDB$SEED from another PDB$SEED (without backup)


Oracle 12c has introduced the multi-tenant architecture for Oracle database, where a single container database (CDB$ROOT) can have multiple pluggable databases (PDBs). This new architecture is introduced to ease the management of Oracle databases, where by we can consolidate multiple Oracle databases into a single container database (CDB). In the multi-tenant architecture, ideally we use the SEED template pluggable database (PDB$SEED) to create any new pluggable database within the container database (CDB$ROOT). The SEED pluggable database (PDB$SEED) acts as a template for creating fresh pluggable databases and we are not allowed to alter the configuration of SEED pluggable database (by default opens up in READ ONLY mode).


There are possibilities, that the SEED pluggable database (PDB$SEED) may become corrupt or unusable due to file system issues or due to any other unforeseen reasons. In that case, we can't use the seed pluggable database (PDB$SEED) for creating new pluggable databases in the respective container.


In this video, I will discuss about the different methods that we can follow to recover or recreate the seed pluggable database (PDB$SEED) in the event of seed being in a unusable state (corrupted)


Recover PDB$SEED using backup:

------------------------------


Backup is the first place of defense to recover or restore a database. It is always recommended to backup the databases to be able to restore it when required. In the multi-tenant architecture, we have the option of taking backup of individual pluggable databases or all the pluggable databases together along with the container database.


If the seed pluggable database becomes unusable, we can restore it using the backup. Here is the pictorial representation of the overall process involved in restoring a seed pluggable database from a backup.


Since, I am simulating the failure of the seed pluggable database (PDB$SEED), let me take a backup of the seed pluggable database (PDB$SEED) for this demonstration. We will use this backup to restore/reover the seed database later.


##---

##--- Taking backup of seed pluggable database (PDB$SEED) ---##

##---

[oracle@labserver2 ~]$ rman target /


RMAN> backup database "pdb$seed" format '/u02/archive/rman/cdb1_seed_%U.bkp';


For the purpose of demonstration, I am deleting the system datafile belonging to the seed pluggable database (PDB$SEED) as shown below. This will make the seed pluggable database unusable and we will not be able to use the seed pluggable database for creating new pluggable databases in the respective container database (CDB$ROOT). 


In a real time scenario, the seed pluggable database may become unusable due to a number of unforeseen reasons.


[oracle@srlabprmy rman]$ sqlplus / as sysdba


SQL*Plus: Release 12.2.0.1.0 Production on Sat Aug 15 01:59:42 2020


Copyright (c) 1982, 2016, Oracle.  All rights reserved.



Connected to:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production


SQL> select * from global_name;


GLOBAL_NAME

--------------------------------------------------------------------------------

CDB1


SQL> set lines 300 pages 2000

SQL> show pdbs


    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 CDB1PLUG                       READ WRITE NO


SQL> select name from v$datafile;


##---

##--- deleting system datafile from seed pluggable database ---##

##---

[oracle@srlabprmy ~]$ rm /u02/oradata/CDB1/pdbseed/system01.dbf

[oracle@srlabprmy ~]$ ls -lrt /u02/oradata/CDB1/pdbseed/system01.dbf

ls: /u02/oradata/CDB1/pdbseed/system01.dbf: No such file or directory


I have deleted the system datafile belonging to seed pluggable database (PDB$SEED). Let's try to create a new pluggable database using the seed pluggable databases.


---//

---// create pluggable database using seed (PDB$SEED) //---

---//

SQL> show pdbs


    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 CDB1PLUG                       READ WRITE NO


mkdir -p /u02/oradata/CDB2PLUG/


SQL> create pluggable database CDB2PLUG admin user pdb_admin identified by oracle file_name_convert=('/u02/oradata/CDB1/pdbseed/','/u02/oradata/CDB2PLUG/');



As expected, we are not able to create new pluggable database using the seed pluggable database (PDB$SEED). Let's use the seed pluggable database backup to restore/recover the seed pluggable database. We need to close the seed pluggable database to be able to restore the missing file. Let's close the seed pluggable database (PDB$SEED).


---//

---// trying to close seed pluggable database //---

---//

SQL> alter pluggable database "pdb$seed" close;


As we can see, we are not allowed to alter the state of the seed pluggable database (PDB$SEED). 

However, there is workaround where we can set the hidden parameter _oracle_script to TRUE and that will allow us to change the seed pluggable database (PDB$SEED) state as shown below.


---//

---// closing PDB$SEED by setting _oracle_script to TRUE //---

---//

SQL> alter session set "_oracle_script"=true;


SQL> alter pluggable database "pdb$seed" close;


SQL> show pdbs

   CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       MOUNTED  

         3 CDB1PLUG                       READ WRITE NO



Let's restore the missing seed datafile using the backup that was taken earlier


##---

##--- validating the availability of backup ---##

##---

RMAN> list backup of datafile 2;


##---

##--- restoring missing seed datafile (file# 2) ---##

##---

 

[oracle@srlabprmy ~]$ env |grep ORA

ORACLE_UNQNAME=SRCDB01

ORACLE_SID=CDB1

ORACLE_BASE=/u01/app/oracle

ORACLE_HOSTNAME=srlabprmy.localdomain

ORA_INVENTORY=/u01/app/oraInventory

ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/db_2

[oracle@srlabprmy ~]$ rman target /

 

RMAN> restore datafile 2;


We have restored the missing seed datafile. Let's open the seed database in it's intended READ ONLY state.


##---

##--- trying to open seed pluggable database after datafile restore ---##

##---

RMAN> alter pluggable database "pdb$seed" open read only;


##---

##--- opening PDB$SEED by setting _oracle_script to TRUE ---##

##---

RMAN> alter session set "_oracle_script"=true;


RMAN> alter pluggable database "pdb$seed" open read only;


##---

##--- validate PDB$SEED is opened in READ ONLY mode ---##

##---

RMAN> select con_id,name,open_mode,restricted from v$pdbs;


##---

##--- reset _oracle_script to FALSE ---##

##---

RMAN> alter session set "_oracle_script"=false;


We have successfully restored and recovered the seed pluggable database (PDB$SEED). Now, we should be able to create new pluggable databases using the seed pluggable database as shown below.


---//

---// creating pluggable database using PDB$SEED //---

---//


SQL> create pluggable database CDB2PLUG admin user pdb_admin identified by oracle file_name_convert=('/u02/oradata/CDB1/pdbseed/','/u02/oradata/CDB2PLUG/');


SQL> show pdbs

Conclusion:

In this video, I have explored how to restoring or recreating a seed pluggable database (PDB$SEED) in the event of seed database being in the UNUSABLE state. It is always recommended to take periodic backup of the seed pluggable database even though it is just a template for creating other pluggable databases. In the presence of a VALID backup, the seed pluggable database restoration/recovery becomes hassle free and straight forward. However, we still have ways (we will see it next videos) to recreate the seed pluggable database in the absence of a VALID backup.


Regards,

Ramesh.

Post a Comment: