blog Oracle blog in Spanish

Convert a cdb database cdb pdb

In this post explain how to convert a non-CDB database into a PDB database PDB an existing container using the "Plugging aCDB a CDB" method .

Partimos de la siguiente siguación:

En uma máquina tenemos una base de datos «test» noncdb que vamos a migrar a una PDB en una base de datos multitenat (CDBORCL) instalada en la misma máquina y en la misma versión.

Máquina: oracle19cdb1
Origen: Oracle 19c (19.3.0.0.0) -> Non-CDB (test)
Destino: Oracle 19c (2(19.3.0.0.0) ) -> CDB (CDBORCL) ->

1- Prerequisites and Prior Validations

Before we begin, we check to make sure the database settings are compatible.
We verify that the source and destination character sets are compatible.

Base de datos: test

SQL > SELECT * FROM v$nls_parameters WHERE parameter IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');

PARAMETER VALUE
—————————————————————- ————————-
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16

Base de datos contenedora: CDBORCL




SQL > SELECT * FROM v$nls_parameters WHERE parameter IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');

PARAMETER VALUE
—————————————————————- ————————-
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16

We verify that there are no components or options that are not supported by the PDB databases.




SQL > select comp_id, version,status from dba_registry:

COMP_ID VERSION STATUS
—————————— —————————— ——————————————–
CATALOG 19.0.0.0.0 VALID
CATPROC 19.0.0.0.0 VALID
RAC 19.0.0.0.0 OPTION OFF
JAVAVM 19.0.0.0.0 VALID
XML 19.0.0.0.0 VALID
CATJAVA 19.0.0.0.0 VALID
APS 19.0.0.0.0 VALID
XDB 19.0.0.0.0 VALID
OWM 19.0.0.0.0 VALID
CONTEXT 19.0.0.0.0 VALID
ORDIM 19.0.0.0.0 VALID
SDO 19.0.0.0.0 VALID
XOQ 19.0.0.0.0 VALID
OLS 19.0.0.0.0 VALID
DV 19.0.0.0.0 VALID

2 – Set theCDB databaseCDB read-only mode

Es recomendable dejar la base de datos en modo read-only, para evitar cambios mientras generasmos el XML.

SHUTDOWN IMMEDIATE;

STARTUP OPEN READ-ONLY;

3 – Generar archivo XML descriptivo (non CDB)

Generamos el fichero xml, que guardará la descripción de la base de datos non-cdb que serán utilizados para importar en la base de datos CDB.

BEGIN
DBMS_PDB.DESCRIBE(
pdb_descr_file => ‘/tmp/oracleconraultest.xml’);
END;

/

4 – Check compatibility ( CDB database)

Antes de añadir la base de datos al contenedor CDB (CDBORCL), es necesario saber si es compatible. Para ello ejecutamos.

SET SERVEROUTPUT ON

DECLARE

compatible VARCHAR2(3);

BEGIN

compatible :=

CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(

pdb_descr_file => ‘tmp/oracleconraultest.xml‘)

WHEN TRUE THEN 'YES'

ELSE 'NO'

END;

DBMS_OUTPUT.PUT_LINE(compatible);

END;

/

Before moving on to the next step, we take the CDB database offline.

IMMEDIATE SHUTDOWN;

5. Create the PDB

There are two ways to create the PDB.

One option would be to reuse the current datafiles without making a copy of the database (NOCOPY option). Another option is to use the COPY option, which creates a backup of the database's datafiles.

Since we're on the same machine, we'll use NOCOPY, which will obviously make the process faster, since it doesn't have to make a copy of the data files.
If you choose this option, it's highly recommended that you perform a backup before running the process.

CREATE PLUGGABLE DATABASE test
USING ‘tmp/oracleconraultest.xml
NOCOPY
TEMPFILE REUSE;

If you want to copy the datafiles to a new ASM location

SCREATE PLUGGABLE DATABASE test
USING ‘/tmp/noncdb.xml’
COPY
FILE_NAME_CONVERT =
(
‘+DATA/NONCDB/’,
‘+DATA/CDB19/TEST/’
);

On the same ASM machine, NOCOPY is ASM used, minimizing space and time.

CREATE PLUGGABLE DATABASE test
USING ‘tmp/oracleconraultest.xml
NOCOPY
TEMPFILE REUSE;

6. Open the database in restricted mode.

We open the database in restricted mode in the CDB.

ALTER PLUGGABLE DATABASE TEST OPEN RESTRICTED;

We checked the errors and saw that the script still needs to be run.

SELECT name, cause, type, message, status
FROM pdb_plug_in_violations
WHERE name = ‘TEST’
ORDER BY time;

7. Running the CDB conversion script

Cambiamos la sesión a la pdb que vamos a convertir «test».

ALTER SESSION SET CONTAINER=TEST;

And we run the conversion:

@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

Once it's finished, we can see that the conversion was successful.

Para evitar que en el próximo reinicio la base de datos TEST arranque en modo mounted, con la base de datos abierta ejecutamos.

ALTER PLUGGABLE DATABASE TEST SAVE STATE;

With that, we would have converted our CDB database CDB PDB.

Oracle ACE