Migrate NON-CDB to CDB

Standalone --> nscdb1
1.) Clear Shutdown on NON-CDB

shut immediate;
startup open read only;
select open_mode from v$database;

2.) Describe and Compatibility

BEGIN
  DBMS_PDB.DESCRIBE(
    pdb_descr_file => '/home/oracle/pdbs/nscdb1.xml');
END;
/

shut immediate;
exit

. oraenv
cdbst

sqlplus / as sysdba

set serveroutput on
 
DECLARE
   compatible BOOLEAN := FALSE;
BEGIN  
   compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/home/oracle/pdbs/nscdb1.xml', pdb_name=>'nscdb1');
   if compatible then
     DBMS_OUTPUT.PUT_LINE('The Pluggable database is Compatible !!!');
   else 
     DBMS_OUTPUT.PUT_LINE('ERROR - The Pluggable database is not compatible !!!');
   end if;
END;
/

Note: In case of issues:

col cause for a10
col name for a10
col message for a35 word_wrapped
select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='nscdb1';


4.) Connect into the CDB Database, if not connected: cdbst

. oraenv
cdbst

sqlplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

         
5.) Create the new PDB:

CREATE PLUGGABLE DATABASE nscdb1 USING '/home/oracle/pdbs/nscdb1.xml'  NOCOPY TEMPFILE REUSE;         

Pluggable database created.

select con_id, name, open_mode from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         2 PDB$SEED                       READ ONLY
         3 NSCDB1                         MOUNTED

6.) Catalog

alter session set container=NSCDB1;    

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         MOUNTED

@?/rdbms/admin/noncdb_to_pdb.sql         

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         MOUNTED

SQL> alter database open;

Database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO
         
  1* SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES
SQL> /

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
USERS                          +DATA/NSCDB1/DATAFILE/users.502.942942475
SYSAUX                         +DATA/NSCDB1/DATAFILE/sysaux.586.942942461
SYSTEM                         +DATA/NSCDB1/DATAFILE/system.325.942942455

7.) Droping the OLD UNDO

as grid user:

[grid@odasys12:/home/grid]asmcmd lsof | grep -i NSCDB1
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/sysaux.586.942942461
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/system.325.942942455
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/users.502.942942475

--> If is not in use you can remove the file

[grid@odasys12:/home/grid]asmcmd
ASMCMD> cd +DATA/NSCDB1/DATAFILE/

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 02 18:00:00  Y    UNDOTBS1.587.942942465
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSAUX.586.942942461
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSTEM.325.942942455
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    USERS.502.942942475

ASMCMD> rm UNDOTBS1.587.942942465
ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSAUX.586.942942461
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSTEM.325.942942455
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    USERS.502.942942475

8.) Remove the Service from the Cluster

. oraenv

nscdb1

[oracle@odasys12:/home/oracle/pdbs]srvctl remove database -d nscdb1
Remove the database nscdb1? (y/[n]) y

9) Checking the service inside of the CDB

. oraenv

cdbst

sqlplus / as sysdba

col NETWORK_NAME format a20
col NAME format a20
select name, NETWORK_NAME, PDB from v$services;

NAME                           NETWORK_NAME         PDB
------------------------------ -------------------- ------------------------------
nscdb1                         nscdb1               NSCDB1
cdbstXDB                       cdbstXDB             CDB$ROOT
cdbst                          cdbst                CDB$ROOT
SYS$BACKGROUND                                      CDB$ROOT
SYS$USERS                                           CDB$ROOT

[grid@odasys12:/home/grid]lsnrctl status listener | grep nscdb1
Service "nscdb1" has 1 instance(s).

10.) Check ODA repository :

oakcli show databases | grep -i nscdb1

cat /etc/oratab | grep -i nscdb1

11.) Cleaning Files:

cd /u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
ls -ltr | grep -i nscdb1

-rw-r----- 1 oracle oinstall     7680 May  2 16:38 orapwnscdb1
-rw-r----- 1 oracle oinstall       39 May  2 16:40 initnscdb1.ora
-rw-rw---- 1 oracle asmadmin     1544 May  2 18:40 hc_nscdb1.dat

rm orapwnscdb1 initnscdb1.ora hc_nscdb1.dat

12.) TNS

NSCDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys12.bgl.lu)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = nscdb1)
    )
  )

  
13.) Connection Test
sqlplus / as sysdba
  
INSTANCE_NAME
----------------
cdbst

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NSCDB1                         READ WRITE NO


alter pluggable database all save state;

SQL>  alter session set container=NSCDB1;

Session altered.

SQL>

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO
SQL> create user conntest identified by x;

User created.

SQL> grant connect to conntest;

Grant succeeded.

exit;

[oracle@odasys12:/u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin]sqlplus conntest/x@NSCDB1

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 09:29:10 2017

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, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

exit

[oracle@odasys12:/u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin]sqlplus sys/welcome1@NSCDB1 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 09:30:15 2017

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, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options


INSTANCE_NAME
----------------
cdbst

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s