Wednesday, February 03, 2016

Cloning a Non-CDB into a CDB

Cloning a Non-CDB orcl2 into a CDB cdb2

1) First, it needs to switch source Non-CDB orcl2 DB to read only mode.

[oracle@myorasrv ~]$ . oraenv
ORACLE_SID = [cdb2] ? orcl2
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is /u01/app/oracle

[oracle@myorasrv ~]$ sqlplus / as sysdba

SQL> startup mount
SQL> alter database open read only;
SQL> exit

[oracle@myorasrv ~]$ mkdir /u01/app/oracle/oradata/cdb1/pdb_orcl2
[oracle@myorasrv ~]$

2) In the cdb2, create db link that allows a connection to remote non-CDB orcl2 DB

  [oracle@edbxr36p0 ~]$ . oraenv
ORACLE_SID = [orcl2] ? cdb2
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 is /u01/app/oracle
[oracle@edbxr36p0 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed Feb 3 04:42:44 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> CREATE DATABASE LINK link_orcl2
  2  CONNECT TO system IDENTIFIED BY oracle_4U
  3  USING 'orcl2';

Database link created.

3) Clone the source non-CDB DB into the CDB using the database link.

SQL> create pluggable database pdb_orcl2 from NON$CDB@link_orcl2
  2  create_file_dest='/u01/app/oracle/oradata/cdb1/pdb_orcl2';

Pluggable database created.

SQL> exit

4) Create net service name for pdb_prcl2 using netca

$ netca

4) Connect to pdb_orcl2 using the net service name to execute the
noncdb_to_pdb.sql before opening the PDB

[oracle@oramysrv ~]$ sqlplus sys@pdb_orcl2 as sysdba
SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
[oracle@oramysrv ~]$ sqlplus sys@pdb_orcl2 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Feb 4 03:39:14 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Enter password:

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
.....................
SQL> -- leave the PDB in the same state it was when we started
SQL> BEGIN
  2    execute immediate '&open_sql &restricted_state';
  3  EXCEPTION
  4    WHEN OTHERS THEN
  5    BEGIN
  6      IF (sqlcode <> -900) THEN
  7        RAISE;
  8      END IF;
  9    END;
 10  END;
 11  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> WHENEVER SQLERROR CONTINUE;
SQL> alter pluggable database pdb_orcl2 open;

Pluggable database altered.
SQL> EXIT;

[oracle@myorasrv ~]$ sqlplus sys@pdb_orcl2 as sysdba

Enter password:

SQL> select count(empno) from scott.emp;

COUNT(EMPNO)
------------
      14
 

No comments: