How to clone Pluggable Database from one container to different Container Database

How to clone Pluggable Database from one container to different Container Database


Cloning and Refresh are day-to-day activity which DBA perform on regular basic. In today blog , We will discuss about Cloning of the pluggable database from one container database to different container database.

Oracle offers to unplug a PDB from one CDB and then plug into a different CDB. This will be another additional feature of PDB to give the highest availability and scalability the database systems may need in a cloud infrastructure environment. 

1)We have two container database cseeddb(Source Container DB) and ctestdb1 (target container DB).
NOTE: We have created container DB ctestdb1 and it does not have any PDB(Pluggable DB).


2)Verify you are in the correct container database root namespace(CDB).
NOTE: We are on first container (cseeddb) database where we have clonedb pluggable database which we will move in to another empty container ctestdb1.
SQL> set echo on
SQL> SET LINESIZE 200
SQL> SET PAGESIZE 10000
SQL> SET SERVEROUTPUT ON
SQL> COLUMN "DB DETAILS" FORMAT A100
SQL> SELECT 'DB_NAME: '||sys_context('userenv','db_name')||'/ CDB?:'||(select cdb from v$database)||'/ AUTH_ID:'
||sys_context('userenv','authenticated_identity')||'/ USER: '||sys_context('userenv','current_user')
||'/ CONTAINER:'||nvl(sys_Context('userenv','con_Name'),'NON-CDB') "DB DETAILS" FROM DUAL;

DB DETAILS
----------------------------------------------------------------------------------------------------
DB_NAME: cseeddb/ CDB?:YES/ AUTH_ID:oraware/ USER: SYS/ CONTAINER:CDB$ROOT

SQL> SET SERVEROUTPUT ON
SQL>COLUMN "RESTRICTED" FORMAT A10
SQL>select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d using (GUID) order by v.create_scn;

NAME                           OPEN_MODE  RESTRICTED STATUS
------------------------------ ---------- ---------- -------------
PDB$SEED                       READ ONLY  NO         NORMAL
PSEEDDB                        READ WRITE NO         NORMAL
CLONEDB                        READ WRITE NO         NORMAL

3) On cseeddb Container database , Close, unplug and drop CLONEDB Pluggable DB with keep datafile..

SQL> alter pluggable database CLONEDB close;
Pluggable database altered.

SQL> alter pluggable database CLONEDB unplug into '/orabackup/CLONEDB.xml';
Pluggable database altered.

SQL> SET SERVEROUTPUT ON
SQL> COLUMN "RESTRICTED" FORMAT A10
SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d using (GUID) order by v.create_scn;

NAME                           OPEN_MODE  RESTRICTED STATUS
------------------------------ ---------- ---------- -------------
PDB$SEED                       READ ONLY  NO         NORMAL
PSEEDDB                        READ WRITE NO         NORMAL
CLONEDB                        MOUNTED    n/a        UNPLUGGED

SQL> drop pluggable database CLONEDB keep datafiles;
Pluggable database dropped.


SQL> SET SERVEROUTPUT ON
SQL> COLUMN "RESTRICTED" FORMAT A10
SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d using (GUID) order by v.create_scn;




4) Verify you are on correct container database.



SQL> set echo on
SQL> SET LINESIZE 200
SET PAGESIZE 10000
SQL> SQL> SET SERVEROUTPUT ON
SQL> COLUMN "DB DETAILS" FORMAT A100
SQL> SELECT 'DB_NAME: '||sys_context('userenv','db_name')||'/ CDB?:'||(select cdb from v$database)||'/ AUTH_ID:'
  ||sys_context('userenv','authenticated_identity')||'/ USER: '||sys_context('userenv','current_user')
  ||'/ CONTAINER:'||nvl(sys_Context('userenv','con_Name'),'NON-CDB') "DB DETAILS" FROM DUAL;

DB DETAILS
----------------------------------------------------------------------------------------------------
DB_NAME: ctestdb1/ CDB?:YES/ AUTH_ID:oraware/ USER: SYS/ CONTAINER:CDB$ROOT
SQL> SET SERVEROUTPUT ON
COLUMN "RESTRICTED" FORMAT A10
select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d using (GUID) order by v.create_scn;

NAME                           OPEN_MODE  RESTRICTED STATUS
------------------------------ ---------- ---------- -------------
PDB$SEED                       READ ONLY  NO         NORMAL





5) Check Compatibility for plugging database.

SQL> SET SERVEROUTPUT ON
DECLARE
compatible CONSTANT VARCHAR2(3) :=
CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/orabackup/CLONEDB.xml',
pdb_name => 'CLONEDB')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/
NO

NOTE: If the scripts returns NO, then check PDB_PLUG_IN_VIOLATIONS view


Compare both container compatibility using below command :

SQL> col cause for a10
col name for a10
col message for a35 word_wrapped
select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='CLONEDB';

NAME       CAUSE      TYPE      MESSAGE                             STATUS
---------- ---------- --------- ----------------------------------- ---------
CLONEDB    Parameter  WARNING   CDB parameter processes mismatch:   PENDING
                                Previous 300 Current 100
CLONEDB    Parameter  WARNING   CDB parameter memory_target         PENDING
                                mismatch: Previous 2147483648
                                Current 1073741824

Do not proceed unless you resolve all the issue of the reported by above query.

6) Plug Pluggable database .

SQL> create pluggable database CLONEDB using '/orabackup/CLONEDB.xml' move file_name_convert = ('/cseeddb/', '/ctestdb1/');

Pluggable database created.

SQL> alter pluggable database CLONEDB open;
Pluggable database altered.

SQL> set echo on
SQL> SET LINESIZE 200
SQL> SET PAGESIZE 10000
SQL> SET SERVEROUTPUT ON
SQL> COLUMN "DB DETAILS" FORMAT A100
SQL> SELECT 'DB_NAME: '||sys_context('userenv','db_name')||'/ CDB?:'||(select cdb from v$database)||'/ AUTH_ID:'
  2  ||sys_context('userenv','authenticated_identity')||'/ USER: '||sys_context('userenv','current_user')
  3  ||'/ CONTAINER:'||nvl(sys_Context('userenv','con_Name'),'NON-CDB') "DB DETAILS" FROM DUAL;

DB DETAILS
----------------------------------------------------------------------------------------------------
DB_NAME: ctestdb1/ CDB?:YES/ AUTH_ID:oraware/ USER: SYS/ CONTAINER:CDB$ROOT

SQL> COLUMN "PDB NAME" FORMAT A20
SQL> select PDB_NAME,GUID from DBA_PDBS;

PDB_NAME       GUID
-------------- --------------------------------
CLONEDB        F2FBCA4CE6AE7C40E04400144FF91E85
PDB$SEED       F325C852F0680BABE04400144FF91E85


7)Verify Container and Pluggable DB in target Container database.

SQL> SET SERVEROUTPUT ON
SQL> COLUMN "RESTRICTED" FORMAT A10
SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status
from v$PDBs v inner join dba_pdbs d using (GUID) order by v.create_scn;

NAME       OPEN_MODE  RESTRICTED STATUS
---------- ---------- ---------- -------------
PDB$SEED   READ ONLY  NO         NORMAL
CLONEDB    READ WRITE NO         NORMAL

SQL> SQL> set echo on
SQL> SET LINESIZE 200
SQL> SET PAGESIZE 10000
SQL> SET SERVEROUTPUT ON
SQL> COLUMN "DB DETAILS" FORMAT A100
SQL> SELECT 'DB_NAME: '||sys_context('userenv','db_name')||'/ CDB?:'||(select cdb from v$database)||'/ AUTH_ID:'
||sys_context('userenv','authenticated_identity')||'/ USER: '||sys_context('userenv','current_user')
||'/ CONTAINER:'||nvl(sys_Context('userenv','con_Name'),'NON-CDB') "DB DETAILS" FROM DUAL;

DB DETAILS
----------------------------------------------------------------------------------------------------
DB_NAME: ctestdb1/ CDB?:YES/ AUTH_ID:oraware/ USER: SYS/ CONTAINER:CDB$ROOT

SQL> select name, cdb from v$database;

NAME       CDB
---------- ---
CTESTDB1   YES

Please read below books in order to know more about oracle CDB and PDB databases:
================================================================
You can also , Visit our Blogs for related topic on Pluggable and Container database:




Comments

Popular posts from this blog

Restore MySQL Database from mysqlbackup

Oracle 19c New Features

Install & Configure MySQL Router - MySQL InnoDB Cluster