Before You Begin
This 15-minute tutorial shows you how to use Database Configuration Assistant (DBCA) to duplicate a container database (CDB).
Background
In Oracle Database 18c, duplicating a CDB requires several commands to be executed.
What Do You Need?
- Oracle Database 19c installed
- A CDB:
ORCLwithPDB1in archivelog mode. HRschema installed inPDB1as an example of application tables. If you want to use theHR.EMPLOYEEStable, use the hr.sql. Download the SQL script to the labs directory created on your server/home/oracle/labs.In the script, update the password of the user connected to the database.
Check
the Existence of Application Data in the CDB
- Log in to
PDB1inORCLasSYSTEM.sqlplus system@PDB1
Enter password: password - Use the hr.sql
script to create the
HRuser andEMPLOYEEStable inPDB1.@/home/oracle/labs/hr.sql - Verify that
PDB1contains theHR.EMPLOYEEStable.SELECT count(*) FROM hr.employees; COUNT(*) ---------- 107 - Quit the session.
EXIT
Use
DBCA to Duplicate a CDB
In this section, you use DBCA in silent mode to duplicate
ORCL as CDB19 .
- Launch DBCA in silent mode to duplicate
ORCLasCDB19. Update the hostname by your server name in the command.SImeans Single Instance.dbca -silent -createDuplicateDB -gdbName CDB19 -sid CDB19 -primaryDBConnectionString hostname:1521/ORCL -databaseConfigType SI -initParams db_unique_name=CDB19 -sysPassword password -datafileDestination /u02/app/oracle/oradata
Prepare for db operation 22% complete Listener config step 44% complete Auxiliary instance creation 67% complete RMAN duplicate 89% complete Post duplicate database operations 100% complete Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/CDB19/CDB19.log" for further details.
Check
that the CDB Is Duplicated
- Connect to
CDB19asSYS.sqlplus sys@CDB19 AS SYSDBA Enter password: password
SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB1 READ WRITE NO - Check that
PDB1contains theHR.EMPLOYEEStable as inPDB1ofORCL.CONNECT hr@PDB1 Enter password: password
SELECT count(*) FROM employees;
COUNT(*) ---------- 107
Use
DBCA to Duplicate a CDB with OMF
In this section, you use DBCA in silent mode to duplicate ORCL
as CDBOMF19 with OMF files.
- Launch DBCA in silent mode to duplicate
ORCLasCDBOMF19. Update the hostname by your server name in the command.dbca -silent -createDuplicateDB -gdbName CDBOMF19 -sid CDBOMF19 -primaryDBConnectionString hostname:1521/ORCL -databaseConfigType SI -initParams db_unique_name=CDBOMF19 -sysPassword password -datafileDestination /u02/app/oracle/oradata –useOMF=TRUE
Prepare for db operation 22% complete Listener config step 44% complete Auxiliary instance creation 67% complete RMAN duplicate 89% complete Post duplicate database operations 100% complete Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/CDBOMF19/CDBOMF19.log" for further details.
- Connect to
CDBOMF19asSYS.sqlplus sys@CDBOMF19 AS SYSDBA Enter password: password
COL name FORMAT A78 SELECT name FROM v$datafile;
NAME -------------------------------------------------------------------- /u02/app/oracle/oradata/CDBOMF19/system01.dbf ... /u02/app/oracle/oradata/CDBOMF19/PDB1/system01.dbf /u02/app/oracle/oradata/CDBOMF19/PDB1/sysaux01.dbf /u02/app/oracle/oradata/CDBOMF19/PDB1/undotbs01.dbf
... - Quit the session.
EXIT
Clean
Up the CDBs Duplicated
- Use DBCA to delete
CDB19.$ORACLE_HOME/bin/dbca -silent -deleteDatabase -sourceDB CDB19 -sid CDB19 -sysPassword password
- Use DBCA to delete
CDBOMF19.$ORACLE_HOME/bin/dbca -silent -deleteDatabase -sourceDB CDBOMF19 -sid CDBOMF19 -sysPassword password
Duplicate
CDBs using DBCA in Silent Mode