Oct 10, 2016

Clone a PDB in different Container Database - Oracle 12c

Prerequisites:

The prerequisites for cloning a remote PDB or non-CDB are very similar, so I will deal with them together.

Source:

Create one pdb:
$ export ORACLE_SID=CDB
$ sqlplus / as sysdba

SQL> CREATE PLUGGABLE DATABASE hrpdb 
ADMIN USER hradmin IDENTIFIED BY hradmin
DEFAULT TABLESPACE hr 
DATAFILE '/u10/EXAM/ORADATA/CDB/hrpdb/hr01.dbf' SIZE 250M AUTOEXTEND ON
PATH_PREFIX = '/u10/EXAM/ORADATA/CDB/hrpdb/'
FILE_NAME_CONVERT = ('/u10/EXAM/ORADATA/CDB/pdbseed/', '/u10/EXAM/ORADATA/CDB/hrpdb/');

Pluggable database created.

Unplug the PDB in source:

SQL> ALTER PLUGGABLE DATABASE hrpdb close immediate;

SQL> ALTER PLUGGABLE DATABASE hrpdb UNPLUG INTO '/u10/EXAM/bkp_pdb/hrpdb.xml';

Pluggable database altered.

-- Copy the XML file along with datafiles to target host with creating paths:

$ cd /u10/EXAM/ORADATA/CDB/hrpdb
[oracle@eh-uatdb1 hrpdb]$ ls
hr01.dbf  pdbseed_temp012016-10-04_03-18-32-PM.dbf  sysaux01.dbf  system01.dbf

[oracle@eh-uatdb1 hrpdb]$ scp *.dbf oracle@172.18.1.18:/u10/EXAM/ORADATA/CDB/hrpdb

-- In target host create the folder structure for datafiles

$ cd /u10/EXAM/ORADATA/CDB/
[oracle@eh-uatdb2 CDB]$ mkdir hrpdb
[oracle@eh-uatdb2 CDB]$ cd hrpdb/
[oracle@eh-uatdb2 hrpdb]$ pwd
/u10/EXAM/ORADATA/CDB/hrpdb

Note : Give full permissions to .xml file in target host.

SQL> CREATE PLUGGABLE DATABASE hrpdb USING '/u10/EXAM/pdb_bkps/hrpdb.xml' NOCOPY TEMPFILE REUSE;

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 SALESPDB                       READ WRITE NO
         5 PDB2                           READ WRITE NO
         6 HRPDB                          MOUNTED
SQL> alter pluggable database HRPDB open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 SALESPDB                       READ WRITE NO
         5 PDB2                           READ WRITE NO
         6 HRPDB                          READ WRITE NO
SQL>

Note :
1) The files are in the correct location. Therefore, NOCOPY is included
2) A file with the same name as the temp file specified in the XML file exists in the target location. Therefore, the TEMPFILE REUSE clause is required.

Here are other options to clone PDB in different hosts:

--  In case datafile location is changed in Target, the use below format:

CREATE PLUGGABLE DATABASE salespdb USING '/disk1/usr/salespdb.xml' 
  SOURCE_FILE_NAME_CONVERT = ('/disk1/oracle/oradata/sales/', '/disk2/oracle/oradata/sales/')
  NOCOPY TEMPFILE REUSE;

-- Plugging In an Unplugged PDB Using the AS CLONE and NOCOPY Clauses

CREATE PLUGGABLE DATABASE salespdb AS CLONE USING '/disk1/usr/salespdb.xml' 
  NOCOPY TEMPFILE REUSE;

-- Plugging In an Unplugged PDB With the COPY, PATH_PREFIX, and FILE_NAME_CONVERT Clauses

CREATE PLUGGABLE DATABASE salespdb USING '/disk1/usr/salespdb.xml' 
  COPY
  PATH_PREFIX = '/disk2/oracle/oradata/sales/'
  FILE_NAME_CONVERT = ('/disk1/oracle/oradata/sales/', '/disk2/oracle/oradata/sales/');

Note:

1) The XML file does not accurately describe the current locations of the files. Therefore, the SOURCE_FILE_NAME_CONVERT clause orSOURCE_FILE_DIRECTORY clause is required. In this example, the XML file indicates that the files are in /disk1/oracle/oradata/sales, but the files are in /disk2/oracle/oradata/sales, and the SOURCE_FILE_NAME_CONVERT clause is used.
2) The new PDB is based on the same unplugged PDB that was used to create an existing PDB in the CDB. Therefore, the AS CLONE clause is required. The AS CLONE clause ensures that the new PDB has unique identifiers.
3) The PDB's relative directory object paths must be treated as relative to a specific directory. Therefore, the PATH_PREFIX clause is required. In this example, the PDB's relative directory object paths must be treated as relative to the /disk2/oracle/oradata/sales directory and its subdirectories.



4 comments:

Translate >>