Oracle by Example brandingCloning Active PDBs Using RMAN DUPLICATE

section 0Before 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 the TARGET in DUPLICATE 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 user HR with demo data

section 1Duplicate a PDB into Another CDB

In this section, you'll duplicate the active PDB1 from ORCL into cdb1.

  1. Log in to ORCL to verify the existence of PDB1 in ORCL.
    sqlplus sys@ORCL AS SYSDBA
    Enter password: password
  2. 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
  3. To check the content of the HR.REGIONS table in PDB1, first connect to PDB1.
    CONNECT hr@PDB1 
    Enter password: password
  4. 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
  5. Connect to CDB1 to verify that there is no PDB1 in cdb1.
    CONNECT sys@cdb1 AS SYSDBA
    Enter password: password
  6. Verify that there is no PDB1 in cdb1.
    SHOW PDBS
    CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO
  7. Set the initialization parameter REMOTE_RECOVERY_FILE_DEST in cdb1 to restore the foreign archive log.
    ALTER SYSTEM SET REMOTE_RECOVERY_FILE_DEST='/home/oracle/labs' SCOPE=BOTH;
  8. Quit the session.
    EXIT
  9. Open an rman session.
    rman
  10. Connect to the source ORCL CDB.
    CONNECT TARGET sys@ORCL
    
    target database Password: password  
    connected to target database: ORCL (DBID=1490974532)
  11. Connect to the auxiliary cdb1 CDB.
    CONNECT AUXILIARY sys@cdb1
    
    auxiliary database Password: password 
    connected to auxiliary database: CDB1 (DBID=936911243)
  12. Duplicate PDB_ORCL into cdb1.
    DUPLICATE PLUGGABLE DATABASE pdb1 FROM ACTIVE DATABASE
              DB_FILE_NAME_CONVERT ('ORCL', 'cdb1');
  13. 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 the SYS user of the other CDB.
    cd $ORACLE_HOME/dbs
    orapwd file=orapwcdb1 entries=5 force=Y Enter password for SYS: password
  14. Quit the rman session.
    EXIT
  15. Start a new rman session to launch the DUPLICATE command.
    rman
  16. Connect to the source ORCL CDB.
    CONNECT TARGET sys@ORCL
    
    target database Password: password  
    connected to target database: ORCL (DBID=1490974532)
  17. Connect to the auxiliary cdb1 CDB.
    CONNECT AUXILIARY sys@cdb1
    
    auxiliary database Password: password 
    connected to auxiliary database: CDB1 (DBID=936911243)
  18. Launch the DUPLICATE command.
    DUPLICATE PLUGGABLE DATABASE pdb1 FROM ACTIVE DATABASE
              DB_FILE_NAME_CONVERT ('ORCL', 'cdb1');
  19. 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.
  20. Quit the session.
    EXIT
  21. Log in to PDB1 to verify that PDB1 is duplicated into cdb1.
    sqlplus sys@cdb1 AS SYSDBA 
    Enter password: password
  22. Verify that PDB1 is duplicated into cdb1.
    SHOW PDBS 
    CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO
    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.
  23. Set your session to PDB1 to check the content of HR.REGIONS table in PDB1 in cdb1.
    ALTER SESSION SET CONTAINER = PDB1;
  24. Check the content of HR.REGIONS table in PDB1 in cdb1.
    SELECT * FROM hr.regions;

    REGION_ID REGION_NAME ---------- ------------------------- 1 Europe 2 Americas 3 Asia 4 Middle East and Africa
  25. To drop the duplicated PDB from cdb1, first set your session to the CDB root.
    ALTER SESSION SET CONTAINER = CDB$ROOT;
  26. Close the PDB before you drop it.
    ALTER PLUGGABLE DATABASE pdb1 CLOSE;
  27. Drop the duplicated PDB from cdb1.
    DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;

section 2Duplicate 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.

  1. Verify that there is no PDB1_IN_CDB1 in cdb1. If there is PDB1_IN_CDB1, then drop the PDB. First, connect to the CDB root.
    CONNECT sys@cdb1 AS SYSDBA 
    Enter password: password
    SHOW PDBS 
    CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO
  2. Quit the session.
    EXIT
  3. Open an rman session.
    rman
  4. Connect to the source ORCL CDB.
    CONNECT TARGET sys@ORCL
    
    target database Password: password
    connected to target database: ORCL (DBID=1490974532)
    
  5. Connect to the auxiliary cdb1 CDB.
    CONNECT AUXILIARY sys@cdb1
    
    auxiliary database Password: password
    connected to auxiliary database: CDB1 (DBID=936911243)
    
  6. Duplicate PDB1 into cdb1 as PDB1_IN_CDB1.
    DUPLICATE PLUGGABLE DATABASE pdb1 AS pdb1_in_cdb1 
              FROM ACTIVE DATABASE
              DB_FILE_NAME_CONVERT ('ORCL', 'cdb1');
  7. 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.
  8. Quit the session.
    EXIT
  9. Log in to cdb1 to verify that PDB1 is duplicated as PDB1_IN_CDB1 into cdb1.
    sqlplus sys@cdb1 AS SYSDBA
    Enter password: password
  10. Verify that PDB1 is duplicated as PDB1_IN_CDB1 into cdb1.
    SHOW PDBS 
    CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1_IN_CDB1 READ WRITE NO
  11. Set your session to PDB1_IN_CDB1 to check the content of HR.REGIONS table in PDB1_IN_CDB1 in cdb1.
    ALTER SESSION SET CONTAINER = pdb1_in_cdb1;
  12. Check the content of HR.REGIONS table in PDB1_IN_CDB1 in cdb1.
    SELECT * FROM hr.regions;
    
     REGION_ID REGION_NAME
    ---------- -------------------------
             1 Europe
             2 Americas
             3 Asia
             4 Middle East and Africa

section 3Clean Up the Tutorial Environment

  1. To drop the duplicated PDB from cdb1, first set your session to the CDB root.
    ALTER SESSION SET CONTAINER = CDB$ROOT;
  2. Close the PDB before you drop it.
    ALTER PLUGGABLE DATABASE pdb1 CLOSE;
  3. Drop the duplicated PDB from cdb1.
    DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;