Create Pluggable Database

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_clone/pdb_clone.html
https://docs.oracle.com/database/121/CNCPT/cdbovrvw.htm
http://docs.oracle.com/database/121/SQLRF/statements_6010.htm
http://docs.oracle.com/database/121/ADMIN/cdb_plug.htm#ADMIN13572     

Tested on:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options

1.) Checking the CDB:

On my case i have the PDB$SEED (default) and one PDB already created.
when creating a database on DBCA you need choose the option to create a CONTAINER DATABASE;
PLease note also that MULTITENANT is an option, so you need to check your license. If you are using just ONE PDB the license is not necessary.

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   4           3899196999 PDB2                           MOUNTED

                   
2.) Creating PDB - SEED:

On this step i will create 2 new plugable databases. One with ASM and other with filesystem:

[oracle@lnx01 ~]$ asmcmd lsdg
State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  EXTERN  N         512   4096  1048576      5114     4950                0            4950              0             N  DATA/

                   
Filesystem:
/oracle/oradata/CDB

SEED Location:
/oracle/oradata/CDB/pdbseed

sqlplus / as sysdba

-- Checking your location inside CDB:
col container format a30;
SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') CONTAINER FROM DUAL;

CONTAINER
------------------------------
CDB$ROOT

-- Creating based on SEED:
CREATE PLUGGABLE DATABASE PDB1 ADMIN USER PDB1_ADM IDENTIFIED BY ORACLE
  FILE_NAME_CONVERT=('/oracle/oradata/CDB/pdbseed/','/oracle/oradata/CDB/pdb1/');
  
Pluggable database created.

[oracle@lnx01 sql]$ ls -ltrh /oracle/oradata/CDB/pdb1/
total 741M
-rw-r----- 1 oracle oinstall  21M Mar  5 16:02 pdbseed_temp012016-01-07_08-28-45-AM.dbf
-rw-r----- 1 oracle oinstall 491M Mar  5 16:02 sysaux01.dbf
-rw-r----- 1 oracle oinstall 251M Mar  5 16:02 system01.dbf

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           MOUNTED
                   4           3899196999 PDB2                           READ WRITE


alter pluggable database pdb1 open;

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           READ WRITE
                   4           3899196999 PDB2                           READ WRITE

SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') CONTAINER FROM DUAL;16:05:03 SQL>

CONTAINER
------------------------------
PDB1

-- Now is ready to use:                   
  
3.) Creating PDB - Clone

The PDB that will be used as base of the clone MUST be on READ-ONLY mode:

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           READ WRITE
                   4           3899196999 PDB2                           READ WRITE

Base for the CLONE: PDB1

col container format a30;
SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') CONTAINER FROM DUAL;

CONTAINER
------------------------------
CDB$ROOT

alter pluggable database PDB1 close;
alter pluggable database pdb1 open read only;

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           READ ONLY
                   4           3899196999 PDB2                           READ WRITE

-- On this case i will clone from FILESYSTEM to +ASM

asmcmd lsdg

State    Type    Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  EXTERN  N         512   4096  1048576      5114     4950                0            4950              0             N  DATA/

[oracle@lnx01 sql]$ asmcmd
ASMCMD> pwd
+
ASMCMD> ls
DATA/
ASMCMD> cd DATA
ASMCMD> pwd
+DATA
ASMCMD> ls
ASM/
CDB/
orapwasm
ASMCMD> cd CDB
ASMCMD> pwd
+DATA/CDB
ASMCMD> ls
28C04D93059F1B02E055000000000001/
ts_asm_pdb2_01.dbf
ASMCMD> mkdir PDB3
ASMCMD> cd PDB3
ASMCMD> pwd
+DATA/CDB/PDB3
ASMCMD>

                   
CREATE PLUGGABLE DATABASE pdb3 FROM pdb1
  FILE_NAME_CONVERT=('/oracle/oradata/CDB/pdb1/','+DATA/CDB/PDB3/');                   

Pluggable database created.

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           READ ONLY
                   4           3899196999 PDB2                           READ WRITE
                   5           4142533224 PDB3                           MOUNTED

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

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

              CON_ID                 DBID NAME                           OPEN_MODE
-------------------- -------------------- ------------------------------ ----------
                   2           1147477011 PDB$SEED                       READ ONLY
                   3           3291301321 PDB1                           READ WRITE
                   4           3899196999 PDB2                           READ WRITE
                   5           4142533224 PDB3                           READ WRITE

 alter session set container=pdb3;

SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') CONTAINER FROM DUAL;
 
 CONTAINER
------------------------------
PDB3


select file_name from dba_data_files

FILE_NAME
------------------------------------------------------------
+DATA/CDB/PDB3/system01.dbf
+DATA/CDB/PDB3/sysaux01.dbf
 
select file_name from dba_temp_files;

FILE_NAME
------------------------------------------------------------
+DATA/CDB/PDB3/pdbseed_temp012016-01-07_08-28-45-am.dbf
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s