Clone PDB using duplicate
http://dba-blogs.blogspot.com/2013/10/12c-clone-pdbs-online.html (12.1.0.1))
https://www.red-gate.com/simple-talk/sql/oracle/duplicate-point-in-time-recovered-pdb-using-backup/ (12.1.0.2)
Clone PDB from local PDB in the same CDB :
NOTE : In Oracle 12.1.0.1c, a pluggable database can be cloned only if it is read-only.
In Oracle 12.1.0.2c: PDBs can be hot cloned, i.e. you don’t need to put the source PDB n read only
If the directory is not already present, it will be automatically created as part of the cloning operation.
-- connect to container CDB1
SQL> conn sys/oracle@cdb1 as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
CDB1>select name, cdb from v$database;
NAME CDB
--------- ---
CDB1 YES
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
ORCL READ WRITE
PROD READ WRITE <--- PROD is pdb database
-- Make read only (not required 12.2.0.2)
Method I : Make read only
Alter pluggable database PROD open read only force;
Method II : Make read only
SQL> alter session set container=PROD;
SQL> show con_name
CON_NAME
------------------------------
PROD
SQL> shutdown immediate;
Pluggable Database closed.
SQL> startup open read only
Pluggable Database opened.
-- Clone pluggable
SQL> conn sys/oracle@cdb1 as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> create pluggable database PROD_CL
from PROD
FILE_NAME_CONVERT=('/home/oracle/app/oracle/oradata/cdb1/prod','/home/oracle/app/oracle/oradata/cdb1/PROD_CL');
Pluggable database created.
Sql>show pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
ORCL READ WRITE
PROD READ ONLY
PROD_CL MOUNTED
Make Both read write ( In 12.2.0.2, not required for source as it's already open)
Method I : Make Both read write
Alter pluggable database PROD open read write force;
Alter pluggable database PROD ,PROD_CL open read write force;
Method II : Make Both read write
SQL> alter session set CONTAINER=PROD;
Session altered.
SQL> shutdown immediate;
SQL> startup
SQL> alter session set container=PROD_CL
SQL> startup
---Test the environrment
SQL> conn sys/oracle@cdb1 as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
ORCL READ WRITE
PROD READ WRITE
PROD_CL READ WRITE
Make tnsnames entries and connect to the PROD_CL
Hot Cloning :
In 12.2.0.2, source PDP is not required to be made read only. So steps marked in Green above won't be required.
Clone PDB from remote PDB in the remote CDB :
Create a user in the remote database for use with the database link.
CREATE USER c##remote_clone_user IDENTIFIED BY remote_clone_user CONTAINER=ALL;
GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO c##remote_clone_user CONTAINER=ALL;
Create a DB Link in the target CDB which connects to source container database and repeat above
Hot Cloning:
CREATE PLUGGABLE DATABASE db12cpdb FROM NONCDB@db_link;
Old Method :
Put the source PDB in read only and then clone
Clone PDB from existing non-CDB in the remote location (Hot cloning/DBMS_PDB/expdp) :
Old Method : DBMS_PDB and read only
Log into source noncdb as sys
shut down and Open it in read only mode
Run DBMS_PDB.DESCRIBE to create an XML file describing the database.
Connect to target CDB (CDB2)
Check whether noncdb can be plugged into target CDB(CDB2) using DBMS_PDB.CHECK_PLUG_COMPATIBILITY and PDB_PLUG_IN_VIOLATIONS view
Plug-in Non-CDB as PDB(NCDB12c) into target CDB(CDB2) : create pluggable...COPY file_name_convert...
Access the PDB and run the noncdb_to_pdb.sql script.
Open the new PDB in read/write mode.
Hot cloning : No DBMS_PDB and no read only required
CREATE PLUGGABLE DATABASE db12cpdb FROM NONCDB@db_link;
(Since there is no PDB to name, we use "NONCDB" as the PDB name.)
ALTER PLUGGABLE DATABASE db12cpdb OPEN;
ALTER SESSION SET CONTAINER=db12cpdb;
Note : Running noncdb_to_pdb.sql is also not required