Before You Begin
This 15-minute tutorial shows you how to clone a pluggable
database (PDB) into an existing opened read/write container
database (CDB) by using the Recovery Manager (RMAN)
DUPLICATE command without the use of a fresh
auxiliary instance.
Background
In Oracle Database 12c, the PDB duplication uses a fresh auxiliary instance.
Oracle Database 18c dispenses from the use of a fresh auxiliary instance.
What Do You Need?
- Familiarity with PDB duplication
- Oracle Database 18c installed
- One CDB (
ORCL) as the source (this is theTARGETinDUPLICATEcommand) that has to be in archive log mode - One PDB (
PDB1) in the source CDB - One CDB (
cdb1) as the auxiliary (this is the destination for the cloned PDB) PDB1includes an unlocked userHRwith demo data
Duplicate
a PDB into Another CDB
In this section, you'll duplicate the active PDB1
from ORCL into cdb1.
- Log in to
ORCLto verify the existence ofPDB1inORCL.sqlplus sys@ORCL AS SYSDBA
Enter password: password - Verify the existence of
PDB1.SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 4 PDB1 READ WRITE NO - To check the content of the
HR.REGIONStable inPDB1,first connect toPDB1.
CONNECT hr@PDB1
Enter password: password - Display the content of
HR.REGIONStable.SELECT * FROM hr.regions;
REGION_ID REGION_NAME ---------- ------------------------- 1 Europe 2 Americas 3 Asia 4 Middle East and Africa - Connect to
CDB1to verify that there is noPDB1incdb1.CONNECT sys@cdb1 AS SYSDBA
Enter password: password - Verify that there is no
PDB1incdb1.SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO - Set
the initialization parameterREMOTE_RECOVERY_FILE_DESTincdb1to restore the foreign archive log.ALTER SYSTEM SET REMOTE_RECOVERY_FILE_DEST='/home/oracle/labs' SCOPE=BOTH; - Quit the session.
EXIT - Open an
rmansession.
rman - Connect to the source
ORCLCDB.
CONNECT TARGET sys@ORCL target database Password: password
connected to target database: ORCL (DBID=1490974532) - Connect to the auxiliary
cdb1CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password
connected to auxiliary database: CDB1 (DBID=936911243) - Duplicate
PDB_ORCLintocdb1.DUPLICATE PLUGGABLE DATABASE pdb1 FROM ACTIVE DATABASE DB_FILE_NAME_CONVERT ('ORCL', 'cdb1'); - Read the progress of the duplicate operation from code1. If an error occurs, in another
session, recreate the password file of one of the CDBs so that
the password of
SYSuser matches the password of theSYSuser of the other CDB.
cd $ORACLE_HOME/dbs
orapwd file=orapwcdb1 entries=5 force=Y Enter password for SYS: password - Quit the
rmansession.EXIT - Start a new
rmansession to launch theDUPLICATEcommand.rman - Connect to the source
ORCLCDB.
CONNECT TARGET sys@ORCL target database Password: password
connected to target database: ORCL (DBID=1490974532) - Connect to the auxiliary
cdb1CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password
connected to auxiliary database: CDB1 (DBID=936911243) - Launch the
DUPLICATEcommand.DUPLICATE PLUGGABLE DATABASE pdb1 FROM ACTIVE DATABASE DB_FILE_NAME_CONVERT ('ORCL', 'cdb1'); - Read the progress of the duplicate operation from code2. Observe that the initialization
parameter
REMOTE_RECOVERY_FILE_DESTwas used to restore the foreign archive log. - Quit the session.
EXIT - Log in to
PDB1to verify thatPDB1is duplicated intocdb1.sqlplus sys@cdb1 AS SYSDBA
Enter password: password - Verify that
PDB1is duplicated intocdb1.
It is not easy nor recommended to handle two PDBs with the same name in two different CDBs. Go to the next section to see how to duplicate a PDB under another name.SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO - Set your session to
PDB1to check the content ofHR.REGIONStable inPDB1incdb1.ALTER SESSION SET CONTAINER = PDB1; - Check the content of
HR.REGIONStable inPDB1incdb1.SELECT * FROM hr.regions;
REGION_ID REGION_NAME ---------- ------------------------- 1 Europe 2 Americas 3 Asia 4 Middle East and Africa - To drop the duplicated PDB from
cdb1,first set your session to the CDB root.ALTER SESSION SET CONTAINER = CDB$ROOT; - Close the PDB before you drop it.
ALTER PLUGGABLE DATABASE pdb1 CLOSE; - Drop the duplicated PDB from
cdb1.DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;
Duplicate
a PDB into Another CDB Under a Different PDB Name
In this section, you'll duplicate the active PDB1
from ORCL into cdb1 as
PDB1_IN_CDB1.
- Verify that there is no
PDB1_IN_CDB1incdb1.If there isPDB1_IN_CDB1,then drop the PDB. First, connect to the CDB root.CONNECT sys@cdb1 AS SYSDBA
Enter password: passwordSHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO - Quit the session.
EXIT - Open an
rmansession.
rman - Connect to the source
ORCLCDB.
CONNECT TARGET sys@ORCL target database Password: password connected to target database: ORCL (DBID=1490974532) - Connect to the auxiliary
cdb1CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password connected to auxiliary database: CDB1 (DBID=936911243) - Duplicate
PDB1intocdb1asPDB1_IN_CDB1.DUPLICATE PLUGGABLE DATABASE pdb1 AS pdb1_in_cdb1 FROM ACTIVE DATABASE DB_FILE_NAME_CONVERT ('ORCL', 'cdb1'); - Read the progress of the duplicate operation from code3. Observe that the initialization
parameter
REMOTE_RECOVERY_FILE_DESTwas used to restore the foreign archive log. - Quit the session.
EXIT - Log in to
cdb1to verify thatPDB1is duplicated asPDB1_IN_CDB1intocdb1.sqlplus sys@cdb1 AS SYSDBA
Enter password: password - Verify that
PDB1is duplicated asPDB1_IN_CDB1intocdb1.SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1_IN_CDB1 READ WRITE NO - Set your session to
PDB1_IN_CDB1to check the content ofHR.REGIONStable inPDB1_IN_CDB1incdb1.
ALTER SESSION SET CONTAINER = pdb1_in_cdb1; - Check the content of
HR.REGIONStable inPDB1_IN_CDB1incdb1.SELECT * FROM hr.regions; REGION_ID REGION_NAME ---------- ------------------------- 1 Europe 2 Americas 3 Asia 4 Middle East and Africa
Clean
Up the Tutorial Environment
- To drop the duplicated PDB from
cdb1,first set your session to the CDB root.ALTER SESSION SET CONTAINER = CDB$ROOT; - Close the PDB before you drop it.
ALTER PLUGGABLE DATABASE pdb1 CLOSE; - Drop the duplicated PDB from
cdb1.DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;
Cloning
Active PDBs Using RMAN DUPLICATE