12C non CDB to CDB

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Step 1

Shut down the source non-CDB and start it in read-only mode:

SQL> select cdb from v$database;

CDB
---
NO

SQL> shutdown immediate


Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup open read only


ORACLE instance started.
Total System Global Area 4865392640 bytes
Fixed Size 8630568 bytes
Variable Size 1006636760 bytes
Database Buffers 3841982464 bytes
Redo Buffers 8142848 bytes
Database mounted.
Database opened.
Create the XML file that describes the non-CDB:

SQL> SET SERVEROUTPUT ON;


SQL> exec DBMS_PDB.DESCRIBE(pdb_descr_file => '/home/oracle/db12201.xml');

PL/SQL procedure successfully completed.

Step 2

On the source non-CDB, check the datafiles location and shut down the non-CDB database:

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ORCL/system01.dbf
/u01/app/oracle/oradata/ORCL/sysaux01.dbf
/u01/app/oracle/oradata/ORCL/undotbs01.dbf
/u01/app/oracle/oradata/ORCL/users01.dbf

SQL> shutdown immediate


Database closed.
Database dismounted.
ORACLE instance shut down.
Copy the XML file along with the datafiles to the target host:

 SCP the files to target

Change as per target files

vi db12201.xml
-- look for "<path>" and edit
<path>/u01/app/oracle/oradata/ORCL/users01.dbf</path>
-- to
<path>/<target/users01.dbf</path>
-- repeat for all datafiles

Step 3
On the target CDB, check the compatibility of the non-CDB to be plugged in as PDB:

SQL> SET SERVEROUTPUT ON;


SQL> DECLARE
compatible CONSTANT VARCHAR2(3) := CASE
DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/home/oracle/db12201.xml',
pdb_name => 'NEWPDB')
WHEN TRUE THEN 'YES' ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/

NO
PL/SQL procedure successfully completed.

 Connect to the target CDB and create a new PDB using the XML file describing the
non-CDB database.

SQL> create pluggable database TRGTCDB using '/home/oracle/db12201.xml' copy;


-- if you are not using OMF, add:
-- file_name_convert = ('/u01/app/oracle/oradata/ORCL/', '+DATA/CDB_FRA/TRGTCDB/');

Pluggable database created.

SQL> alter session set container=TRGTCDB;

Session altered.
SQL> select name from v$datafile;

NAME
----------------------------------------------------------------------------------------------------
+DATA/CDB_FRA/D8ABE7903A33E0533700000A9D8ABE790D11A214/DATAFILE/
system.280.9331710682
+DATA/CDB_FRA/D8ABE7903A33E0533700000A9D8ABE790D11A214/DATAFILE/
sysaux.278.9331710682
+DATA/CDB_FRA/D8ABE7903A33E0533700000A9D8ABE790D11A214/DATAFILE/
undotbs1.279.9331710682
+DATA/CDB_FRA/D8ABE7903A33E0533700000A9D8ABE790D11A214/DATAFILE/
users.277.9331710682

Step 4
In case your target CDB is at a higher release level (e.g. source is 18c and target is 19c), then
now it’s the time to upgrade the newly created PDB. Use AutoUpgrade or execute the
following commands:

SQL> alter Pluggable database TRGTCDB open upgrade;


$ORACLE_HOME/bin/dbupgrade -c "TRGTCDB" -l /tmp

Step 5

 The plugged in non-CDB (the new PDB) still contains some objects in the data
dictionary that does not belong to a PDB and hence need to be removed. This is
done by executing the noncdb_to_pdb.sql script from within the PDB:

The script also automatically runs the utl_recomp.recomp_parallel procedure, which could
take a while to complete.

SQL> alter session set container=TRGTCDB;

Session altered.

SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
4 TRGTCDB MOUNTED

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
Step 6

SQL> alter pluggable database TRGTCDB open;

Warning: PDB altered with errors.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
4 TRGTCDB READ WRITE YES

SQL> set lines 300


SQL> col type for a15
SQL> col cause for a30
SQL> col message for a170
SQL> select type, cause, message
from PDB_PLUG_IN_VIOLATIONS
where name='TRGTCDB' and status != 'RESOLVED';

TYPE CAUSE MESSAGE


--------------- ------------------------------
--------------------------------------------------------------------------------------------------------------------------
------------------------------------------------
ERROR SQL Patch SQL patch ID/UID 31668898/23868204 (OJVM RELEASE
UPDATE 12.2.0.1.201020): Installed in the PDB but not in the CDB.
ERROR SQL Patch SQL patch ID/UID 31465389/23823236 (RMAN RECOVER
FAILS FOR PDB$SEED DATAFILES RMAN-06163 RMAN-06166): Installed in the CDB but not in
the PDB.
ERROR SQL Patch SQL patch ID/UID 31668898/23868204 (OJVM RELEASE
UPDATE 12.2.0.1.201020): Installed in the CDB but not in the PDB.
ERROR SQL Patch SQL patch ID/UID 31772700/23767883 (MERGE
REQUEST ON TOP OF DATABASE OCT 2020 RU 12.2.0.1.201020 FOR BUGS 31359592):
Installed in the CDB but not in the PDB.
WARNING is encrypted tablespace? Tablespace SYSTEM is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
WARNING is encrypted tablespace? Tablespace SYSAUX is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
WARNING is encrypted tablespace? Tablespace USERS is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
Ok, we have 4 errors regarding missing patches and 3 warnings regarding non-encrypted
tablespaces.

The patching related errors indicates having patches in the CDB, but not in the PDB, so we
need to run datapatch for the PDB. This would also be the case when the CDB is at a higher
patch level than the original non-CDB.
$ORACLE_HOME/OPatch/datapatch -verbose -pdbs TRGTCDB

...
Patch 31772700 apply (pdb TRGTCDB): SUCCESS
logfile:

SQL Patching tool complete on Sat Jul27 2:40:50 2021

-- check
SQL> alter pluggable database TRGTCDB close immediate;

Pluggable database altered.

SQL> alter pluggable database TRGTCDB open;

Pluggable database altered.

SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
4 TRGTCDB READ WRITE NO

SQL> select type, cause, message


from PDB_PLUG_IN_VIOLATIONS
where name='TRGTCDB' and status != 'RESOLVED';

TYPE CAUSE MESSAGE


--------------- ------------------------------
--------------------------------------------------------------------------------------------------------------------------
------------------------------------------------
WARNING is encrypted tablespace? Tablespace SYSTEM is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
WARNING is encrypted tablespace? Tablespace SYSAUX is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
WARNING is encrypted tablespace? Tablespace USERS is not encrypted. Oracle
Cloud mandates all tablespaces should be encrypted.
No errors regarding patches anymore.

Step 7
 Encrypt the USERS tablespace. Encrypting the SYSTEM and SYSAUX tablespaces is
usually not needed as they should not contain any application data. But let’s do it
anyway to demonstrate getting rid of the above warnings:

SQL> administer key management set key force keystore identified by


<TDE_Wallet_Password> with backup;
keystore altered.

SQL> alter tablespace USERS encryption online encrypt;

Tablespace altered.

SQL> alter tablespace SYSTEM encryption online encrypt;

Tablespace altered.

SQL> alter tablespace SYSAUX encryption online encrypt;

Tablespace altered.
Last check:

SQL> alter pluggable database TRGTCDB close immediate;

Pluggable database altered.

SQL> alter pluggable database TRGTCDB open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
4 TRGTCDB READ WRITE NO

SQL> select type, cause, message


from PDB_PLUG_IN_VIOLATIONS
where name='TRGTCDB' and status != 'RESOLVED';

no rows selected

Done !!

You might also like