Overview

Multitenancy is a new concept in Oracle 12c. The basis of it is that, you can separate the application data from the system data. Up to and including 11g, all the data in the database was residing in the same dimension as the system data or any other data for that matter. Data related to different application, were in the same tablespaces or even managed by the same user. Well, from 12c, all this can go under the table, now you can have many databases PDBs (pluggable databases), inside one big database, the root container. There are even more possibilities like application containers and so on, but we will see that later.

With the multi-tenancy, we have a:

root container - Where the system data resides. Also you can choose if you want the UNDO tablespace in the root to be used for all PDBs, or each PDB to have its own undo, SYSTEM and SYSAUX tablespace, making it completely independent from the root container.

Application Container - Container which consist of 1 or many PDBs which host a specific application. We are able to assign versions and name to such container, furthermore we can initiate installation and upgrade modes.

Creation

Firstly, we need to create our container. From 12c, we can create a database to be either as it always has been, a normal database, OR we can create it to allow other databases as well. So it will be a container, let's see how we can do both:

Create Normal DB

Actually, the creation of a normal database isn't that hard, you can just type:

Create simple database

Simply that, will create us a normal database, well after that you will have to run the catproc and the catalog scripts, but you get the gist.

Create container DB

To create a container, database we NEED to allow it to have PLUGGABLE databases, as follows:

Create CDB

That will create us a container database called CDB1 and a SEED, after that you will have to run script:

@$ORACLE_HOME/rdbms/admin/catcdb.sql

But other than that, all will be ok. So we have a container, big deal, what then. Well, now we can create PLUGGABLE databases as follows:

Create Pluggable DB (PDB)

As I said before, pluggable databases, are totally separate databases from one another. Imagine it having many databases (PDBs) within one big database (CDB). These PDBs, can have separate user totally individual from each other. So let's see how it is done:

Create PDB

You can use either:

FILE_NAME_CONVERT, or

CREATE_FILE_DEST, or

PDB_FILE_NAME_CONVERT

Either in the session level or on the CREATE statement, up to you, the result will be the same.

Once created, you can list all PDBs in a certain CDB as follows:

List PDBs

Remember, 1 PDB can be in only 1 ROOT$CDB, but 1 CDB can have many PDBs. Furthermore, from 12.2, we have also applicational containers, which are containers within the CDB, but we will speak about them in a second.

Management

We can perform several actions with a PDB:

OPEN

Plug & Unplig

Close

Restore / Recover

Open

After we create a CDB, we need to open it, as follows:

Open PDB

That command, will open us a database and it will become available to the users. We can also close a pluggable database as follows:

Close PDB

Unplug a PDB

In 12.1 we could unplug a PDB into .xml file and the migration of the PDB, would be the migration of that XML file AND the relevant database files. From 12.2 we can also unplug the PDB into a .pdb archive file, which contains information about the PDB AND the relevant database files. That will ease our migration.

Unplug to .pdb file

That assumes, you are using OMF file. The resulting file contains all the necessary data:

List .pdb file

Plug a PDB

To plug a database, we need the file from above and we need to verify the compatibility as follows:

Plug a PDB

Create a PDB using the source file

Then we can create a PDB using the .pdb file as follows:

Plug-in PDB

Clone a PDB

We can clone a PDB as follows:

Cloning a PDB

Clone a remote PDB (12.1)

For that feature, you need to be at least: 12.1.0.2, there is a big with 12.1.0.1. Furthermore, there are two varieties of that procedure.

Clone from PDB within other CDB

Clone a non-CDB

For both, there are the following pre-requisites:

Pre-requisites

The user in the local database must have the CREATE PLUGGABLE DATABASE privilege in the root container.

The remote database (PDB or non-CDB) must be open in read-only mode.

The local database must have a database link to the remote database. If the remote database is a PDB, the database link can point to the remote CDB using a common user, or the PDB using a local or common user.

The user in the remote database that the database link connects to must have the CREATE PLUGGABLE DATABASE privilege.

The local and remote databases must have the same endianness, options installed and character sets.

If the remote database uses Transparent Data Encryption (TDE) the local CDB must be configured appropriately before attempting the clone. If not you will be left with a new PDB that will only open in restricted mode.

The default tablespaces for each common user in the remote PDB *must* exist in local CDB. If this is not true, create the missing tablespaces in the root container of the local PDB. If you don't do this your new PDB will only be able to open in restricted mode (Bug 19174942).

When cloning from a non-CDB, both the the local and remote databases must using version 12.1.0.2 or higher.

Clone from a PDB in another CDB

As explained, we need to create a user and open the remote PDB in read only, and create Link in the local one:

On remote

Create a user on remote

Then we can move to the local machine and create the link:

On local

Create link

Clone a non-CDB

Non-CDB in this case, refers to normal database, pre 12c So let's see how it will be done. As before we need to create a user and bring the whole database in read only mode:

On remote

<code:bash|Create user and enable read-only> export ORAENV_ASK=NO export ORACLE_SID=db12c . oraenv export ORAENV_ASK=YES

sqlplus / as sysdba

CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user; GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user;

SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE OPEN READ ONLY; EXIT; </Code>

Then on the local we have to do the same as before:

On local

Create DB Link

Then we can create the PDBs as follows:

Create the PDB

REMEMBER, as the cloned DB wasn't a PDB, we need to run the noncdb_to_pdb.sql.

Hot clone

There is however one BIG flow in that procedure. The problem is that we need the database (non-cdb) or even PDB to be in read-only mode. That pretty much kills all the desire to perform the procedure as the downtime would be too much for production. Because of that from 12.2 we can do a hot clone, which eliminates that prerequisites :)

So let's see how it is done:

Prerequisites

Prerequisites

On remote

On the remote machine, we have to however assure couple stuff:

Create user and verify archivelog

On local

Now, we can create a DB link on the local machine and then we can create the PDB itself :)

Create DB Link