Database 12c: Duplicate PDB


Today morning I wanted to check how to duplicate a PDB. The first questions to me were:

  • Duplicate PDB, how to create an empty PDB and bring it to nomount like non-cdbs?
  • Duplicate within a CDB?

Here the answer:

The duplication process of a PDB works at CDB level. So if you want to duplicate a PDB you have to create an empty CDB instance. Then the needed parts of the CDB will be cloned and all other dropped. This will answer the second question: duplication within a CDB is not out-of-the-box possible. But you are able to clone the PDB or use a shadow CDB.

Here the example to clone:

Setup:

  • Target CDB = CDB12C1
  • Auxiliary CDB = CDB12C3
  • PDB to duplicate = Only PDB1
[bash]$ rman target sys/<password>@cdb12c1 auxiliary sys/<password>@cdb12c3

Recovery Manager: Release 12.1.0.1.0 - Production on Sat Jul 20 13:15:57 2013

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CDB12C1 (DBID=2076797181)
connected to auxiliary database: CDB12C3 (not mounted)

RMAN> duplicate target database to CDB12C3 pluggable database pdb1 from active database;

Starting Duplicate Db at 20-JUL-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CDB12C1'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''CDB12C3'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'cdb12c1' primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''CDB12C1'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''CDB12C3'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes

Starting restore at 20-JUL-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/app/oradata/CDB12C3/control01.ctl
Finished restore at 20-JUL-13

database mounted
Skipping pluggable database PDB2
Automatically adding tablespace SYSTEM
Automatically adding tablespace SYSAUX
Automatically adding tablespace PDB$SEED:SYSTEM
Automatically adding tablespace PDB$SEED:SYSAUX
Automatically adding tablespace UNDOTBS1
Skipping tablespace USERS

contents of Memory Script:
{
   set newname for clone datafile  1 to new;
   set newname for clone datafile  3 to new;
   set newname for clone datafile  4 to new;
   set newname for clone datafile  5 to new;
   set newname for clone datafile  7 to new;
   set newname for clone datafile  21 to new;
   set newname for clone datafile  22 to new;
   restore
   from service  'cdb12c1'   clone database
   skip forever tablespace  "USERS",
 "PDB2":"SYSTEM",
 "PDB2":"SYSAUX"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 20-JUL-13
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 cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_%u_.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 cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00021 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_%u_.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 cdb12c1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00022 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 20-JUL-13

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'cdb12c1' 
           archivelog from scn  2534976;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 20-JUL-13
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=97
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service cdb12c1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=98
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20-JUL-13

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwdjk0_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwf5kv_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=14 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf
datafile 21 switched to datafile copy
input datafile copy RECID=15 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwfhny_.dbf
datafile 22 switched to datafile copy
input datafile copy RECID=16 STAMP=821279836 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf

contents of Memory Script:
{
   set until scn  2535061;
   recover
   clone database
   skip forever tablespace  "USERS",
 "PDB2":"SYSTEM",
 "PDB2":"SYSAUX"    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 20-JUL-13
using channel ORA_AUX_DISK_1

Executing: alter database datafile 6 offline drop
Executing: alter database datafile 23 offline drop
Executing: alter database datafile 24 offline drop
starting media recovery

archived log for thread 1 with sequence 97 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_97_8ynwft7h_.arc
archived log for thread 1 with sequence 98 is already on disk as file /opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_98_8ynwfv8y_.arc
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_97_8ynwft7h_.arc thread=1 sequence=97
archived log file name=/opt/oracle/app/fast_recovery_area/CDB12C3/archivelog/2013_07_20/o1_mf_1_98_8ynwfv8y_.arc thread=1 sequence=98
media recovery complete, elapsed time: 00:00:00
Finished recover at 20-JUL-13
Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CDB12C3'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
}
executing Memory Script

sql statement: alter system set  db_name =  ''CDB12C3'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile
Oracle instance started

Total System Global Area     417546240 bytes

Fixed Size                     2289064 bytes
Variable Size                293601880 bytes
Database Buffers             113246208 bytes
Redo Buffers                   8409088 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CDB12C3" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1  SIZE 50 M ,
  GROUP   2  SIZE 50 M ,
  GROUP   3  SIZE 50 M 
 DATAFILE
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwdjk0_.dbf',
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwf5kv_.dbf',
  '/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_system_8ynwfhny_.dbf'
 CHARACTER SET AL32UTF8

contents of Memory Script:
{
   set newname for clone tempfile  1 to new;
   set newname for clone tempfile  2 to new;
   set newname for clone tempfile  3 to new;
   switch clone tempfile all;
   catalog clone datafilecopy  "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf", 
 "/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 2 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_temp_%u_.tmp in control file

cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf RECID=1 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf RECID=2 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf RECID=3 STAMP=821279854
cataloged datafile copy
datafile copy file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf RECID=4 STAMP=821279854

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwdqkh_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_undotbs1_8ynwdynw_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=3 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwf8lz_.dbf
datafile 22 switched to datafile copy
input datafile copy RECID=4 STAMP=821279854 file name=/opt/oracle/app/oradata/CDB12C3/datafile/o1_mf_sysaux_8ynwflo0_.dbf

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Executing: drop pluggable database "PDB2"

contents of Memory Script:
{
   sql clone "alter pluggable database all open";
}
executing Memory Script

sql statement: alter pluggable database all open
Dropping offline and skipped tablespaces
Executing: alter database default tablespace system
Executing: drop tablespace "USERS" including contents cascade constraints
Finished Duplicate Db at 20-JUL-13

RMAN>

Now check the new PDB

SQL> select * from v$pdbs

    CON_ID       DBID    CON_UID GUID                             NAME                           OPEN_MODE  RES OPEN_TIME                                                                   CREATE_SCN TOTAL_SIZE
---------- ---------- ---------- -------------------------------- ------------------------------ ---------- --- --------------------------------------------------------------------------- ---------- ----------
         2 4063775335 4063775335 E1E189D14D2C2049E0430100007FAB5B PDB$SEED                       READ ONLY  NO  20-JUL-13 01.17.36.174 PM                                                      1720752  283115520
         3 3328955419 3328955419 E1EE338E12A16C3EE0430100007F1A4F PDB1                           READ WRITE NO  20-JUL-13 01.17.39.820 PM                                                      2502055  283115520

SQL> 

Important to know is that the GUID of the PDB doesn’t change in the new CDB.