How To Clone A Pluggable Database from a Existing PDB in 19C

How To Clone A Pluggable Database from a Existing PDB


Step 1. 

Put PDB in read only mode , which would be cloned.

SQL> show pdbs

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



SQL> alter session set container=ORCLPDB1;

Session altered.

SQL> SHOW PDBS

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ORCLPDB1                       READ WRITE NO
 
SQL>select file_name,tablespace_name from dba_data_Files

FILE_NAME                                                              TABLESPACE_NAME
---------------------------------------------------------------------- ------------------------------
/u01/app/oracle/oradata/ORCLCDB/orclpdb1/undotbs01.dbf                 UNDOTBS1
/u01/app/oracle/oradata/ORCLCDB/orclpdb1/sysaux01.dbf                  SYSAUX
/u01/app/oracle/oradata/ORCLCDB/orclpdb1/system01.dbf                  SYSTEM
/u01/app/oracle/oradata/ORCLCDB/orclpdb1/users01.dbf                   USERS



SQL> shut immediate
Pluggable Database closed.
SQL> startup open read only
Pluggable Database opened.
SQL>


Step 2:- 

Create directory for new clone PDB

[oracle@primary ORCLCDB]$ mkdir -p /u01/app/oracle/oradata/ORCLCDB/orclpdb2


Step 3:-Connect to the container and clone the pluggable:

[oracle@primary ~]$ sqlplus sys/admin123#@orclcdb as sysdba

SQL> SHOW CON_NAME

CON_NAME
------------------------------
CDB$ROOT

SQL> create pluggable database ORCLPDB2 from ORCLPDB1 FILE_NAME_CONVERT=('/u01/app/oracle/oradata/ORCLCDB/orclpdb1','/u01/app/oracle/oradata/ORCLCDB/orclpdb2');
Pluggable database created.

Open new PDB database


SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ ONLY  NO
         4 ORCLPDB2                       MOUNTED

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


SQL>  show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ ONLY  NO
         4 ORCLPDB2                       READ WRITE NO


Step 3:- Create tns entry for newly cloned pdbs and check connectivity.

vi /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/tnsnames.ora

orclpdb2 =
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = primary.soumya.com)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orclpdb2)
    )
  )

[oracle@primary ORCLCDB]$ sqlplus sys/admin123#@orclpdb2 as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 16 21:21:39 2020
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Last Successful login time: Thu Apr 16 2020 21:15:51 +05:30

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show con_name

CON_NAME
------------------------------
ORCLPDB2
SQL>


Step 4. Put the source PDB back to open mode.
SQL> alter pluggable database orclpdb1 close immediate ;

Pluggable database altered.

SQL> alter pluggable database orclpdb1 open;

Pluggable database altered.

SQL> select con_id, dbid, name, open_mode from v$pdbs;

   CON_ID       DBID NAME                           OPEN_MODE
---------- ---------- ------------------------------ ----------
         2  175321227 PDB$SEED                       READ ONLY
         3 3538046173 ORCLPDB1                       READ WRITE
         4  210051730 ORCLPDB2                       READ WRITE

So this concludes the process of cloning a plugable database from a existing PDB in 19c


No comments:

Post a Comment