Oracledna

Migrate Non-CDB RAC Database to PDB manually

To manually migrate a Non-CDB RAC database to a PDB in Oracle 19c, we must first create a CDB, then plug in the Non-CDB as a PDB using the DBMS_PDB.DESCRIBE and CREATE PLUGGABLE DATABASE commands, followed by running noncdb_to_pdb.sql inside the new PDB.

Note: This procedure is irreversible, make sure to have valid backup of NON CDB database.

1. Shutdown the source non-cdb database and start in Read-Only mode.

 

oracle@racnode1 ~]$ srvctl stop database -db racdb


[oracle@racnode1 ~]$ srvctl status database -db racdb -v
Instance racdb1 is not running on node racnode1
Instance racdb2 is not running on node racnode2

 

[oracle@racnode1 ~]$ srvctl start database -db racdb -o “READ ONLY”


[oracle@racnode1 ~]$ srvctl status database -db racdb -v
Instance racdb1 is running on node racnode1. Instance status: Open,Readonly.
Instance racdb2 is running on node racnode2. Instance status: Open,Readonly.

2. In non-CDB source database, generate manifest file by executing the “DBMS_PDB.DESCRIBE” package.

The “DBMS_PDB.DESCRIBE” package will generate the xml file.

SQL> exec dbms_pdb.describe(‘/tmp/CDB19.xml’);
PL/SQL procedure successfully completed.


[oracle@racnode1 ~]$ cd /tmp/
[oracle@racnode1 tmp]$ ls -lrt *.xml
-rw-r–r–. 1 oracle asmadmin 7957 May 29 12:01 CDB19.xml

 

Shutdown the source non-CDB database.
[oracle@racnode1 ~]$ srvctl stop database -db racdb

[oracle@racnode1 ~]$ srvctl status database -db racdb -v
Instance racdb1 is not running on node racnode1
Instance racdb2 is not running on node racnode2

3. Check the compatibility in CDB to plug in the source non CDB as PDB.
 
Connecto to the CDB database
 
export ORACLE_SID=prodcdb1
sqlplus / as sysdba
 
set serveroutput on
BEGIN
IF dbms_pdb.check_plug_compatibility(‘/tmp/CDB19.xml’) THEN
dbms_output.put_line(‘PDB compatible? ==> YES’);
ELSE
dbms_output.put_line(‘PDB compatible? ==> NO’);
END IF;
END;
/
 
 
SQL> set serveroutput on
BEGIN
        IF dbms_pdb.check_plug_compatibility(‘/tmp/CDB19.xml’) THEN
                dbms_output.put_line(‘PDB compatible? ==> YES’);
        ELSE
                dbms_output.put_line(‘PDB compatible? ==> NO’);
        END IF;
END;
/SQL>  
PDB compatible? ==> YES
 
PL/SQL procedure successfully completed.
 
 
So, source database is compatible to convert as pdb.
 
 
 
SQL> select name, cause, type, message from pdb_plug_in_violations where name=’PROD’ and status <>’RESOLVED’;
no rows selected

4. Plug the Non-CDB into the CDB as a PDB


sqlplus / as sysdba

SQL> show con_name
CON_NAME
——————————
CDB$ROOT


SQL> show pdbs

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

 

SQL> CREATE PLUGGABLE DATABASE PRODPDB1 USING ‘/tmp/CDB19.xml’ NOCOPY TEMPFILE REUSE;
Pluggable database created.


SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PRODPDB1 MOUNTED

5. Connect to the PDB and run the noncdb_to_pdb.sql in new pdb.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PRODPDB1 MOUNTED


SQL> alter pluggable database PRODPDB1 open;
Warning: PDB altered with errors.

 

SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PRODPDB1 READ WRITE YES


SQL> alter session set container=PRODPDB1;
Session altered.

 

SQL> show con_name
CON_NAME
——————————
PRODPDB1

 

SQL> @?/rdbms/admin/noncdb_to_pdb.sql
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL> SET VERIFY OFF
SQL>
SQL> WHENEVER SQLERROR EXIT;
SQL>
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC> The following statement will cause an “ORA-01403: no data found”
DOC> error if we’re not in a PDB.
DOC> This script is intended to be run right after plugin of a PDB,
DOC> while inside the PDB.
.
.
.
.
.
.
.

SQL> alter session set container = “&pdbname”;

Session altered.

SQL>
SQL> alter session set “_enable_view_pdb”=false;

Session altered.

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;

6. Restart the PDB and check the plug in violations.


SQL> alter pluggable database PRODPDB1 close;
Pluggable database altered.


SQL> alter pluggable database PRODPDB1 open;
Pluggable database altered.


SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PRODPDB1 READ WRITE NO


SQL> alter session set container=PRODPDB1;
Session altered.


SQL> select name ,open_mode from v$pdbs;
NAME OPEN_MODE
———- ———-
PRODPDB1 READ WRITE

 

SQL> select name, cause, type, message from pdb_plug_in_violations where name=’PROD’ and status <>’RESOLVED’;
no rows selected

Disclaimer:

Please note the above information is only for educational purpose and practised in personal test database only. Always test in test database before implementing in production database. The pre-requisites and ways of implementing may vary from one environment to another. Hence, not providing guarantee that it will work in your environment.