Migrating NON-CDB to CDB – NOCOPY

https://oracle-base.com/articles/12c/multitenant-migrate-non-cdb-to-pdb-12cr1
http://docs.oracle.com/database/121/ADMIN/cdb_plug.htm


1.) Listing DBs:

db01:/oracle/product/12.1.0.2/db_1:N -> NON-CDB
CDB:/oracle/product/12.1.0.2/db_1:N  -> CDB

2.) CDB:

select con_id, name, open_mode from v$pdbs;

              CON_ID NAME                           OPEN_MODE
-------------------- ------------------------------ ----------
                   2 PDB$SEED                       READ ONLY
                   3 PDB1                           READ WRITE
                   5 PDB3                           READ WRITE

3.) NON-CDB:

select instance_name, con_id, status from v$instance;

INSTANCE_NAME                  CON_ID STATUS
---------------- -------------------- ------------
db01                                0 OPEN

select name from v$datafile;

NAME
----------------------------------------------------------------------------------
/oracle/oradata/DB01/datafile/o1_mf_system_c885167z_.dbf
/oracle/oradata/DB01/datafile/o1_mf_sysaux_c884zs08_.dbf
/oracle/oradata/DB01/datafile/o1_mf_undotbs1_c8852oby_.dbf
/oracle/oradata/DB01/datafile/o1_mf_users_c8852mj6_.dbf

select * from v$logfile
13:01:55 SQL> /

              GROUP# STATUS  TYPE    MEMBER                                                                 IS_               CON_ID
-------------------- ------- ------- ---------------------------------------------------------------------- --- --------------------
                   3         ONLINE  /oracle/oradata/DB01/onlinelog/o1_mf_3_c8853lc8_.log                   NO                     0
                   3         ONLINE  /oracle/fast_recovery_area/DB01/onlinelog/o1_mf_3_c8853ldk_.log        YES                    0
                   2         ONLINE  /oracle/oradata/DB01/onlinelog/o1_mf_2_c8853ky9_.log                   NO                     0
                   2         ONLINE  /oracle/fast_recovery_area/DB01/onlinelog/o1_mf_2_c8853l0j_.log        YES                    0
                   1         ONLINE  /oracle/oradata/DB01/onlinelog/o1_mf_1_c8853kkh_.log                   NO                     0
                   1         ONLINE  /oracle/fast_recovery_area/DB01/onlinelog/o1_mf_1_c8853km4_.log        YES                    0


4.) Clear Shutdown on NON-CDB

shut immediate;
startup open read only;

select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY

5.) DBMS_PDB - Describe

BEGIN
  DBMS_PDB.DESCRIBE(
    pdb_descr_file => '/home/oracle/xml/db01.xml');
END;
/

6.) Close NON-CDB

shut immediate;

7.) Creating PDB

/oracle/oradata/CDB/pdb4

CREATE PLUGGABLE DATABASE pdb4 USING '/home/oracle/xml/db01.xml'
  COPY
  FILE_NAME_CONVERT = ('/oracle/oradata/DB01/datafile/', '/oracle/oradata/CDB/pdb4/');

  ERROR at line 1:
ORA-01276: Cannot add file /oracle/oradata/CDB/pdb4/o1_mf_system_c885167z_.dbf.  File has an Oracle Managed Files file name.

Note: Here we faced an error because my database is on OMF.
--> Filename parameters for Create Pluggable Database with OMF and non-OMF (Doc ID 2095929.1)

--> Here my favorite way. Because you can imagine if we need plug a big TERABYTE database. NOCOPY option is a good alternative.
   
CREATE PLUGGABLE DATABASE pdb4 USING '/home/oracle/xml/db01.xml'
  NOCOPY
  TEMPFILE REUSE;
 
Pluggable database created. 

select con_id, name, open_mode from v$pdbs;

              CON_ID NAME                           OPEN_MODE
-------------------- ------------------------------ ----------
                   2 PDB$SEED                       READ ONLY
                   3 PDB1                           READ WRITE
                   4 PDB4                           MOUNTED
                   5 PDB3                           READ WRITE

8.) $ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

alter session set container=PDB4;
@?/rdbms/admin/noncdb_to_pdb.sql

13:21:30 SQL> -- leave the PDB in the same state it was when we started
13:21:30 SQL> BEGIN
13:21:30   2    execute immediate '&open_sql &restricted_state';
13:21:30   3  EXCEPTION
13:21:30   4    WHEN OTHERS THEN
13:21:30   5    BEGIN
13:21:30   6      IF (sqlcode <> -900) THEN
13:21:30   7        RAISE;
13:21:30   8      END IF;
13:21:30   9    END;
13:21:30  10  END;
13:21:30  11  /

PL/SQL procedure successfully completed.

13:21:30 SQL>
13:21:30 SQL>
13:21:30 SQL> WHENEVER SQLERROR CONTINUE;

 select con_id, name, open_mode from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         4 PDB4                           MOUNTED

13:24:52 SQL> ALTER DATABASE OPEN;

Database altered.

13:29:26 SQL> select con_id, name, open_mode from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         4 PDB4                           READ WRITE

1 row selected.

SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES
13:30:35 SQL> /

TABLESPACE_NAME                FILE_NAME
------------------------------ ----------------------------------------------------------------------
USERS                          /oracle/oradata/DB01/datafile/o1_mf_users_c8852mj6_.dbf
SYSAUX                         /oracle/oradata/DB01/datafile/o1_mf_sysaux_c884zs08_.dbf
SYSTEM                         /oracle/oradata/DB01/datafile/o1_mf_system_c885167z_.dbf

Note: We can delete UNDO because the UNDO tablespace now is from CDB.

[root@lnx01 ~]# fuser /oracle/oradata/DB01/datafile/o1_mf_undotbs1_c8852oby_.dbf
[root@lnx01 ~]# rm /oracle/oradata/DB01/datafile/o1_mf_undotbs1_c8852oby_.dbf
rm: remove regular file `/oracle/oradata/DB01/datafile/o1_mf_undotbs1_c8852oby_.dbf'? y

                   

Checking BALANCE IO on ASM

-- Reference:
-- https://community.oracle.com/docs/DOC-995178

prompt "Checking balance IO on ASM...";

SELECT dg.group_number "GROUP#",
       dg.name,
       DECODE (total_dg.total_io, 0, 100, 100 * (DECODE (SIGN (1 - df.sum_io / total_dg.total_io), -1, 0, (1 - df.sum_io / total_dg.total_io)))) "IO_BALANCED"
  FROM (SELECT d.group_number group_number,
                 SUM (ABS ((d.reads + d.writes) - tot.avg_io)) sum_io
            FROM v$asm_disk_stat d,
                 (SELECT group_number,
                           SUM (reads) + SUM (writes),
                           DECODE (COUNT (*), 0, 0, (SUM (reads) + SUM (writes)) / COUNT (*)) avg_io
                      FROM v$asm_disk_stat
                     WHERE header_status = 'MEMBER'
                  GROUP BY group_number) tot
           WHERE header_status = 'MEMBER' AND tot.group_number = d.group_number
        GROUP BY d.group_number) df,
       (SELECT group_number,
                 SUM (reads) + SUM (writes) total_io
            FROM v$asm_disk_stat
           WHERE header_status = 'MEMBER'
        GROUP BY group_number) total_dg,
        V$ASM_DISKGROUP dg
 WHERE df.group_number = total_dg.group_number
 AND df.group_number = dg.group_number;

Using LIKE on Long Data Types

-- Constraints SEARCH_CONDITION
-- Carlos Magno

create or replace function getlong_const( p_owner in varchar2,
                                          p_table_name in varchar2,
                                          p_cons_name in varchar2) return varchar2
as
l_cursor integer default dbms_sql.open_cursor;
l_n number;
l_long_val varchar2(4000);
l_long_len number;
l_buflen number := 4000;
l_curpos number := 0;
begin
dbms_sql.parse( l_cursor,
'select search_condition from dba_constraints where owner = :x and table_name=:y and constraint_name=:z ',
dbms_sql.native );
dbms_sql.bind_variable( l_cursor, ':x', p_owner );
dbms_sql.bind_variable( l_cursor, ':y', p_table_name );
dbms_sql.bind_variable( l_cursor, ':z', p_cons_name );


dbms_sql.define_column_long(l_cursor, 1);
l_n := dbms_sql.execute(l_cursor);

if (dbms_sql.fetch_rows(l_cursor)>0)
then
   dbms_sql.column_value_long(l_cursor, 1, l_buflen, l_curpos ,l_long_val, l_long_len );
end if;
dbms_sql.close_cursor(l_cursor);
return l_long_val;
end getlong_const;
/

select * 
from dba_constraints 
where getlong_const(owner, table_name, constraint_name) like '%NOT NULL%';

Recover Pluggable Database

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_pitr/pdb_pitr.html
https://oracle-base.com/articles/12c/multitenant-rman-backup-recovery-cdb-and-pdb-12cr1#pdb-recovery

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.) Simulating some erros on PDB1:

 select name, open_mode from v$pdbs;

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

alter pluggable database all open;

Pluggable database altered.

select name, open_mode from v$pdbs;

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

alter session set container=pdb1;

 select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
TEMP


create tablespace ts_pdb1 datafile '/oracle/oradata/CDB/pdb1/ts_pdb1.dbf' size 10m;

Tablespace created.

alter user test default tablespace ts_pdb1;

User altered.

alter user test quota unlimited on ts_pdb1;

User altered.

--> To connect directly on PDB:

alter system set local_listener='lnx01:1521' scope=both;

select con_id, name, open_mode from v$pdbs;

              CON_ID NAME                           OPEN_MODE
-------------------- ------------------------------ ----------
                   2 PDB$SEED                       READ ONLY
                   3 PDB1                           READ WRITE <===
                   5 PDB3                           READ WRITE

 conn test/test@pdb1
Connected.

show con_id

CON_ID
------------------------------
3

insert into t1 values (1,to_char(sysdate,'ddmmyyyy-hh24miss'));
insert into t1 values (2,to_char(sysdate,'ddmmyyyy-hh24miss'));
insert into t1 values (3,to_char(sysdate,'ddmmyyyy-hh24miss'));

commit;
        
select scn from v$database;

 select CURRENT_SCN from v$database;

         CURRENT_SCN
--------------------
             2058379
             
insert into TEST.t1 values (4,'AFTER SCN 2058379');

commit;

 SELECT * FROM TEST.T1;

                 NUM TEXT
-------------------- ---------------------
                   1 06032016-141735
                   2 06032016-141735
                   3 06032016-141735
                   4 AFTER SCN 2058379


2.) Listing backups:

RMAN> LIST BACKUP OF PLUGGABLE DATABASE PDB1;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T132621
        Piece Name: /data02/backup/CDB/CDB_0mqvq6cc_1_1
  List of Datafiles in backup set 22
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 27   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T133029
        Piece Name: /data02/backup/CDB/CDB_0rqvq6jl_1_1
  List of Datafiles in backup set 27
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

  
--> Please note that SCN from Backup is lower than desired SCN:

3.) Recover PDB1 until  scn: 2058379

 show con_id

CON_ID
------------------------------
3


shut immediate;

Pluggable Database closed.

 show con_id
 
CON_ID
------------------------------
1

select name, con_id, open_mode from v$pdbs;

NAME                                         CON_ID OPEN_MODE
------------------------------ -------------------- ----------
PDB$SEED                                          2 READ ONLY
PDB1                                              3 MOUNTED
PDB3                                              5 READ WRITE

rman target /

RUN {
  SET UNTIL scn 2058379;
  RESTORE PLUGGABLE DATABASE pdb1;
  RECOVER PLUGGABLE DATABASE pdb1;
  ALTER PLUGGABLE DATABASE pdb1 OPEN RESETLOGS;
}

                2> 3> 4> 5> 6>
executing command: SET until clause

Starting restore at 06-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK

creating datafile file number=20 name=/oracle/oradata/CDB/pdb1/ts_pdb1.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00016 to /oracle/oradata/CDB/pdb1/system01.dbf
channel ORA_DISK_1: restoring datafile 00017 to /oracle/oradata/CDB/pdb1/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /data02/backup/CDB/CDB_0rqvq6jl_1_1
channel ORA_DISK_1: piece handle=/data02/backup/CDB/CDB_0rqvq6jl_1_1 tag=TAG20160306T133029
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 06-MAR-16

Starting recover at 06-MAR-16
current log archived
using channel ORA_DISK_1
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='ecby'

initialization parameters used for automatic instance:
db_name=CDB
db_unique_name=ecby_pitr_pdb1_CDB
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/oracle
_system_trig_enabled=FALSE
sga_target=800M
processes=200
#No auxiliary destination in use
enable_pluggable_database=true
_clone_one_pdb_recovery=true
control_files=/oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl
#No auxiliary parameter file used


starting up automatic instance CDB

Oracle instance started

Total System Global Area     838860800 bytes

Fixed Size                     2929936 bytes
Variable Size                230689520 bytes
Database Buffers             599785472 bytes
Redo Buffers                   5455872 bytes
Automatic instance created

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# restore the controlfile
restore clone controlfile;

# mount the controlfile
sql clone 'alter database mount clone database';
}
executing Memory Script

executing command: SET until clause

Starting restore at 06-MAR-16
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905781318_cfrz8pqp_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905781318_cfrz8pqp_.bkp tag=TAG20160306T135518
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl
Finished restore at 06-MAR-16

sql statement: alter database mount clone database

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# switch to valid datafilecopies
switch clone datafile  16 to datafilecopy
 "/oracle/oradata/CDB/pdb1/system01.dbf";
switch clone datafile  17 to datafilecopy
 "/oracle/oradata/CDB/pdb1/sysaux01.dbf";
switch clone datafile  20 to datafilecopy
 "/oracle/oradata/CDB/pdb1/ts_pdb1.dbf";
# set destinations for recovery set and auxiliary set datafiles
set newname for datafile  1 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf";
set newname for datafile  4 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf";
set newname for datafile  3 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf";
set newname for datafile  6 to
 "/oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf";
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3, 6;

switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

datafile 16 switched to datafile copy
input datafile copy RECID=4 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/system01.dbf

datafile 17 switched to datafile copy
input datafile copy RECID=5 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/sysaux01.dbf

datafile 20 switched to datafile copy
input datafile copy RECID=6 STAMP=905783225 file name=/oracle/oradata/CDB/pdb1/ts_pdb1.dbf

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 06-MAR-16
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /data02/backup/CDB/CDB_0lqvq6bt_1_1
channel ORA_AUX_DISK_1: piece handle=/data02/backup/CDB/CDB_0lqvq6bt_1_1 tag=TAG20160306T132621
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 06-MAR-16

datafile 1 switched to datafile copy
input datafile copy RECID=11 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_system_cfs140md_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_undotbs1_cfs140n4_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=905783240 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=905783241 file name=/oracle/fast_recovery_area/CDB/datafile/o1_mf_users_cfs149f8_.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 2058379;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  4 online";
sql clone "alter database datafile  3 online";
sql clone 'PDB1' "alter database datafile
 16 online";
sql clone 'PDB1' "alter database datafile
 17 online";
sql clone 'PDB1' "alter database datafile
 20 online";
sql clone "alter database datafile  6 online";
# recover pdb
recover clone database tablespace  "SYSTEM", "UNDOTBS1", "SYSAUX", "USERS" pluggable database
 'PDB1'   delete archivelog;
sql clone 'alter database open read only';
plsql <<<begin
   add_dropped_ts;
end; >>>;
plsql <<<begin
   save_pdb_clean_scn;
end; >>>;
# shutdown clone before import
shutdown clone abort
plsql <<<begin
   pdbpitr_inspect(pdbname =>  'PDB1');
end; >>>;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  4 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  16 online

sql statement: alter database datafile  17 online

sql statement: alter database datafile  20 online

sql statement: alter database datafile  6 online

Starting recover at 06-MAR-16
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 90 is already on disk as file /data01/CDB/archives/1_90_900491294.dbf
archived log for thread 1 with sequence 91 is already on disk as file /data01/CDB/archives/1_91_900491294.dbf
archived log file name=/data01/CDB/archives/1_90_900491294.dbf thread=1 sequence=90
archived log file name=/data01/CDB/archives/1_91_900491294.dbf thread=1 sequence=91
media recovery complete, elapsed time: 00:00:01
Finished recover at 06-MAR-16

sql statement: alter database open read only



Oracle instance shut down


Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/fast_recovery_area/CDB/datafile/o1_mf_sysaux_cfs140n9_.dbf deleted
auxiliary instance file /oracle/fast_recovery_area/CDB/controlfile/o1_mf_cfs13q8s_.ctl deleted
Finished recover at 06-MAR-16

Statement processed

4.) Checking after recovery

 show con_id

CON_ID
------------------------------
1
14:28:19 SQL> select name, con_id, open_mode from v$pdbs;

NAME                                         CON_ID OPEN_MODE
------------------------------ -------------------- ----------
PDB$SEED                                          2 READ ONLY
PDB1                                              3 READ WRITE
PDB3                                              5 READ WRITE

3 rows selected.

 conn test/test@pdb1;
Connected.

 SELECT * FROM TEST.T1;

                 NUM TEXT
-------------------- --------------------
                   1 06032016-141735
                   2 06032016-141735
                   3 06032016-141735

Backup Pluggable Database

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_pitr/pdb_pitr.html

Tested on: 
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

1.) Listing PDBS:

13:05:01 SQL> select name, open_mode from v$pdbs;

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


2.) Opening PDBs:

alter pluggable database all open;

Pluggable database altered.

select name, open_mode from v$pdbs;

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

3.) Backup directory:

/data02/backup/CDB

4.) Database in archive MODE:

archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /data01/CDB/archives
Oldest online log sequence     87
Next log sequence to archive   89
Current log sequence           89

5.) Flashback database enabled:

db_recovery_file_dest                string      /oracle/fast_recovery_area
db_recovery_file_dest_size           big integer 4560M

db_flashback_retention_target        integer     1440

select FLASHBACK_ON from v$database;

FLASHBACK_ON
------------------
NO

shut immediate;
startup mount;
alter database flashback on;
alter database open;

 select FLASHBACK_ON from v$database;

FLASHBACK_ON
------------------
YES


5.) Backup CDB:

rman target /

configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

 configure channel device type disk format '/data02/backup/CDB/CDB_%U';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/data02/backup/CDB/CDB_%U';
new RMAN configuration parameters are successfully stored

 backup database plus archivelog;


Starting backup at 06-MAR-16
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=77 RECID=1 STAMP=901791271
input archived log thread=1 sequence=78 RECID=2 STAMP=901791829
input archived log thread=1 sequence=79 RECID=3 STAMP=901791879
input archived log thread=1 sequence=80 RECID=4 STAMP=901794646
input archived log thread=1 sequence=81 RECID=5 STAMP=905701139
input archived log thread=1 sequence=82 RECID=6 STAMP=905701398
input archived log thread=1 sequence=83 RECID=7 STAMP=905701551
input archived log thread=1 sequence=84 RECID=8 STAMP=905778404
input archived log thread=1 sequence=85 RECID=9 STAMP=905778523
input archived log thread=1 sequence=86 RECID=10 STAMP=905778549
input archived log thread=1 sequence=87 RECID=11 STAMP=905778576
input archived log thread=1 sequence=88 RECID=12 STAMP=905778589
input archived log thread=1 sequence=89 RECID=13 STAMP=905779578
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0kqvq6bq_1_1 tag=TAG20160306T132618 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 06-MAR-16

Starting backup at 06-MAR-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/oracle/oradata/CDB/undotbs01.dbf
input datafile file number=00001 name=/oracle/oradata/CDB/system01.dbf
input datafile file number=00003 name=/oracle/oradata/CDB/sysaux01.dbf
input datafile file number=00006 name=/oracle/oradata/CDB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0lqvq6bt_1_1 tag=TAG20160306T132621 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/oracle/oradata/CDB/pdb1/sysaux01.dbf
input datafile file number=00016 name=/oracle/oradata/CDB/pdb1/system01.dbf
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0mqvq6cc_1_1 tag=TAG20160306T132621 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00019 name=+DATA/CDB/PDB3/sysaux01.dbf
input datafile file number=00018 name=+DATA/CDB/PDB3/system01.dbf
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0nqvq6cj_1_1 tag=TAG20160306T132621 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/oracle/oradata/CDB/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/oracle/oradata/CDB/pdbseed/system01.dbf
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0oqvq6cr_1_1 tag=TAG20160306T132621 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 06-MAR-16

Starting backup at 06-MAR-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=90 RECID=14 STAMP=905779618
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0pqvq6d2_1_1 tag=TAG20160306T132658 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-MAR-16

Starting Control File and SPFILE Autobackup at 06-MAR-16
piece handle=/oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905779619_cfrxmmm0_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 06-MAR-16

6.) Backup PDB

BACKUP PLUGGABLE DATABASE pdb1;

Starting backup at 06-MAR-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/oracle/oradata/CDB/pdb1/sysaux01.dbf
input datafile file number=00016 name=/oracle/oradata/CDB/pdb1/system01.dbf
channel ORA_DISK_1: starting piece 1 at 06-MAR-16
channel ORA_DISK_1: finished piece 1 at 06-MAR-16
piece handle=/data02/backup/CDB/CDB_0rqvq6jl_1_1 tag=TAG20160306T133029 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 06-MAR-16

Starting Control File and SPFILE Autobackup at 06-MAR-16
piece handle=/oracle/fast_recovery_area/CDB/autobackup/2016_03_06/o1_mf_s_905779836_cfrxtf16_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 06-MAR-16

7.) Listing Backups:

list backup of database summary;


List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
21      B  F  A DISK        06-MAR-16       1       1       NO         TAG20160306T132621
22      B  F  A DISK        06-MAR-16       1       1       NO         TAG20160306T132621
23      B  F  A DISK        06-MAR-16       1       1       NO         TAG20160306T132621
24      B  F  A DISK        06-MAR-16       1       1       NO         TAG20160306T132621
27      B  F  A DISK        06-MAR-16       1       1       NO         TAG20160306T133029


list backup  of pluggable database pdb1;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T132621
        Piece Name: /data02/backup/CDB/CDB_0mqvq6cc_1_1
  List of Datafiles in backup set 22
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
27      Full    603.45M    DISK        00:00:04     06-MAR-16
        BP Key: 27   Status: AVAILABLE  Compressed: NO  Tag: TAG20160306T133029
        Piece Name: /data02/backup/CDB/CDB_0rqvq6jl_1_1
  List of Datafiles in backup set 27
  Container ID: 3, PDB Name: PDB1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  16      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/system01.dbf
  17      Full 2053591    06-MAR-16 /oracle/oradata/CDB/pdb1/sysaux01.dbf

Drop Pluggable Database

http://docs.oracle.com/database/121/ADMIN/cdb_plug.htm#ADMIN13658

1.) DROP PDB2

alter session set container=pdb2;

Session altered.

select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
/oracle/oradata/CDB/pdb2/system01.dbf
/oracle/oradata/CDB/pdb2/sysaux01.dbf
/oracle/oradata/CDB/pdb2/ts_pdb2_01_01.dbf
+DATA/CDB/28C04D93059F1B02E055000000000001/DATAFILE/ts_asm_pdb2.257.901697877


2.) List PDBs

alter session set container=cdb$root

Session altered.

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 pluggable database pdb2 close;
drop pluggable database pdb2 including datafiles;

 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
                   5           4142533224 PDB3                           READ WRITE

SQL> !ls -ltrh /oracle/oradata/CDB/pdb2/
total 0

ASMCMD> pwd
+DATA/CDB/2D54BCC7D628108FE0530100007F9019/DATAFILE
ASMCMD> ls -l ts_asm_pdb2.257.901697877
ASMCMD-8002: entry 'ts_asm_pdb2.257.901697877' does not exist in directory '+DATA/CDB/2D54BCC7D628108FE0530100007F9019/DATAFILE/'


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