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 theTARGET
inDUPLICATE
command) 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) PDB1
includes an unlocked userHR
with demo data
Duplicate a PDB into Another CDB
In this section, you'll duplicate the active PDB1
from ORCL
into cdb1.
- Log in to
ORCL
to verify the existence ofPDB1
inORCL.
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.REGIONS
table inPDB1,
first connect toPDB1.
CONNECT hr@PDB1
Enter password: password - Display the content of
HR.REGIONS
table.SELECT * FROM hr.regions;
REGION_ID REGION_NAME ---------- ------------------------- 1 Europe 2 Americas 3 Asia 4 Middle East and Africa - Connect to
CDB1
to verify that there is noPDB1
incdb1.
CONNECT sys@cdb1 AS SYSDBA
Enter password: password - Verify that there is no
PDB1
incdb1.
SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO - Set
the initialization parameter
REMOTE_RECOVERY_FILE_DEST
incdb1
to restore the foreign archive log.ALTER SYSTEM SET REMOTE_RECOVERY_FILE_DEST='/home/oracle/labs' SCOPE=BOTH;
- Quit the session.
EXIT
- Open an
rman
session.
rman
- Connect to the source
ORCL
CDB.
CONNECT TARGET sys@ORCL target database Password: password
connected to target database: ORCL (DBID=1490974532) - Connect to the auxiliary
cdb1
CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password
connected to auxiliary database: CDB1 (DBID=936911243) - Duplicate
PDB_ORCL
intocdb1.
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
SYS
user matches the password of theSYS
user of the other CDB.
cd $ORACLE_HOME/dbs
orapwd file=orapwcdb1 entries=5 force=Y Enter password for SYS: password - Quit the
rman
session.EXIT
- Start a new
rman
session to launch theDUPLICATE
command.rman
- Connect to the source
ORCL
CDB.
CONNECT TARGET sys@ORCL target database Password: password
connected to target database: ORCL (DBID=1490974532) - Connect to the auxiliary
cdb1
CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password
connected to auxiliary database: CDB1 (DBID=936911243) - Launch the
DUPLICATE
command.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_DEST
was used to restore the foreign archive log. - Quit the session.
EXIT
- Log in to
PDB1
to verify thatPDB1
is duplicated intocdb1.
sqlplus sys@cdb1 AS SYSDBA
Enter password: password - Verify that
PDB1
is 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
PDB1
to check the content ofHR.REGIONS
table inPDB1
incdb1.
ALTER SESSION SET CONTAINER = PDB1;
- Check the content of
HR.REGIONS
table inPDB1
incdb1.
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_CDB1
incdb1.
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
rman
session.
rman
- Connect to the source
ORCL
CDB.
CONNECT TARGET sys@ORCL target database Password: password connected to target database: ORCL (DBID=1490974532)
- Connect to the auxiliary
cdb1
CDB.
CONNECT AUXILIARY sys@cdb1 auxiliary database Password: password connected to auxiliary database: CDB1 (DBID=936911243)
- Duplicate
PDB1
intocdb1
asPDB1_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_DEST
was used to restore the foreign archive log. - Quit the session.
EXIT
- Log in to
cdb1
to verify thatPDB1
is duplicated asPDB1_IN_CDB1
intocdb1.
sqlplus sys@cdb1 AS SYSDBA
Enter password: password - Verify that
PDB1
is duplicated asPDB1_IN_CDB1
intocdb1.
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_CDB1
to check the content ofHR.REGIONS
table inPDB1_IN_CDB1
incdb1.
ALTER SESSION SET CONTAINER = pdb1_in_cdb1;
- Check the content of
HR.REGIONS
table inPDB1_IN_CDB1
incdb1.
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;