How to Convert the NON-CDB database to CDB

How to Convert the NON-CDB database to CDB

In this article, I’m going to show you how to convert a NON-CDB database into cdb database. Convert non-container database to multitenant pluggable database with Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 – 64bit.

Run the following commands on both machines.

SQL> select * from v$version;
SQL>select dbid,name,cdb from v$database;

Output from Non-CDB database

Output from CDB database

SQL>select pdb_id,dbid,pdb_name,status from cdb_pdbs;

Output from CDB database

Run the following commands on the Non-CDB database step by step.

SQL>shut immediate
SQL>startup mount exclusive
SQL>alter database open read only;
SQL>exec dbms_pdb.describe (pdb_descr_file=>'/u01/aarav.xml');
SQL>shutdown immediate

Run the following commands on the CDB database step by step

SQL>startup
SQL>SET SERVEROUTPUT ON;

SQL>DECLARE
Compatible CONSTANT VARCHAR2(3) :=CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY
(pdb_descr_file => '/u01/aarav.xml')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/

After running the above code then check the Violations, if any.

SQL>select name, cause, type, message, status FROM PDB_PLUG_IN_VIOLATIONS WHERE name='AARAV';

Note:- In the above query it’s showing two warnings, these warnings can be safely ignored.

Create a pluggable database with any name using the following command.

SQL>CREATE PLUGGABLE DATABASE pdb12c USING '/u01/aarav.xml' COPY FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/aarav', '/u01/app/oracle/oradata/pdb12c');

Set your session with the newly created pluggable database using the following command.

SQL>alter session set container=pdb12c;

Now it’s finally time to migrate a non-CDB database to a CDB database, just run the following script.

SQL>@?/rdbms/admin/noncdb_to_pdb.sql

Note:- The above script takes a few minutes in execution, so don’t panic.

After completing the above script, now you can open the newly pluggable database, using the following command.

SQL>alter pluggable database open;

Now you can check your database name and open mode using the following command.

SQL>select name, open_mode FROM v$pdbs;

Conclusion

When you convert a non-CDB database to a CDB pluggable database, you can choose from several options depending upon the size of the database.

If the database is very large, you might use the NOCOPY option. This minimizes the amount of extra space needed and reduces the time it takes to perform the conversion operation. The NOCOPY option is risky, however, because you don’t keep the original database files intact. Thus, if you need to restore the database to the previous state, you must restore the database using the backups taken before the conversion activity.

If the database size is smaller, you should use the COPY option so that, if there are any issues, the fallback to the old non-CDB is straightforward because the original files are always intact.

Read - How to Change password without showing the actual password on screen?

Our Latest Posts:

Connect with me on:
Instagram: https://www.instagram.com/shripaldba
Linkedin: 
https://www.linkedin.com/in/shripal-singh
Twitter: 
https://twitter.com/ocptechnology
Facebook: 
https://www.facebook.com/ocptechnology
YouTube:
https://www.youtube.com/ocptechnology

9 thoughts on “How to Convert the NON-CDB database to CDB

  1. Hi Sir,

    After shut down on Non CDB DB ,
    I was trying to create PDB on the CDB DB as you said on the notes, then got an error which is missing data file,

    SQL> CREATE PLUGGABLE DATABASE pdb19c USING ‘/u01/aarav.xml’ COPY FILE_NAME_CONVERT = (‘/u01/app/oracle/oradata/aarav’, ‘/u01/app/oracle/oradata/pdb19c’);
    CREATE PLUGGABLE DATABASE pdb19c USING ‘/u01/aarav.xml’ COPY FILE_NAME_CONVERT = (‘/u01/app/oracle/oradata/aarav’, ‘/u01/app/oracle/oradata/pdb19c’)
    *
    ERROR at line 1:
    ORA-65005: missing or invalid file name pattern for file –
    /u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_k4rbsn75_.dbf

  2. SQL> CREATE PLUGGABLE DATABASE pdb12c USING ‘/u01/orcl.xml’ COPY FILE_NAME_CONVERT = (‘/u01/app/oracle/oradata/orcl’, ‘/u01/app/oracle/oradata/pdb12c’);
    CREATE PLUGGABLE DATABASE pdb12c USING ‘/u01/orcl.xml’ COPY FILE_NAME_CONVERT = (‘/u01/app/oracle/oradata/orcl’, ‘/u01/app/oracle/oradata/pdb12c’)
    *
    ERROR at line 1:
    ORA-65090: operation only allowed in a container database
    please tell me how can i convert to container database

  3. SQL> DECLARE
    Compatible CONSTANT VARCHAR2(3) :=CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY
    (pdb_descr_file => ‘/u01/orcl.xml’)
    WHEN TRUE THEN ‘YES’
    ELSE ‘NO’
    END;
    BEGIN
    DBMS_OUTPUT.PUT_LINE(compatible);
    END;
    / 2 3 4 5 6 7 8 9 10
    DECLARE
    *
    ERROR at line 1:
    ORA-65026: Plug XML error : LPX-00202: could not open “/u01/orcl.xml” (error
    200)
    ORA-06512: at “SYS.DBMS_PDB”, line 37
    ORA-06512: at line 2
    i am getting this error

  4. SQL> alter database open read only;

    Database altered.

    SQL> exec dbms_pdb.describe (pdb_descr_file=>’/u01/orcl.xml’);
    BEGIN dbms_pdb.describe (pdb_descr_file=>’/u01/orcl.xml’); END;

    *
    ERROR at line 1:
    ORA-65026: Plug XML error : LPX-00202: could not open “/u01/orcl.xml” (error 0)
    ORA-06512: at “SYS.DBMS_PDB”, line 30
    ORA-06512: at line 1

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top