Cloning of PDB database into same CDB database Oracle

Cloning a PDB database into same CDB database in Oracle 12c

Clone a PDB database from another PDB database present in Same CDB.

Following are the steps:

1. Create new directory in oradata folder e.g PDB2 (location where you want to create database).

2. Connect to container database(CDB)

sqlplus sys as sysdba

3. Check the pluggable database status.

SQL> select name,open_mode from v$pdbs;

NAME      OPEN_MODE
--------  -----------
PDB$SEED  READ ONLY
PDB1      READ WRITE


4. Close the PDB1 database.

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

5. Open PDB1 Database in read only mode.

SQL> alter pluggable database pdb1 open read only;
Pluggable database altered.

6. Start cloning process from pdb1 to pdb2.

Option 1: It will create files as oracle managed file system otherwise you need to specify manually each file.

SQL> create pluggable database pdb2 from pdb1 create_file_dest='D:\container\oradata\cdb1\pdb2';

Option 2: It will create the exact structure as present in old PDB.

SQL> CREATE PLUGGABLE DATABASE pdb3 FROM pdb1
FILE_NAME_CONVERT = ('D:\container\oradata\cdb1\pdb1\', 'D:\container\oradata\cdb1\pdb3\')
PATH_PREFIX = 'D:\container\oradata\cdb1\pdb3';
Pluggable database created.

7. Check the database PDB is created.

SQL> select name,open_mode from v$pdbs;

NAME      OPEN_MODE
--------  -----------
PDB$SEED  READ ONLY
PDB1      READ ONLY
PDB2      MOUNTED


8. Open the database for user access.

alter pluggable database pdb1 close;
alter pluggable database pdb1 open;

alter pluggable database pdb2 close;
alter pluggable database pdb2 open;

9. Check file location and status.

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;

select con_id, tablespace_name, File_Name from cdb_data_files order by 1, 2;

10. Drop the OLD PDB database.

-- It will keep datafiles on disk only temp tablespace is deleted
DROP PLUGGABLE DATABASE pdb1 KEEP DATAFILES;

-- It will drop all the datafiles associated with pluggable database
DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.