Saturday 2 January 2016

12c : Clone a Remote Non-Container Database CDB

---------------------------------------------------------------------------
Multitenant : Clone a Remote Pluggable Database (PDB)
---------------------------------------------------------------------------
-- In my case Two database exist on my single machine One is CDB database and Second is Non-CDB.



-- Connect to remote non-CDB.
sqlplus sys/oracle@db12c as sysdba

SQL> select name,open_mode from v$database;

SQL> show con_name


-- create a user we can point a database link to.

SQL> drop user remote_clone_user CASCADE;


SQL> CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user;
create user remote_clone_user identified by remote_clone_user
            *
ERROR at line 1:
ORA-65096: invalid common user or role name


SQL> alter session set "_ORACLE_SCRIPT"=true;


SQL> CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user;


SQL> grant create session,create pluggable database to remote_clone_user;



-- Switch the remote non-CDB to read-only mode.

shutdown immediate
startup mount
alter database open read only;


-- Connect to root container in the local CDB.
sqlplus sys/oracle@cdb1 AS sysdba


-- Check database name.
SQL> select name from v$database;


-- Create a database link to the remote PDB
SQL> Drop database link clone_link
SQL> Create Database Link clone_link connect to remote_clone_user identified by remote_clone_user using 'db12c';


-- Clone the remote PDB over the database link.
-- If You are not using OMF, Convert the paths if necessary.
SQL> Create Pluggable Database db12cpdb from NON$CDB@clone_link
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/DB12C/','/u01/app/oracle/oradata/CDB1/db12cpdb/');

---else OMF

Create Pluggable Database db12cpdb from NON$CDB@clone_link
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/DB12C/datafile/o1_mf_system_c6lq1ynk_.dbf',
'/u01/app/oracle/oradata/CDB1/DB12CPDB/datafile/system01.dbf',
'/u01/app/oracle/oradata/DB12C/datafile/o1_mf_sysaux_c6lpcz6v_.dbf',
'/u01/app/oracle/oradata/CDB1/DB12CPDB/datafile/sysaux01.dbf',
'/u01/app/oracle/oradata/DB12C/datafile/o1_mf_users_c6z4wyn8_.dbf',
'/u01/app/oracle/oradata/CDB1/DB12CPDB/datafile/users01.dbf',
'/u01/app/oracle/oradata/DB12C/datafile/o1_mf_temp_c6z65ljc_.tmp',
'/u01/app/oracle/oradata/CDB1/DB12CPDB/datafile/temp01.dbf');

-- Check the PDBs.
SQL> select name,open_mode from v$pdbs order by name;



-- Clean up extra components not found in a PDB.
-- ALTER SESSION SET CONTAINER=db12cpdb;
-- @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql


alter pluggable database db12cpdb OPEN;


-- Open the remote non-CDB in read-write mode again.
SQL> conn sys/oracle@cb12c as sysdba

shutdown immediate
startup



-- Clean up new clone
conn sys/oracle@cdb1 as sysdba

alter pluggable database db12cpdb close;

drop pluggable database db12cpdb including datafiles;

-- Check the PDBs.

SQL> select name,open_mode from v$pdbs order by name;


No comments: