Clone PDB or Non-CDB in Oracle 19c
Learn to clone PDBs and Non-CDBs in Oracle 19c.
With Oracle multi-tenant architecture, you get flexibility to clone pluggable databases from one container to another containers easily. The process of cloning PDB is way more simple than RMAN cloning process.
If version of source and target CDB is different and you want to clone PDB then, you must use Unplug and Plug PDB cloning method.
Clone PDB on Same CDB
For testing purpose, application team might want you to create a clone of single PDB. Simply put PDB that you want to clone into read only mode
SQL> alter pluggable database HRPDB close;
SQL> alter pluggable database HRPDB open read only;
With one single command, you can start cloning PDB
SQL> create pluggable database HRPDB_TEST from HRPDB FILE_NAME_CONVERT= ('/u01/CDB/HRPDB', '/u01/CDB/HRPDB_TEST');
That's it!
Clone PDB on Remote CDB
Set the DB_CREATE_FILE_DEST parameter on target so you don't have to worry about FILE_NAME_CONVERT parameter during cloning or migration. Your target CDB will auto create the datafiles for cloned PDB into DB_CREATE_FILE_DEST parameter location
On target CDB:
==============
SQL> alter system set DB_CREATE_FILE_DEST='/u01/CDB/';
On the source CDB, create a user inside PDB (you want to clone) and give permissions
On source PDB:
==============
SQL> create user migrate identified by migrate#123;
SQL> grant connect, resource, create pluggable database to migrate;
On the target CDB, setup tns entries to connect source PDB
On target CDB:
==============
SOURCE_HRPDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 3.19.61.169)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = HRPDB)
)
)
Create database link which allows us to connect source PDB inside sqlplus on target
On target CDB:
==============
SQL> create database link HRPDB connect to migrate identified by migrate#123 using 'SOURCE_HRPDB';
Clone pdb from source to target
On target CDB:
==============
SQL> create pluggable database HRPDB_NEW from HRPDB@HRPDB;
SQL> create pluggable database {new-pdb} from {old-pdb}@{db-link};
Clone Non-CDB to CDB
Set the DB_CREATE_FILE_DEST parameter on target so you don't have to worry about FILE_NAME_CONVERT parameter during cloning or migration. Your target CDB will auto create the datafiles for cloned PDB into DB_CREATE_FILE_DEST parameter location
On target CDB:
==============
SQL> alter system set DB_CREATE_FILE_DEST='/u01/CDB/';
On the source Non-CDB, create a user inside database and give permissions
On source Non-CDB:
==================
SQL> create user migrate identified by migrate#123;
SQL> grant connect, resource, create pluggable database to migrate;
On the target CDB, setup tns entries to connect source Non-CDB
On target CDB:
==============
NONCDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 3.19.61.169)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORCL)
)
)
Create database link which allows us to connect source DB inside sqlplus on target
On target CDB:
==============
SQL> create database link clone_link connect to migrate identified by migrate#123 using 'NONCDB';
Clone DB from source to target
On target CDB:
==============
SQL> create pluggable database ORCL from NON$CDB@clone_link;
SQL> create pluggable database {new-pdb} from {non$cdb}@{db-link};
Since there is no PDB to name, we use "NON$CDB" as the PDB name
Enjoy! 😉