Clone a pluggable database (PDB) within a CDB in Oracle 12c

clone a pdb within a cdb

Oracle has introduced new Multitenant Option from Oracle 12cR1 and this option allows a single container database (CDB) to host multiple pluggable databases.

Refer here for more details on Oracle Multitenant option.

Related articles:

Create Container Database (CDB) in Oracle 12c using DBCA
Create Container database (CDB) in silent mode
Drop a container database in silent mode
Create a pluggable database manually in Oracle 12c

In this post I will describe how to clone a pluggable database (PDB) within the same CDB.

Here Cloning a new PDB pdb3 from pdb2 within CDB cdb2, we will cover the following steps:

  1. Create a directory to store new PDB datafiles
  2. Set PDB2 (source pdb) in Open Read only mode
  3. Clone PDB from PDB2 to PDB3
  4. Check the newly created PDB status
  5. Open the PDB database
1. Create a directory to store new PDB Datafiles
mkdir /u01/app/oracle/oradata/cdb2/pdb3
2. Set pdb2(source PDB) in Open Read only mode
sqlplus "/as sysdba"
alter pluggable database pdb2 close;
alter pluggable database pdb2 open read only;

o/p:

[oracle@cdb12c /]$ . oraenv
ORACLE_SID = [cdb2] ?
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@cdb12c /]$ sqlplus "/as sysdba"

SQL*Plus: Release 12.2.0.1.0 Production on Mon Jan 18 15:51:40 2021
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> alter pluggable database pdb2 close;
Pluggable database altered.
SQL> alter pluggable database pdb2 open read only;
Pluggable database altered.
SQL>
3. Clone PDB from PDB2 to PDB3
create pluggable database pdb3 from pdb2
create_file_dest='/u01/app/oracle/oradata/cdb2/pdb3';

Output:

SQL> create pluggable database pdb3 from pdb2
  2  create_file_dest='/u01/app/oracle/oradata/cdb2/pdb3';

Pluggable database created.

SQL>
4. Check the newly created pdb status

Status of the PDBs can be checked using v$pdbs view,

select name, open_mode from v$pdbs;
show pdbs;

SQL> select name, open_mode from v$pdbs;

NAME            OPEN_MODE
--------------- ----------
PDB$SEED        READ ONLY
PDB1            READ WRITE
PDB2            READ ONLY
PDB3            MOUNTED  -->newly created 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 ONLY  NO
         5 PDB3                           MOUNTED
SQL>

5. Open the PDB database in read-write mode
--Open source pdb if required:
alter pluggable database pdb2 close;
alter pluggable database pdb2 open;

--Open newly created pdb:
alter pluggable database pdb3 open;

Output:
SQL> alter pluggable database pdb2 close;
Pluggable database altered.
SQL> alter pluggable database pdb2 open;
Pluggable database altered.

SQL> alter pluggable database pdb3 open;
Pluggable database altered.
SQL>

We have successfully cloned PDB3 from PDB2 database and opened it in read-write mode.

Hope this helps…