Tuesday, October 29, 2013

Oracle 12c: cloning a PDB

Out here I create a clone of testdb1(PDB). The clone testdb2(PDB) is on the same CDB(testdb)

SQL> alter pluggable database testdb1 close;

Pluggable database altered.

SQL> alter pluggable database testdb1 open read only;

Pluggable database altered.


SQL>
SQL> create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2');
create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2')
*
ERROR at line 1:
ORA-65005: missing or invalid file name pattern for file -
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf

The above error was due to the fact that I had not added the datafile soe.dbf from SOE tablespace into the FILE_NAME_CONVERT list. By adding it as shown below, resolved the issue.

 The below operation not allowed from within a pluggable database, and needs to be executed from within the CDB. If we execute it withing testdb1, we will get the following error message: ORA-65040: operation not allowed from within a pluggable database.


SQL> create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2','/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf','/u02/app/oracle/oradata/testdb/testdb2/soe.dbf');

Pluggable database created.

SQL>

We see below that the datafiles have been added to the directory testdb2

-bash-3.2$ pwd
/u02/app/oracle/oradata/testdb/testdb2
-bash-3.2$ ls
soe.dbf  sysaux01.dbf  system01.dbf  temp01.dbf  testdb1_users01.dbf
-bash-3.2$ ls -lrt
total 4397364
-rw-r----- 1 oracle oinstall   20979712 Oct 29 22:50 temp01.dbf
-rw-r----- 1 oracle oinstall    5251072 Oct 29 22:50 testdb1_users01.dbf
-rw-r----- 1 oracle oinstall  272637952 Oct 29 22:50 system01.dbf
-rw-r----- 1 oracle oinstall  650125312 Oct 29 22:50 sysaux01.dbf
-rw-r----- 1 oracle oinstall 3570409472 Oct 29 22:50 soe.dbf
-bash-3.2$

Below we open the newly created clone database testdb2

SQL> alter pluggable database testdb2 open;

Pluggable database altered.

SQL>

 Next, we close testdb1 which is in read only node and re-open it again.

SQL> alter pluggable database testdb1 close;


Pluggable database altered.

SQL> SQL> alter pluggable database testdb1 open ;

Pluggable database altered.

SQL>

Below we connect to the CDB (testdb) and see that datafiles for the clone PDB (testdb2) now shows up when listing the datafiles.

-bash-3.2$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Tue Oct 29 22:55:05 2013

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> show con_id

CON_ID
------------------------------
1
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/system01.dbf
/u02/app/oracle/oradata/testdb/sysaux01.dbf
/u02/app/oracle/oradata/testdb/undotbs01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/system01.dbf
/u02/app/oracle/oradata/testdb/users01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/system01.dbf
/u02/app/oracle/oradata/testdb/testdb1/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/testdb1_users01.dbf
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf
/u02/app/oracle/oradata/testdb/testdb2/system01.dbf

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/testdb2/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb2/testdb1_users01.dbf
/u02/app/oracle/oradata/testdb/testdb2/soe.dbf

14 rows selected.

SQL>

No comments: