Wednesday, April 28, 2021

Multitenant Part 2 : PDB Hot Clone

 Multitenant Part 2 : PDB Hot Clone

  • Introduction
  • Histroy about PDB clone
  • Step by Step to Perform Hot Clone
  • How Stuff Works?

Introduction
Developer and testing team always require fresh database to identify bug or issues.
This is just a graphical representation of what we are going to do now.
At PRODCdb container database we have ProPdb1, this we are going to clone at our DEVCdb container database as HOTPorPdb1

History about PDB clone
Very quickly there is some history about clone pdbs.
In 12cR1, pdb clone was introduced; this was a feature with some restrictions. And restriction is like you have to make your pdb in read only mode. Basically this is cold cloning, not a hot clone. Because our pdb in read only mode. 

Later part in 12cR2, new feature is introduce as Hot clone, you can do cloning when your database / pdb is in read/write mode.

And later in 19c, remote clone can be done via dbca too in silent mode.




Step by Step to perform Hot Clone
Here I would like to share step by step commands to perform Hot Clone

Let’s define what could be our database name for Production and Development and CDB/PDB name.
Throughout our scenario I will follow below names to be performed.

Source Database Server (Production)
CDB Name : PRODCDB
PDB Name : PROPDB1

Target Database Server (Development)
CDB Name : DEVDCDB
PDB Name : DEVPDB1

Prerequisites of Scenarios
You can follow same set of commands and replicate this in your environment.

These prerequisites are common for all our scenarios, like, Hot Clone, Refreshable PDB, PDB Relocation and Snapshot Carousel, other scenarios you can found in my blog or follow the link embedded above. 

Source Database Server

At source we need to configure database in archive log mode if not, it is mandatory to do it and local undo mode, so each pdb will have their own undo tablespace.

Database should be in Archive log mode and local undo mode.

Target Database Server

Step 1 : Add tns entry of source database and create database link to connect to source database.
Step 2 : There should be a common user in Source Database
Step 3 : Grant privileges to common user i.e. create session and create pluggable database to all.

Create a database link which will be later used for cloning
CREATE DATABASE LINK prod_link CONNECT TO c##clone_user IDENTIFIED BY  clone_user USING 'PROPDB1';

Once we are done with these prerequisites, only few commands need to run after that to complete the task.

I always say that, each task have five steps,  and three steps we already completed here so remaining two steps needs to complete it.


On Target Server
Hot Clone from ProdCdb to DevCdb, Now, there are only two steps remaining. 

Step 4 : to create pluggable database from target database using database link.

Create pluggable database from db link,
CREATE PLUGGABLE DATABASE PROPDBHTCLONE FROM PROPDB1@prod_link;

Step 5 : Now, just to open database using alter pluggable database open;

After creation, new PDB will be in MOUNTED state. Open it to change the state to READ WRITE.
ALTER PLUGGABLE DATABASE PROPDBHTCLONE OPEN;


How Stuff Works,
You may wonder how this stuff works, So here is some insight of hot clone. 
When we run create pluggable database command, We do parallel scan of data file and it will read each block and transfer from source database to target database.
 
Now you may have question like what about those on going transaction which are happening in target database which are still not part of datafile. 

The answer is, we ship redos and apply in target database, so all your current transactions will ship their.

But there may be some committed and some uncommitted transaction how to tackle that?
So answer is, undo segment is used for the same to rollback your uncommitted transactions.


I hope, this helps you to perform PDB Hot Clone in these simple five steps.



Thanks & Regards,
Chandan Tanwani
Oracle Performance Tuning Certified Expert

No comments: