Tag Archives: create pdb

CREATE NEW PDB BY CLONING AN EXISTING PDB

Goal: CREATE NEW PLUGGABLE DATABASE (PDB2) BY CLONING AN EXISTING PLUGGABLE DATABASE (PDB1)

Contents
___________________________________________________________________________________________________

1. Pre-requisites
2. Close existing PLUGGABLE DATABASE PDB1
3. Open existing PLUGGABLE DATABASE PDB1 in Read-Only
4. Create new directory at OS level
5. CREATE NEW PDB (PDB2) BY CLONING AN EXISTING PDB (PDB1)
6. OPEN NEW PLUGGABLE DATABASE PDB2
7. Close existing PLUGGABLE DATABASE PDB1 FROM RO MODE
8. Open existing PLUGGABLE DATABASE PDB1 in RW MODE
9. Verification
___________________________________________________________________________________________________


1. Pre-requisites

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

NAME                 OPEN_MODE                CON_ID
-------------------- -------------------- ----------
CDB2                 READ WRITE                    0

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO  <---
SQL>
SQL> col name for a60
SQL> select name from v$datafile where con_id=3;

NAME
------------------------------------------------------------
/home/oracle/oradata/PDB1system01.dbf
/home/oracle/oradata/PDB1sysaux01.dbf
/home/oracle/oradata/PDB1undotbs01.dbf
/home/oracle/oradata/PDB1/pdb1_users01.dbf

SQL> select name from v$tempfile where con_id=3;

NAME
------------------------------------------------------------
/home/oracle/oradata/PDB1temp01.dbf


2. Close existing PLUGGABLE DATABASE PDB1

SQL> alter pluggable database PDB1 close immediate;

Pluggable database altered.

SQL> 


3. Open existing PLUGGABLE DATABASE PDB1 in Read-Only

SQL> alter pluggable database PDB1 open read only;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ ONLY  NO  <----

SQL>


4. Create new directory at OS level

SQL> !mkdir -p /home/oracle/oradata/PDB2


5. CREATE NEW PDB (PDB2) BY CLONING AN EXISTING PDB (PDB1)

SQL> CREATE PLUGGABLE DATABASE PDB2 FROM PDB1
FILE_NAME_CONVERT=('/home/oracle/oradata/PDB1','/home/oracle/oradata/PDB2/');

Pluggable database created.  <-----

SQL>
SQL> show pdbs;

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

SQL> 


6. OPEN NEW PLUGGABLE DATABASE PDB2

SQL> alter pluggable database PDB2 open;

Pluggable database altered.

SQL>


7. Close existing PLUGGABLE DATABASE PDB1 FROM RO MODE

SQL> alter pluggable database PDB1 close immediate;

Pluggable database altered.

SQL>


8. Open existing PLUGGABLE DATABASE PDB1 in RW MODE

SQL> alter pluggable database PDB1 open;

Pluggable database altered.

SQL> 


9. Verification

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  <----
		 
SQL> select name from v$datafile where con_id=4;

NAME
------------------------------------------------------------
/home/oracle/oradata/PDB2/system01.dbf
/home/oracle/oradata/PDB2/sysaux01.dbf
/home/oracle/oradata/PDB2/undotbs01.dbf
/home/oracle/oradata/PDB2/pdb1_users01.dbf

SQL> select name from v$tempfile where con_id=4;

NAME
------------------------------------------------------------
/home/oracle/oradata/PDB2/temp01.dbf

SQL>

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.