Visit Counter

Wednesday, November 20, 2013

Migrate a Non-Container Database (CDB) to a Pluggable Database (PDB) in Oracle Database 12c


Migrate a Non-Container DB (CDB) to PDB

Container DB: CDB2

Non-PDB:       PDB7


 Shutdown the non-CDB and start it in read-only mode.

$ export ORACLE_SID=pdb7

$ sqlplus / as sysdba

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup open read only;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size    2293880 bytes
Variable Size  595595144 bytes
Database Buffers  234881024 bytes
Redo Buffers    2334720 bytes
Database mounted.
Database opened.


This procedure creates an XML file in the same way that the unplug operation does for a PDB.

SQL> 
SQL> begin
  2  DBMS_PDB.DESCRIBE(
  3  pdb_descr_file => '/tmp/db12c.xml');
  4  end;
  5  /

PL/SQL procedure successfully completed.


Shutdown the non-CDB database.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

$ oracle@oracle12c bin]$ export ORACLE_SID=cdb2


$ oracle@oracle12c bin]$ ./sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on SEPT 21 01:15:21 2013

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

Connect to an existing CDB and create a new PDB using the file describing the non-CDB database. Remember to configure the FILE_NAME_CONVERT parameter to convert the existing files to the new location.


SQL> create pluggable database pdb7 using '/tmp/db12c.xml'
  2  copy    
  3  file_name_convert = ('/ora/oracle/app/oracle/oradata/pdb7/','/ora/oracle/app/oracle/oradata/cdb2/pdb7/');

Pluggable database created.
System altered.


Switch to the PDB container and run the "$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql" script to clean up the new PDB, removing any items that should not be present in a PDB. You can see an example of the output produced by this script here.

SQL> alter session set container = pdb7;

Session altered.

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> WHENEVER SQLERROR CONTINUE;

Startup the PDB and check the open mode.

SQL> alter session set container=pdb7;

Session altered.

SQL> alter pluggable database open;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;

NAME                           OPEN_MODE
------------------------------ ------------------------
PDB7                           READ WRITE

1 row selected.




NcFTP Client for copying files to remote location



http://www.ncftp.com/ncftp/

Download ncftp client

# vi xyz.sh

 cd /ncftp-3.2.4/bin

./ncftpput -DD -u admin -p xyz123 192.0.0.120 /Archivelog1 /ora_temp/archive1/*.dbf


Username:  admin
Password:  xyz123
Remotely Location IP: 192.0.0.120
Remotely Folder: Archivelog1
host Location Folder: /ora_temp/archive1