8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » 18c » Here

Multitenant : Duplicate a Pluggable Database (PDB) to an existing Container Database (CDB) in Oracle Database 18c

Oracle 18c allows you to duplicate a pluggable database (PDB) from one container database (CDB) instance to another existing CDB instance using RMAN. There are alternatives, like hot cloning.

Multitenant : Duplicate PDB

Oracle 12c introduced RMAN new features to allow the duplication of PDBs to a CDB, where the new CDB was initially created as an auxiliary instance. This new feature is similar, but it uses a regular CDB instance, rather than an auxiliary instance.

Related articles.

Assumptions

Duplicate a PDB to an existing CDB

We duplicate a pluggable database using the RMAN DUPLICATE command using the PLUGGABLE DATABASE clause. This comes in two basic forms, depending on whether we want to retain the original PDB name, or rename it. Remember, if you duplicate a PDB to a destination CDB that shares the same listener as the source CDB, you must rename it or it will share the same service name as the original source PDB.

DUPLICATE PLUGGABLE DATABASE {source-pdb} TO {destination-cdb} 
...
FROM ACTIVE DATABASE
...;

DUPLICATE PLUGGABLE DATABASE {source-pdb} AS {destination-pdb} TO {destination-cdb} 
...
FROM ACTIVE DATABASE
...;

As you might expect, if we didn't use Oracle Managed Files (OMF) we would need to cope with any file renames.

DUPLICATE PLUGGABLE DATABASE {source-pdb} TO {destination-cdb} 
DB_FILE_NAME_CONVERT('{source-cdb}','{destination-cdb}','{source-pdb}','{deat-pdb}')
FROM ACTIVE DATABASE
...;

In the example below we duplicate pdb1 in cdb1 to pdb2 in cdb3.

export ORACLE_SID=cdb1
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

rman target=sys/SysPassword1@cdb1 auxiliary=sys/SysPassword1@cdb3 <<EOF

DUPLICATE PLUGGABLE DATABASE pdb1 AS pdb2 TO cdb3 
FROM ACTIVE DATABASE 
SECTION SIZE 400M;

exit;
EOF

Here is the output from the command.

Starting Duplicate PDB at 28-DEC-18
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=32 device type=DISK
current log archived

contents of Memory Script:
{
   set newname for clone datafile  9 to new;
   set newname for clone datafile  10 to new;
   set newname for clone datafile  11 to new;
   set newname for clone datafile  12 to new;
   restore
   from  nonsparse   section size
 400 m   clone foreign pluggable database
    "PDB1"
   from service  'cdb1'   ;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 28-DEC-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring section 1 of 1
channel ORA_AUX_DISK_1: restoring foreign file 9 to /u02/oradata/CDB3/7E16165026D8778DE055000000000001/datafile/o1_mf_system_g2dh0l7c_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring section 1 of 1
channel ORA_AUX_DISK_1: restoring foreign file 10 to /u02/oradata/CDB3/7E16165026D8778DE055000000000001/datafile/o1_mf_sysaux_g2dh0ofl_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring section 1 of 1
channel ORA_AUX_DISK_1: restoring foreign file 11 to /u02/oradata/CDB3/7E16165026D8778DE055000000000001/datafile/o1_mf_undotbs1_g2dh0rlt_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring section 1 of 1
channel ORA_AUX_DISK_1: restoring foreign file 12 to /u02/oradata/CDB3/7E16165026D8778DE055000000000001/datafile/o1_mf_users_g2dh0sq9_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 28-DEC-18
current log archived

contents of Memory Script:
{
   set archivelog destination to  '/u01/app/oracle/fast_recovery_area';
   restore clone force from service  'cdb1'
           foreign archivelog from scn  1558681;
}
executing Memory Script

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 28-DEC-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to user-specified destination
archived log destination=/u01/app/oracle/fast_recovery_area
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=22
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to user-specified destination
archived log destination=/u01/app/oracle/fast_recovery_area
channel ORA_AUX_DISK_1: using network backup set from service cdb1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=23
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 28-DEC-18

Performing import of metadata...
Finished Duplicate PDB at 28-DEC-18

RMAN>

If we connect to the cdb3 instance, we can see the new PDB has been created as expected.

export ORACLE_SID=cdb3
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

sqlplus / as sysdba

COLUMN name FORMAT A30

SELECT name, open_mode
FROM   v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB2                           READ WRITE

SQL>

Appendix

The two container database instances were built using the following commands. The commands to remove the instances are included, so you can clean up when you are finished.

# Create FRA location.
mkdir -p /u01/app/oracle/fast_recovery_area

# Container (cdb1) with PDB (pdb1).
dbca -silent -createDatabase \
 -templateName General_Purpose.dbc \
 -gdbname cdb1 -sid cdb1 -responseFile NO_VALUE \
 -characterSet AL32UTF8 \
 -sysPassword SysPassword1 \
 -systemPassword SysPassword1 \
 -createAsContainerDatabase true \
 -numberOfPDBs 1 \
 -pdbName pdb1 \
 -pdbAdminPassword SysPassword1 \
 -databaseType MULTIPURPOSE \
 -memoryMgmtType auto_sga \
 -totalMemory 2048 \
 -storageType FS \
 -datafileDestination "/u02/oradata/" \
 -redoLogFileSize 50 \
 -emConfiguration NONE \
 -ignorePreReqs

export ORACLE_SID=cdb1
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

# Set required parameters.
sqlplus / as sysdba <<EOF
alter pluggable database pdb1 save state;
alter system set db_create_file_dest = '/u02/oradata';
alter system set db_recovery_file_dest_size = 10G;
alter system set db_recovery_file_dest = '/u01/app/oracle/fast_recovery_area';
exit;
EOF

# Enable ARCHIVELOG mode.
sqlplus / as sysdba <<EOF
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
exit;
EOF


# Empty container (cdb3).
dbca -silent -createDatabase \
 -templateName General_Purpose.dbc \
 -gdbname cdb3 -sid cdb3 -responseFile NO_VALUE \
 -characterSet AL32UTF8 \
 -sysPassword SysPassword1 \
 -systemPassword SysPassword1 \
 -createAsContainerDatabase true \
 -numberOfPDBs 0 \
 -databaseType MULTIPURPOSE \
 -memoryMgmtType auto_sga \
 -totalMemory 2048 \
 -storageType FS \
 -datafileDestination "/u02/oradata/" \
 -redoLogFileSize 50 \
 -emConfiguration NONE \
 -ignorePreReqs

export ORACLE_SID=cdb3
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

# Set required parameters.
sqlplus / as sysdba <<EOF
alter system set db_create_file_dest = '/u02/oradata';
alter system set remote_recovery_file_dest = '/u01/app/oracle/fast_recovery_area';
exit;
EOF


# Delete the instances.
#dbca -silent -deleteDatabase -sourceDB cdb1 -sysDBAUserName sys -sysDBAPassword SysPassword1
#dbca -silent -deleteDatabase -sourceDB cdb3 -sysDBAUserName sys -sysDBAPassword SysPassword1

For more information see:

Hope this helps. Regards Tim...

Back to the Top.