By Mouhamadou Diaw

Dealing these last days to database migration with a customer, I write this blog to describe the main tasks

The context is to migrate databases to a new infrastructure. Below the configuration

Source : Linux Suse in a non-multitenant architecture

Target : Oracle Enterprise Linux 8 with multitenant

The database version is Oracle 19c

Installing Oracle Binaries on the OEL

The first step is to install the Oracle binaries. You can do it by many ways. I created a Gold Image from the source server.

The advantage is that I will have the exact patch level than the source environment.

The steps are described below

1-Create the Gold Image on the source

[oracle@sourceserver ~]$ echo $ORACLE_HOME
/u00/app/oracle/product/19.14/dbhome_1
[oracle@u027 ~]$ /u00/app/oracle/product/19.14/dbhome_1/runInstaller  -silent -createGoldImage -destinationLocation /u01/software/gold_image/rdbms19.14
Launching Oracle Database Setup Wizard...

Successfully Setup Software.
Gold Image location: /u01/software/gold_image/rdbms19.14/db_home_2023-02-06_09-03-15AM.zip

2-Copy the Image to the OEL target server and unzip it to the new Oracle_Home

[oracle@targetserver ~]$ unzip -d /u00/app/oracle/product/19.14/dbhome_1 /u01/software/gold_image/rdbms19.14/db_home_2023-02-06_09-03-15AM.zip

3-Launch the installation process on the target OEL server

The installation can be graphical or silent method. In my case I used the silent method with a response file

With Oracle Enterprise Linux 8, you will need to export the CV_ASSUME_DISTID  variable otherwise the install will fail

oracle@targetserver ~]$ export CV_ASSUME_DISTID=OEL7.8

[oracle@targetserver ~]$ /u00/app/oracle/product/19.14/dbhome_1/runInstaller -silent  -responseFile /u01/software/gold_image/db_1914.rsp
Launching Oracle Database Setup Wizard...

The response file for this session can be found at:
 /u00/app/oracle/product/19.14/dbhome_1/install/response/db_2023-02-06_10-00-42AM.rsp

You can find the log of this install session at:
 /tmp/InstallActions2023-02-06_10-00-42AM/installActions2023-02-06_10-00-42AM.log

As a root user, execute the following script(s):
        1. /u00/app/oraInventory/orainstRoot.sh
        2. /u00/app/oracle/product/19.14/dbhome_1/root.sh

Execute /u00/app/oraInventory/orainstRoot.sh on the following nodes:
[targetserver]
Execute /u00/app/oracle/product/19.14/dbhome_1/root.sh on the following nodes:
[targetserver]

Successfully Setup Software.
Moved the install session logs to:
 /u00/app/oraInventory/logs/InstallActions2023-02-06_10-00-42AM
[oracle@targetserver ~]$ 

Then run the 2 scripts as asked

[root@targetserver ~]# /u00/app/oraInventory/orainstRoot.sh
Changing permissions of /u00/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u00/app/oraInventory to oinstall.
The execution of the script is complete.
[root@targetserver ~]# /u00/app/oracle/product/19.14/dbhome_1/root.sh
Check /u00/app/oracle/product/19.14/dbhome_1/install/root_targetserver.sig-ge.ch_2023-02-06_10-02-03-988526328.log for the output of root script
[root@targetserver ~]#

4-Relink Oracle binaries (optional)

This step is optional but I recommend to do it when cloning your environment

[oracle@targetserver ~]$ export ORACLE_HOME=/u00/app/oracle/product/19.14/dbhome_1
[oracle@targetserver ~]$ cd $ORACLE_HOME/bin
[oracle@targetserver ~]$./relink as_installed

And that is all for the binaries. If you have different Oracle version, do the same

Migrating the Data to multitenant architecture

You have may options to do that, we can for example list following

-datapump

-unplug and plug data

-Creating the PDB via DB Link

I used the third method, i.e using database link

1-On the target server create an empty container

I used the silent method. You will have to create your responsefile accordingly.

oracle@u027:/home/oracle/ [rdbms1914] /u00/app/oracle/product/19.14/dbhome_1/bin/dbca -silent -createDatabase -responseFile /home/oracle/dbca_1914.rsp

2-On the target server create a database link to the source database

Let’s say my source database is PROD and the port used is 1521

On the CDB$ROOT with SYS or a user with required privilege

SQL> show pdbs

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

SQL> CREATE DATABASE LINK "MIGLINK" CONNECT TO "SYSTEM" IDENTIFIED BY secret USING 'sourceserver:1521/PROD';

Database link created

And now test the DB Link

SQL> show pdbs

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

SQL> select name from v$database@MIGLINK

3-On the source server, give following privilege to the user used in the DB Link (i.e SYSTEM)

SQL> grant create pluggable database to system;

Grant succeeded.

SQL>

4-On the target server create the PDB using the DB Link

This can be done while the non-cdb database PROD is opened in Read Write mode but it is recommended to open the database in Read Only mode

SQL> CREATE PLUGGABLE DATABASE PROD from non$cdb@MIGLINK;

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         5 PROD                           MOUNTED
SQL>

Of course you can change the PDB name .

5-On the target server run the noncdb_to_pdb.sql on the newly created PDB

Connect as SYS

SQL> alter session set container=PROD;

Session altered.

SQL> show con_name;

CON_NAME
------------------------------
PROD
SQL> @?/rdbms/admin/noncdb_to_pdb.sql
…
…
  8      END IF;
  9    END;
 10  END;
 11  /

PL/SQL procedure successfully completed.

SQL>
SQL> WHENEVER SQLERROR CONTINUE;
SQL>
SQL>
SQL>
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         5 PROD                          MOUNTED

There should not be any error. And then you can now open you PDB in a R/W mode

SQL> alter pluggable database PROD open;

Pluggable database altered.

SQL>

To automatically open the PDB the next time the instance is restarted.

SQL> show pdbs

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

SQL> alter pluggable database all save state;

Pluggable database altered.

SQL>

Conclusion

As you can see migrating a Non-CDB database to multitenant one is not very difficult. Read Oracle documentation and you will see many information about converting database to CDB architecture