Wednesday, October 3, 2018

Duplicate pluggable database

Step by step Clone PDB within CDB in Oracle Database 12c Oracle database 12c is providing new feature to clone database in very simple steps.
It is very easy and simple to clone database in Oracle version 12c.

Here, I am listing step by step to clone PDB (Plug-able Database ) database within it's CDB (Container Database).

Example shows, clone database from ORADBPDB to new database ORADBUPGpdb.




[oracle@CDB ~]$ sss
SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 3 17:27:37 2018
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Session altered.

CON_NAME
------------------------------
ORADBPDB
SQL> select sum(bytes)/1024/1024/1024 from dba_data_files;

SUM(BYTES)/1024/1024/1024
-------------------------
        40.446106


[oracle@CDB ~]$ cd /u01/app/oracle/oradata/orcl/

[oracle@CDB orcl]$ mkdir ORADBUPGpdb
[oracle@CDB orcl]$ cd ORADBUPGpdb/
[oracle@CDB ORADBUPGpdb]$ pwd
/u01/app/oracle/oradata/orcl/ORADBUPGpdb
[oracle@CDB ORADBUPGpdb]$


[oracle@CDB ORADBUPGpdb]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Oct 3 17:31:17 2018

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> shw pdbs
SP2-0042: unknown command "shw pdbs" - rest of line ignored.
SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 ORADBPDB           READ WRITE NO
     4 ORADBTMPPDB          READ WRITE NO
SQL> alter pluggable database ORADBPDB close immediate;

Pluggable database altered.

SQL> alter pluggable database ORADBPDB open read only;

Pluggable database altered.

SQL>  alter system set db_create_file_dest='/u01/app/oracle/oradata/orcl/ORADBUPGpdb';

System altered.

SQL> create pluggable database ORADBUPGpdb from ORADBPDB;

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 ORADBPDB           READ ONLY  NO
     4 ORADBTMPPDB          READ WRITE NO
     5 ORADBUPGpdb          MOUNTED
SQL> alter pluggable database ORADBUPGpdb open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 ORADBPDB           READ ONLY  NO
     4 ORADBTMPPDB          READ WRITE NO
     5 ORADBUPGpdb          READ WRITE NO
SQL> alter pluggable database ORADBPDB close immediate;

Pluggable database altered.

SQL> alter pluggable database ORADBPDB open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED              READ ONLY  NO
     3 ORADBPDB           READ WRITE NO
     4 ORADBTMPPDB          READ WRITE NO
     5 ORADBUPGpdb          READ WRITE NO
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@CDB ORADBUPGpdb]$





Add the entry of the new database into the tnsnames.ora



[oracle@CDB admin]$ tnsping ORADBUPGpdb

TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 03-OCT-2018 17:44:56

Copyright (c) 1997, 2016, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/122/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = CDB.local)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORADBUPGpdb.local)))
OK (10 msec)
[oracle@CDB admin]$