Dataguard Setup with Broker

Container Database: cdbst -> cdbstdg
Primary: odasys12
StandBy: odasys11

1.) Primary - Check Archive Log Mode:

sqlplus / as sysdba

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     15
Next log sequence to archive   17
Current log sequence           17

2.) Primary - FORCE LOGGING

ALTER DATABASE FORCE LOGGING;
ALTER SYSTEM SWITCH LOGFILE;

3.) Primary - Standby Redo Log Files (SUM of Redo Logs + 1 with the max size of redo log files)

col member format A60
select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                                       IS_     CON_ID
---------- ------- ------- ------------------------------------------------------------ --- ----------
         1         ONLINE  +REDO/CDBST/ONLINELOG/group_1.334.942934501                  NO           0
         2         ONLINE  +REDO/CDBST/ONLINELOG/group_2.287.942934507                  NO           0
         3         ONLINE  +REDO/CDBST/ONLINELOG/group_3.292.942934511                  NO           0

SQL> select max(bytes) / (1024*1024) mb from v$log;

        MB
----------
      1024

ALTER DATABASE ADD STANDBY LOGFILE ('+REDO/CDBST/ONLINELOG/standby_redo01.log') SIZE 1g;
ALTER DATABASE ADD STANDBY LOGFILE ('+REDO/CDBST/ONLINELOG/standby_redo02.log') SIZE 1g;
ALTER DATABASE ADD STANDBY LOGFILE ('+REDO/CDBST/ONLINELOG/standby_redo03.log') SIZE 1g;
ALTER DATABASE ADD STANDBY LOGFILE ('+REDO/CDBST/ONLINELOG/standby_redo04.log') SIZE 1g;

4.) Primary - Enable Flashback Database      
ALTER DATABASE FLASHBACK ON;

5.) Primary - Init Parameters

SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      cdbst

SQL> show parameter db_unique_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_unique_name                       string      cdbst

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO scope=both;

6.)  Primary/StandBy - Listener.ora

Specific Listener for DRP
PORT: 1527
Name: LISTENER_DG
ORACLE_HOME: /u01/app/oracle/product/12.1.0.2/dbhome_1

srvctl add listener -l LISTENER_DG -o $ORACLE_HOME -p 1527
srvctl start listener -l LISTENER_DG -n odasys12
srvctl start listener -l LISTENER_DG -n odasys11

a.) Primary - include into Listener.ora

SID_LIST_LISTENER_DG =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = cdbst_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/12.1.0.2/dbhome_1)
      (SID_NAME = cdbst)
    )
  )

lsnrctl reload LISTENER_DG
lsnrctl status LISTENER_DG

Service "cdbst_DGMGRL" has 1 instance(s).
  Instance "cdbst", status UNKNOWN, has 1 handler(s) for this service...

-- Include the Host/Port into the LOCAL_LISTENER to listener on the new port
alter system set LOCAL_LISTENER="(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=odasys12)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=odasys12)(PORT=1527)))" scope=BOTH;  
  
b.) StandBy - include into Listener.ora

SID_LIST_LISTENER_DG =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = cdbstdg_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/12.1.0.2/dbhome_1)
      (SID_NAME = cdbstdg)
    )
  )

lsnrctl reload LISTENER_DG
lsnrctl status LISTENER_DG

Service "cdbstdg_DGMGRL" has 1 instance(s).
  Instance "cdbst", status UNKNOWN, has 1 handler(s) for this service...

7.) TNS Entries -  Include this TNS for both servers

CDBSTP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys12.bgl.lu)(PORT = 1527))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (sid = cdbst)
    )
  )

CDBSTDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys11.bgl.lu)(PORT = 1527))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (sid = cdbstdg)
    )
  )

Note: After configure both tnsnames.ora test with tnsping the entries.  

8.) Duplicate
StandBy Database Name: cdbstdg

a.) On the primary database:

create pfile='initcdbstdg.ora' from spfile;

scp initcdbstdg.ora odasys11:/u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
scp orapwcdbst odasys11:/u01/app/oracle/product/12.1.0.2/dbhome_1/dbs

b.) On the Standby Server:
cd /u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
cp orapwcdbst orapwcdbstdg

vi initcdbstdg.ora
:%s/cdbst/cdbstdg/g

- Check the Parameters to see if there are some specific configurations to fix
*.db_name='cdbst' --> must keep the same for both sites
*.db_unique_name='cdbstdg' --> include 

mkdir -p /u01/app/oracle/admin/cdbstdg/adump

c.) Preparing the ASM to Receive the CDB and PDBs:

- Controlfile:
inside of the init.ora for the standby there is:
*.control_files='+REDO/CDBST/CONTROLFILE/current.331.942934501'

asmcmd
cd +REDO
mkdir CDBSTDG
cd CDBSTDG
mkdir CONTROLFILE

Change the controlfile parameter to:

*.control_files='+REDO/CDBSTDG/CONTROLFILE/control_cdbstdg.ctl'

- Datafiles on PRIMARY:
Directories to CONVERT CLAUSE
col DIRECTORY format a60
select distinct substr(file_name,1,instr(file_name,'/',-1)) directory from cdb_data_files;

+DATA/NSCDB2/DATAFILE/
+DATA/NSCDB1/datafile/
+DATA/CDBST/DATAFILE/
+DATA/NSCDB1/DATAFILE/
+DATA/NSCDB3/DATAFILE/

select distinct substr(member,1,instr(member,'/',-1)) directory from v$logfile;

+REDO/CDBST/ONLINELOG/

- Create the directories on ASM to receive the files

+DATA/DG/NSCDB2/DATAFILE/
+DATA/DG/NSCDB1/datafile/
+DATA/DG/CDBST/DATAFILE/
+DATA/DG/NSCDB1/DATAFILE/
+DATA/DG/NSCDB3/DATAFILE/

+REDO/DG/CDBST/ONLINELOG/

- create the file DupDG.rman

cd /home/oracle/scripts

vi DupDG.rman

DUPLICATE TARGET DATABASE
  FOR STANDBY
  FROM ACTIVE DATABASE
  DORECOVER
  NOFILENAMECHECK;

d.) Start the standby instance:

- Include into /etc/oratab
cdbstdg:/u01/app/oracle/product/12.1.0.2/dbhome_1:N

. oraenv
cdbstdg

sqlplus / as sysdba 
create spfile='+DATA/DG/spfilecdbstdg.ora' from pfile;
- change the initcdbstdg.ora
-- > SPFILE='+DATA/DG/spfilecdbstdg.ora'

startup nomount;

alter system set LOCAL_LISTENER="(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=odasys11)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=odasys11)(PORT=1527)))" scope=BOTH;  
alter system  SET db_file_name_convert='+DATA/NSCDB2/DATAFILE/','+DATA/DG/NSCDB2/DATAFILE/','+DATA/NSCDB1/datafile/','+DATA/DG/NSCDB1/datafile/','+DATA/CDBST/DATAFILE/','+DATA/DG/CDBST/DATAFILE/','+DATA/NSCDB1/DATAFILE/','+DATA/DG/NSCDB1/DATAFILE/','+DATA/NSCDB3/DATAFILE/','+DATA/DG/NSCDB3/DATAFILE/' scope=spfile;
alter system  SET log_file_name_convert='+REDO/CDBST/ONLINELOG/','+REDO/DG/CDBST/ONLINELOG/' scope=spfile;
alter system  SET job_queue_processes=0 scope=both;

shut immediate
startup nomount;

-- On this case as the CONVERT parameter is used, is need to set on the primary also;
alter system  SET db_file_name_convert='+DATA/DG/NSCDB2/DATAFILE/','+DATA/NSCDB2/DATAFILE/','+DATA/DG/NSCDB1/datafile/','+DATA/NSCDB1/datafile/','+DATA/DG/CDBST/DATAFILE/','+DATA/CDBST/DATAFILE/','+DATA/DG/NSCDB1/DATAFILE/','+DATA/NSCDB1/DATAFILE/','+DATA/DG/NSCDB3/DATAFILE/','+DATA/NSCDB3/DATAFILE/' scope=spfile;
alter system  SET log_file_name_convert='+REDO/DG/CDBST/ONLINELOG/','+REDO/CDBST/ONLINELOG/' scope=spfile;

-- If the parameter needs to be changed after the BROKER is already configured use the commands below:
edit database 'cdbst' set property 'DbFileNameConvert'='+DATA/DG/NSCDB2/DATAFILE/,+DATA/NSCDB2/DATAFILE/,+DATA/DG/NSCDB1/datafile/,+DATA/NSCDB1/datafile/,+DATA/DG/CDBST/DATAFILE/,+DATA/CDBST/DATAFILE/,+DATA/DG/NSCDB1/DATAFILE/,+DATA/NSCDB1/DATAFILE/,+DATA/DG/NSCDB3/DATAFILE/,+DATA/NSCDB3/DATAFILE/';
edit database 'cdbst' set property 'LogFileNameConvert'='+REDO/DG/CDBST/ONLINELOG/,+REDO/CDBST/ONLINELOG/';
show database 'cdbst' 'InconsistentProperties';

---> Test the connections using TNS
rman target sys/welcome1@CDBSTP AUXILIARY sys/welcome1@odasys11:1527/cdbstdg_DGMGRL
-- It should works in both servers

e.) Execute the Duplicate
cd $ORACLE_HOME/dbs

rman target sys/welcome1@CDBSTP AUXILIARY sys/welcome1@odasys11:1527/cdbstdg_DGMGRL @DupDG.rman log DupDG.log

Finished recover at 04/05/2017 14:23:22
Finished Duplicate Db at 04/05/2017 14:23:49

9.) Broker

-- Both Servers:
ALTER SYSTEM SET dg_broker_start=true;

-- PRIMARY
dgmgrl sys/welcome1@cdbst
CREATE CONFIGURATION cdbst_config AS PRIMARY DATABASE IS cdbst CONNECT IDENTIFIER IS cdbstp;
ADD DATABASE cdbstdg AS CONNECT IDENTIFIER IS cdbstdg MAINTAINED AS PHYSICAL;
ENABLE CONFIGURATION;
SHOW CONFIGURATION;
show database cdbst;
show database cdbstdg;

-- Choose the best option for the Environment: maxavailability (Enabled)
edit database 'cdbst' set property 'LogXptMode'='SYNC';
edit database 'cdbstdg' set property 'LogXptMode'='SYNC';
edit configuration set protection mode as maxavailability;

-- To change to maxperformance
edit configuration set protection mode as maxperformance;
edit database 'cdbst' set property 'LogXptMode'='ASYNC';
edit database 'cdbstdg' set property 'LogXptMode'='ASYNC';

10.) Configure FAL / FLASHBACK

- FAL

Primary:
alter system set fal_client=cdbstp scope=both;
alter system set fal_server=cdbstdg scope=both;

StandBy:
alter system set fal_server=cdbstp scope=both;
alter system set fal_client=cdbstdg scope=both;

- FLASHBACK

dgmgrl sys/welcome1
edit database 'cdbstdg' set state='APPLY-OFF';
exit
sqlplus / as sysdba 
alter database  flashback on;
exit
dgmgrl sys/welcome1
edit database 'cdbstdg' set state='APPLY-ON';

11.) Including the database into the ocr

srvctl add database -d cdbstdg -o /u01/app/oracle/product/12.1.0.2/dbhome_1 -r physical_standby -s mount -a DATA,REDO,RECO -p '+DATA/DG/spfilecdbstdg.ora'
srvctl add instance -d cdbstdg -i cdbstdg -n odasys11

- test on Standby:

srvctl stop database -d cdbstdg
srvctl start database -d cdbstdg
dgmgrl sys/welcome1@cdbstp
show configuration

12.) Switchover

-- Check if is possible execute the switchover

validate database verbose 'cdbst';
Database Role:    Primary database
Ready for Switchover:  Yes
 
-- PRIMARY

salplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NSCDB1                         READ WRITE NO
         4 NSCDB2                         READ WRITE NO
         5 NSCDB3                         READ WRITE NO

SQL> alter session set container=NSCDB1;

Session altered.

SQL> select tablespace_name from dba_data_files;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
USERS
TS_TEST

SQL> create user dr identified by dr;

User created.

SQL> grant dba to dr;

Grant succeeded.

SQL> alter user dr default tablespace TS_TEST;

User altered.

SQL> create table dr.teste as select * from dba_users;

Table created.

SQL> select count(*) from dr.teste;

  COUNT(*)
----------
        21

exit

dgmgrl sys/welcome1@cdbstp
switchover to cdbstdg;
Performing switchover NOW, please wait...
Operation requires a connection to instance "cdbstdg" on database "cdbstdg"
Connecting to instance "cdbstdg"...
Connected as SYSDBA.
New primary database "cdbstdg" is opening...
Oracle Clusterware is restarting database "cdbst" ...
Switchover succeeded, new primary is "cdbstdg"

DGMGRL> show configuration

Configuration - cdbst_config

  Protection Mode: MaxAvailability
  Members:
  cdbstdg - Primary database
    cdbst   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS   (status updated 7 seconds ago)

-- StandBy (Now Primary)

sqlplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NSCDB1                         READ WRITE NO
         4 NSCDB2                         READ WRITE NO
         5 NSCDB3                         READ WRITE NO

alter session set container=NSCDB1;

SQL> select count(*) from dr.teste;

  COUNT(*)
----------
        21

        
--> Switching Back
odasys12:

dgmgrl sys/welcome1

DGMGRL> show configuration;

Configuration - cdbst_config

  Protection Mode: MaxAvailability
  Members:
  cdbstdg - Primary database
    cdbst   - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS   (status updated 57 seconds ago)

DGMGRL> validate database cdbstdg;

  Database Role:    Primary database

  Ready for Switchover:  Yes

  Flashback Database Status:
    cdbstdg:  Off

DGMGRL> switchover to cdbst;
Performing switchover NOW, please wait...
Operation requires a connection to instance "cdbst" on database "cdbst"
Connecting to instance "cdbst"...
Connected as SYSDBA.
New primary database "cdbst" is opening...
Oracle Clusterware is restarting database "cdbstdg" ...
Switchover succeeded, new primary is "cdbst"


DGMGRL> show configuration

Configuration - cdbst_config

  Protection Mode: MaxAvailability
  Members:
  cdbst   - Primary database
    cdbstdg - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS   (status updated 11 seconds ago)

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NSCDB1                         READ WRITE NO
         4 NSCDB2                         READ WRITE NO
         5 NSCDB3                         READ WRITE NO

Migrate RAC 1 Node NON-CDB to RAC 1 Node CDB

Rac 1 Node:

nr1cdb1 - OK
nr1cdb2 - OK

Container: cdbr1

[oracle@odasys11:/home/oracle]srvctl config database -d nr1cdb1
Database unique name: nr1cdb1
Database name: nr1cdb1
Oracle home: /u01/app/oracle/product/12.1.0.2/dbhome_1
Oracle user: oracle
Spfile: +DATA/NR1CDB1/PARAMETERFILE/spfile.843.942944503
Password file: +DATA/NR1CDB1/PASSWORD/pwdnr1cdb1.1067.942943723
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups: DATA,REDO
Mount point paths:
Services: nr1cdb1_racone
Type: RACOneNode
Online relocation timeout: 30
Instance name prefix: nr1cdb1
Candidate servers: odasys11,odasys12
OSDBA group: dba
OSOPER group: racoper
Database instances:
Database is administrator managed

1.) Clear Shutdown on NON-CDB

shut immediate;
startup open read only;
select open_mode from v$database;

2.) Describe

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

shut immediate
exit

. oraenv
cdbr1_1

sqlplus / as sysdba

set serveroutput on
 
DECLARE
   compatible BOOLEAN := FALSE;
BEGIN  
   compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/home/oracle/pdbs/nr1cdb1.xml', pdb_name=>'nr1cdb1');
   if compatible then
     DBMS_OUTPUT.PUT_LINE('The Pluggable database is Compatible !!!');
   else 
     DBMS_OUTPUT.PUT_LINE('ERROR - The Pluggable database is not compatible !!!');
   end if;
END;
/

Note: In case of issues:

col cause for a10
col name for a10
col message for a35 word_wrapped
select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='nrccdb1';

4.) Connect into the CDB Database, if not connected: cdbst

. oraenv
cdbr1_1

sqlplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

         
5.) Create the new PDB:

CREATE PLUGGABLE DATABASE nr1cdb1 USING '/home/oracle/pdbs/nr1cdb1.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 NR1CDB1                        MOUNTED

6.) Catalog

alter session set container=NR1CDB1;    

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NR1CDB1                        MOUNTED

@?/rdbms/admin/noncdb_to_pdb.sql         

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NR1CDB1                        MOUNTED


SQL> alter database open;

Database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NR1CDB1                        READ WRITE NO
         
SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES;

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
USERS                          +DATA/NR1CDB1/DATAFILE/users.730.942943793
SYSAUX                         +DATA/NR1CDB1/DATAFILE/sysaux.673.942943779
SYSTEM                         +DATA/NR1CDB1/DATAFILE/system.1122.942943773

7.) Droping the OLD UNDO

as grid user:

[grid@odasys12:/home/grid]asmcmd lsof | grep -i NR1CDB1
cdbr1    cdbr1_1        +DATA/NR1CDB1/DATAFILE/sysaux.673.942943779                                                   
cdbr1    cdbr1_1        +DATA/NR1CDB1/DATAFILE/system.1122.942943773                                                  
cdbr1    cdbr1_1        +DATA/NR1CDB1/DATAFILE/users.730.942943793

--> If is not in use you can remove the file

[grid@odasys12:/home/grid]asmcmd
ASMCMD> cd  +DATA/NR1CDB1/DATAFILE/

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    SYSAUX.673.942943779
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    SYSTEM.1122.942943773
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    UNDOTBS1.781.942943781
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    UNDOTBS2.995.942943791
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    USERS.730.942943793

rm UNDOTBS1.781.942943781
rm UNDOTBS2.995.942943791

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    SYSAUX.673.942943779
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    SYSTEM.1122.942943773
DATAFILE  MIRROR  COARSE   MAY 03 15:00:00  Y    USERS.730.942943793

8.) Remove the Service from the Cluster

. oraenv

nr1cdb1_1

[oracle@odasys11:/home/oracle]srvctl remove database -d  nr1cdb1
Remove the database nr1cdb1? (y/[n]) y

9) Checking the service inside of the CDB

. oraenv

cdbr1_1

sqlplus / as sysdba

col NETWORK_NAME format a20
col NAME format a20
select name, NETWORK_NAME, PDB from v$services;

NAME                 NETWORK_NAME         PDB
-------------------- -------------------- ------------------------------
nr1cdb1              nr1cdb1              NR1CDB1
cdbr1_racone         cdbr1_racone         CDB$ROOT
cdbr1XDB             cdbr1XDB             CDB$ROOT
cdbr1                cdbr1                CDB$ROOT
SYS$BACKGROUND                            CDB$ROOT
SYS$USERS                                 CDB$ROOT

alter pluggable database all save state;

[grid@odasys11:/home/grid]lsnrctl status listener | grep nr1cdb1
Service "nr1cdb1" has 1 instance(s).

10.) Check ODA repository :

oakcli show databases | grep -i nr1cdb1

cat /etc/oratab | grep -i nr1cdb1

11.) Cleaning Files both nodes:

cd /u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
ls -ltr | grep -i nr1cdb1

-rw-r----- 1 oracle oinstall       41 May  2 17:02 initnr1cdb1_1.ora
-rw-rw---- 1 oracle asmadmin     1544 May  3 15:02 hc_nr1cdb1_1.dat
-rw-rw---- 1 oracle asmadmin   524288 May  3 15:02 id_nr1cdb1_1.dat

rm initnr1cdb1_1.ora hc_nr1cdb1_1.dat id_nr1cdb1_1.dat
rm initnr1cdb1_2.ora

12.) TNS

NR1CDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys1-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = nr1cdb1)
    )
  )
  
13.) Connection Test

from both nodes

sqlplus system/welcome1@NR1CDB1

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 15:22:52 2017

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

Last Successful login time: Tue May 02 2017 12:55:23 +02:00

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


INSTANCE_NAME
----------------
cdbr1_1

14.) Testing thye failover:

as oracle:

srvctl relocate database -d cdbr1 -n odasys12

sqlplus sys/welcome1@NR1CDB1 as sysdba

INSTANCE_NAME
----------------
cdbr1_2

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NR1CDB1                        READ WRITE NO

Note: If at the very first time the  failover for the  PDB is in MOUNT state,
is needed execute a manual failover with srvctl relocate database and
execute:
sqlplus / as sysdba
alter pluggable database <PDB> open;
alter pluggable database <PDB> save state;
on the next time the PDB will be opened as READ WRITE;

srvctl relocate database -d cdbr1 -n odasys11

sqlplus sys/welcome1@NR1CDB1 as sysdba

INSTANCE_NAME
----------------
cdbr1_1

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NR1CDB1                        READ WRITE NO


Migrate RAC NON-CDB to RAC CDB

RAC --> nrccdb1
RAC --> nrccdb2

***** 1.) Check the Config

[oracle@odasys11:/home/oracle]srvctl config database -d nrccdb1
Database unique name: nrccdb1
Database name: nrccdb1
Oracle home: /u01/app/oracle/product/12.1.0.2/dbhome_1
Oracle user: oracle
Spfile: +DATA/NRCCDB1/PARAMETERFILE/spfile.1064.942947307
Password file: +DATA/NRCCDB1/PASSWORD/pwdnrccdb1.1004.942946507
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools:
Disk Groups: DATA,REDO
Mount point paths:
Services:
Type: RAC
Start concurrency:
Stop concurrency:
OSDBA group: dba
OSOPER group: racoper
Database instances: nrccdb11,nrccdb12
Configured nodes: odasys11,odasys12
Database is administrator managed

***** 2.) Stop Node 2

srvctl stop instance -i nrccdb12 -d nrccdb1

***** 3.) Restart Node 1 

. oraenv
nrccdb11

shut immediate;
startup open read only;
select open_mode from v$database;

***** 4.) Describe and Compatibility

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

shut immediate;
exit;

. oraenv
cdbtst11

sqlplus / as sysdba

set serveroutput on
 
DECLARE
   compatible BOOLEAN := FALSE;
BEGIN  
   compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/home/oracle/pdbs/nrccdb1.xml', pdb_name=>'nrccdb1');
   if compatible then
     DBMS_OUTPUT.PUT_LINE('The Pluggable database is Compatible !!!');
   else 
     DBMS_OUTPUT.PUT_LINE('ERROR - The Pluggable database is not compatible !!!');
   end if;
END;
/

Note: In case of issues:

col cause for a10
col name for a10
col message for a35 word_wrapped
select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='nrccdb1';

***** 6.) Connect into the CDB Database, if not connected: cdbtst1

sqlplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

         
***** 7.) Create the new PDB:

CREATE PLUGGABLE DATABASE nrccdb1 USING '/home/oracle/pdbs/nrccdb1.xml'  NOCOPY TEMPFILE REUSE;         

Pluggable database created.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NRCCDB1                        MOUNTED


***** 8.) Catalog

alter session set container=NRCCDB1;    

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NRCCDB1                        MOUNTED


select INST_ID,CON_ID,NAME,OPEN_MODE, open_time from gv$pdbs;

   INST_ID     CON_ID NAME                 OPEN_MODE  OPEN_TIME
---------- ---------- -------------------- ---------- ---------------------------------------------------------------------------
         1          3 NRCCDB1              MOUNTED    03-MAY-17 10.52.18.840 AM +02:00
         2          3 NRCCDB1              MOUNTED

@?/rdbms/admin/noncdb_to_pdb.sql         

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NRCCDB1                        MOUNTED


SQL> alter database open;

Database altered.

select INST_ID,CON_ID,NAME,OPEN_MODE, open_time from gv$pdbs;

   INST_ID     CON_ID NAME                 OPEN_MODE  OPEN_TIME
---------- ---------- -------------------- ---------- ---------------------------------------------------------------------------
         1          3 NRCCDB1              READ WRITE 03-MAY-17 11.37.34.288 AM +02:00
         2          3 NRCCDB1              MOUNTED


SQL> select instance_name from gv$instance;

INSTANCE_NAME
----------------
cdbtst11
cdbtst12
         
alter pluggable database open instances=('cdbtst12');

SQL> select INST_ID,CON_ID,NAME,OPEN_MODE, open_time from gv$pdbs;

   INST_ID     CON_ID NAME                 OPEN_MODE  OPEN_TIME
---------- ---------- -------------------- ---------- ---------------------------------------------------------------------------
         1          3 NRCCDB1              READ WRITE 03-MAY-17 11.37.34.288 AM +02:00
         2          3 NRCCDB1              READ WRITE 03-MAY-17 11.45.45.375 AM +02:00

SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES;

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
USERS                          +DATA/NRCCDB1/DATAFILE/users.1065.942946573
SYSAUX                         +DATA/NRCCDB1/DATAFILE/sysaux.857.942946559
SYSTEM                         +DATA/NRCCDB1/DATAFILE/system.782.942946555


***** 9.) Droping the OLD UNDO

as grid user:

asmcmd lsof | grep -i NRCCDB1
cdbtst1  cdbtst11       +DATA/NRCCDB1/DATAFILE/sysaux.857.942946559                                                   
cdbtst1  cdbtst11       +DATA/NRCCDB1/DATAFILE/system.782.942946555                                                   
cdbtst1  cdbtst11       +DATA/NRCCDB1/DATAFILE/users.1065.942946573  

--> If is not in use you can remove the file

[grid@odasys12:/home/grid]asmcmd
ASMCMD> cd +DATA/NRCCDB1/DATAFILE/

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 03 10:00:00  Y    UNDOTBS1.994.942946563
DATAFILE  MIRROR  COARSE   MAY 03 10:00:00  Y    UNDOTBS2.874.942946573
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    SYSAUX.857.942946559
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    SYSTEM.782.942946555
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    USERS.1065.942946573


ASMCMD> rm UNDOTBS1.994.942946563
ASMCMD> rm UNDOTBS2.874.942946573

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    SYSAUX.857.942946559
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    SYSTEM.782.942946555
DATAFILE  MIRROR  COARSE   MAY 03 11:00:00  Y    USERS.1065.942946573


***** 10.) Remove the Service from the Cluster

. oraenv

nrccdb11

[oracle@odasys12:/home/oracle/pdbs]srvctl remove database -d nrccdb1
Remove the database nrccdb1? (y/[n]) y

***** 11) Checking the service inside of the CDB

. oraenv

cdbtst11

sqlplus / as sysdba

col NETWORK_NAME format a20
col NAME format a20
select name, NETWORK_NAME, PDB from v$services;

NAME                           NETWORK_NAME         PDB
------------------------------ -------------------- ------------------------------
nscdb1                         nscdb1               NSCDB1
cdbstXDB                       cdbstXDB             CDB$ROOT
cdbst                          cdbst                CDB$ROOT
SYS$BACKGROUND                                      CDB$ROOT
SYS$USERS                                           CDB$ROOT

[oracle@odasys11:/home/oracle]lsnrctl status listener | grep nrccdb1
Service "nrccdb1" has 1 instance(s).

[oracle@odasys11:/home/oracle]tnsping nrccdb1

TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 03-MAY-2017 11:53:46

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

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


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = odasys1-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = nrccdb1)))
OK (10 msec)

[oracle@odasys11:/home/oracle]sqlplus sys/welcome1@nrccdb1 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 11:55:05 2017

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


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


INSTANCE_NAME
----------------
cdbtst11

[oracle@odasys12:/u01/app/oracle/product/12.1.0.2/dbhome_1/dbs]sqlplus sys/welcome1@nrccdb1 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 11:55:41 2017

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


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


INSTANCE_NAME
----------------
cdbtst12

Note: According with MOS 1998112.1, is not a good practice use the PDB Name as a service name to connect,
so lets create a new service to be used:

. oraenv
cdbtst11

srvctl add service -database cdbtst1 -pdb NRCCDB1 -s pdb_NRCCDB1 -preferred "cdbtst11,cdbtst12"
srvctl config service -db cdbtst1 -service pdb_NRCCDB1
srvctl start service -db cdbtst1 -service pdb_NRCCDB1

sqlplus / as sysdba
select name, NETWORK_NAME, PDB from v$services;

alter pluggable database all save state;

alter session set container=NRCCDB1;

NAME                 NETWORK_NAME         PDB
-------------------- -------------------- ------------------------------
pdb_NRCCDB1          pdb_NRCCDB1          NRCCDB1
nrccdb1              nrccdb1              NRCCDB1



***** 12.) Change the TNSNAMES Entry both Nodes

cd /u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin
vi tnsnames.ora

NRCCDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys1-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdb_NRCCDB1)
    )
  )

from node1:
sqlplus system/welcome1@NRCCDB1

from node2:
sqlplus system/welcome1@NRCCDB1

***** 13.) Check ODA repository :

oakcli show databases | grep -i NRCCDB1


***** 14.) Clean ORATAB both nodes
cat /etc/oratab | grep -i NRCCDB1

***** 15.) Cleaning Files both nodes:

cd /u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
ls -ltr | grep -i NRCCDB1

-rw-r----- 1 oracle oinstall       41 May  2 17:49 initnrccdb11.ora
-rw-rw---- 1 oracle asmadmin   524288 May  3 10:48 id_nrccdb11.dat
-rw-rw---- 1 oracle asmadmin     1544 May  3 10:49 hc_nrccdb11.dat

rm initnrccdb11.ora id_nrccdb11.dat hc_nrccdb11.dat
rm initnrccdb12.ora hc_nrccdb12.dat id_nrccdb12.dat

Migrate NON-CDB to CDB

Standalone --> nscdb1
1.) Clear Shutdown on NON-CDB

shut immediate;
startup open read only;
select open_mode from v$database;

2.) Describe and Compatibility

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

shut immediate;
exit

. oraenv
cdbst

sqlplus / as sysdba

set serveroutput on
 
DECLARE
   compatible BOOLEAN := FALSE;
BEGIN  
   compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/home/oracle/pdbs/nscdb1.xml', pdb_name=>'nscdb1');
   if compatible then
     DBMS_OUTPUT.PUT_LINE('The Pluggable database is Compatible !!!');
   else 
     DBMS_OUTPUT.PUT_LINE('ERROR - The Pluggable database is not compatible !!!');
   end if;
END;
/

Note: In case of issues:

col cause for a10
col name for a10
col message for a35 word_wrapped
select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='nscdb1';


4.) Connect into the CDB Database, if not connected: cdbst

. oraenv
cdbst

sqlplus / as sysdba

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

         
5.) Create the new PDB:

CREATE PLUGGABLE DATABASE nscdb1 USING '/home/oracle/pdbs/nscdb1.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 NSCDB1                         MOUNTED

6.) Catalog

alter session set container=NSCDB1;    

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         MOUNTED

@?/rdbms/admin/noncdb_to_pdb.sql         

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         MOUNTED

SQL> alter database open;

Database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO
         
  1* SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES
SQL> /

TABLESPACE_NAME                FILE_NAME
------------------------------ --------------------------------------------------
USERS                          +DATA/NSCDB1/DATAFILE/users.502.942942475
SYSAUX                         +DATA/NSCDB1/DATAFILE/sysaux.586.942942461
SYSTEM                         +DATA/NSCDB1/DATAFILE/system.325.942942455

7.) Droping the OLD UNDO

as grid user:

[grid@odasys12:/home/grid]asmcmd lsof | grep -i NSCDB1
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/sysaux.586.942942461
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/system.325.942942455
cdbst     cdbst          +DATA/NSCDB1/DATAFILE/users.502.942942475

--> If is not in use you can remove the file

[grid@odasys12:/home/grid]asmcmd
ASMCMD> cd +DATA/NSCDB1/DATAFILE/

ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 02 18:00:00  Y    UNDOTBS1.587.942942465
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSAUX.586.942942461
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSTEM.325.942942455
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    USERS.502.942942475

ASMCMD> rm UNDOTBS1.587.942942465
ASMCMD> ls -ltr
WARNING:option 'r' is deprecated for 'ls'
please use 'reverse'

Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSAUX.586.942942461
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    SYSTEM.325.942942455
DATAFILE  MIRROR  COARSE   MAY 02 19:00:00  Y    USERS.502.942942475

8.) Remove the Service from the Cluster

. oraenv

nscdb1

[oracle@odasys12:/home/oracle/pdbs]srvctl remove database -d nscdb1
Remove the database nscdb1? (y/[n]) y

9) Checking the service inside of the CDB

. oraenv

cdbst

sqlplus / as sysdba

col NETWORK_NAME format a20
col NAME format a20
select name, NETWORK_NAME, PDB from v$services;

NAME                           NETWORK_NAME         PDB
------------------------------ -------------------- ------------------------------
nscdb1                         nscdb1               NSCDB1
cdbstXDB                       cdbstXDB             CDB$ROOT
cdbst                          cdbst                CDB$ROOT
SYS$BACKGROUND                                      CDB$ROOT
SYS$USERS                                           CDB$ROOT

[grid@odasys12:/home/grid]lsnrctl status listener | grep nscdb1
Service "nscdb1" has 1 instance(s).

10.) Check ODA repository :

oakcli show databases | grep -i nscdb1

cat /etc/oratab | grep -i nscdb1

11.) Cleaning Files:

cd /u01/app/oracle/product/12.1.0.2/dbhome_1/dbs
ls -ltr | grep -i nscdb1

-rw-r----- 1 oracle oinstall     7680 May  2 16:38 orapwnscdb1
-rw-r----- 1 oracle oinstall       39 May  2 16:40 initnscdb1.ora
-rw-rw---- 1 oracle asmadmin     1544 May  2 18:40 hc_nscdb1.dat

rm orapwnscdb1 initnscdb1.ora hc_nscdb1.dat

12.) TNS

NSCDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = odasys12.bgl.lu)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = nscdb1)
    )
  )

  
13.) Connection Test
sqlplus / as sysdba
  
INSTANCE_NAME
----------------
cdbst

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 NSCDB1                         READ WRITE NO


alter pluggable database all save state;

SQL>  alter session set container=NSCDB1;

Session altered.

SQL>

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO
SQL> create user conntest identified by x;

User created.

SQL> grant connect to conntest;

Grant succeeded.

exit;

[oracle@odasys12:/u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin]sqlplus conntest/x@NSCDB1

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 09:29:10 2017

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


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

exit

[oracle@odasys12:/u01/app/oracle/product/12.1.0.2/dbhome_1/network/admin]sqlplus sys/welcome1@NSCDB1 as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Wed May 3 09:30:15 2017

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


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


INSTANCE_NAME
----------------
cdbst

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 NSCDB1                         READ WRITE NO

LogMiner – Pluggable Database

Log Miner on Multitenant 12c

The following steps will show you some differences to use LogMiner with Pluggable
databases. At this time i will use Flat File for the dictionary.

References:
http://docs.oracle.com/database
/121/SUTIL/GUID-3417B738-374C-4EE3-B15C-3A66E01AE2B5.htm#SUTIL019

--> PDBS:
select * 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

--> Archive Status
--> The time below will be used on DBMS_LOGMNR.start_logmnr

08:42:41 SQL> archive log list;

Database log mode          Archive Mode
Automatic archival             Enabled
Archive destination            /data01/CDB/archives
Oldest online log sequence     167
Next log sequence to archive   169
Current log sequence           169

--> Simulating some operations on PDBs

alter session set container=pdb1;

select name, open_mode from v$pdbs;

NAME                                     OPEN_MODE
---------------------------------------- ----------
PDB1                                     READ WRITE

create table test.test_pdb1
(num number,
 text varchar2(10))
tablespace TS_PDB1;

insert into test.test_pdb1 values (1,'test 1');
insert into test.test_pdb1 values (2,'test 2');
insert into test.test_pdb1 values (3,'test 3');
insert into test.test_pdb1 values (4,'test 4');

commit;

delete test.test_pdb1 where num = 2;
commit;

update test.test_pdb1 set text='UPDATE 3' where num=3;
commit;

select * from test.test_pdb1;

                 NUM TEXT
-------------------- ----------
                   1 test 1
                   3 UPDATE 3
                   4 test 4


alter session set container=pdb3;
 
select name, open_mode from v$pdbs;

NAME                                     OPEN_MODE
---------------------------------------- ----------
PDB3                                     READ WRITE

create table test.test_pdb3
(num number,
text varchar2(10))
tablespace users;

insert into test.test_pdb3 values (1,'test 1');
insert into test.test_pdb3 values (2,'test 2');
insert into test.test_pdb3 values (3,'test 3');
insert into test.test_pdb3 values (4,'test 4');
commit;

update test.test_pdb3 set text='ERROR';
commit;

select * from test.test_pdb3;

                 NUM TEXT
-------------------- ----------
                   1 ERROR
                   2 ERROR
                   3 ERROR
                   4 ERROR

-------------------------------- STARTING HERE ---------------------------------

alter session set container=cdb$root;

select name, open_mode from v$pdbs;

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

alter system switch logfile;
--> The time below will be used on DBMS_LOGMNR.start_logmnr

09:04:13 SQL> archive log list;

Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /data01/CDB/archives
Oldest online log sequence     173
Next log sequence to archive   175
Current log sequence           175

--> At this time we will work with archived logs below:

/data01/CDB/archives/1_168_900491294.dbf
/data01/CDB/archives/1_169_900491294.dbf
/data01/CDB/archives/1_170_900491294.dbf
/data01/CDB/archives/1_171_900491294.dbf
/data01/CDB/archives/1_172_900491294.dbf
/data01/CDB/archives/1_173_900491294.dbf
/data01/CDB/archives/1_174_900491294.dbf

Note:

http://docs.oracle.com/database/121/SUTIL/GUID-EF8A932F-7E71-4995-893E-E583B90007C2.htm#SUTIL4227

Using a Flat File Dictionary in a CDB

"You cannot take a dictionary snapshot for an entire CDB in a single flat file. 
You must be connected to a distinct PDB, and can take a snapshot of only that 
PDB in a flat file. Thus, when using a flat file dictionary, you can only mine 
the redo logs for the changes associated with the PDB whose data dictionary is 
contained within the flat file."

1.) Creating the dictionary PDB1

alter session set container=pdb1;
create directory scripts as '/home/oracle/dba/scripts';
exec dbms_logmnr_d.build('minerPDB1.dic', 'SCRIPTS', dbms_logmnr_d.store_in_flat_file);

!ls -ltr /home/oracle/dba/scripts/minerPDB1.dic
-rw-r--r-- 1 oracle oinstall 44592353 May 17 10:14 /home/oracle/dba/scripts/minerPDB1.dic

2.) Creating the Dictionary PDB3

alter session set container=pdb3;
create directory scripts as '/home/oracle/dba/scripts';
exec dbms_logmnr_d.build('minerPDB3.dic', 'SCRIPTS', dbms_logmnr_d.store_in_flat_file);

!ls -ltr /home/oracle/dba/scripts/minerPDB3.dic
-rw-r--r-- 1 oracle oinstall 44638808 May 17 10:16 /home/oracle/dba/scripts/minerPDB3.dic

3.) Including Archived Logs to be mined for PDB1:

exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_168_900491294.dbf',Options=>dbms_logmnr.NEW);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_169_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_170_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_171_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_172_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_173_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_174_900491294.dbf',Options=>dbms_logmnr.ADDFILE);

4.) Starting the miner for PDB1:

BEGIN
DBMS_LOGMNR.start_logmnr (
dictfilename => '/home/oracle/dba/scripts/minerPDB1.dic',
starttime => TO_DATE('17-MAY-2016 08:42:41', 'DD-MON-YYYY HH:MI:SS'),
endtime => TO_DATE('17-MAY-2016 09:04:13', 'DD-MON-YYYY HH:MI:SS'),
options => DBMS_LOGMNR.COMMITTED_DATA_ONLY);
END;
/

5.) Collecting Information for PDB1

desc v$logmnr_contents

select count(*), TABLE_NAME
FROM v$logmnr_contents
GROUP BY TABLE_NAME;

select count(*) from v$logmnr_contents where table_name like '%TEST_PDB%';

            COUNT(*)
--------------------
                   7


col operation format a10
col sql_redo format a80
col sql_undo format a80
col username format a10

select username, operation, sql_redo, sql_undo 
from  v$logmnr_contents
where table_name ='TEST_PDB1';
                   
LogMiner1
                   
6.) Finishing for PDB1

exec DBMS_LOGMNR.END_LOGMNR;

7.) Including Archived Logs to be mined for PDB3:

exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_168_900491294.dbf',Options=>dbms_logmnr.NEW);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_169_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_170_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_171_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_172_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_173_900491294.dbf',Options=>dbms_logmnr.ADDFILE);
exec dbms_logmnr.add_logfile(LogFileName=>'/data01/CDB/archives/1_174_900491294.dbf',Options=>dbms_logmnr.ADDFILE);

8.) Starting the miner for PDB3:

BEGIN
DBMS_LOGMNR.start_logmnr (
dictfilename => '/home/oracle/dba/scripts/minerPDB3.dic',
starttime => TO_DATE('17-MAY-2016 08:42:41', 'DD-MON-YYYY HH:MI:SS'),
endtime => TO_DATE('17-MAY-2016 09:04:13', 'DD-MON-YYYY HH:MI:SS'),
options => DBMS_LOGMNR.COMMITTED_DATA_ONLY);
END;
/

9.) Collection Information for PDB3

desc v$logmnr_contents

select count(*), TABLE_NAME
FROM v$logmnr_contents
GROUP BY TABLE_NAME;

select count(*) from v$logmnr_contents where table_name like '%TEST_PDB%';

            COUNT(*)
--------------------
                   9


col operation format a10
col sql_redo format a80
col sql_undo format a80
col username format a10

select username, operation, sql_redo, sql_undo 
from  v$logmnr_contents
where table_name ='TEST_PDB3';

LogMiner2
                   
10.) Finishing for PDB3

exec DBMS_LOGMNR.END_LOGMNR;

Online Move Datafile

Oracle Database 12c

--> Here i want move the datafiles from all PDBs to 
    the same location where the datafiles for the CDB are placed:

==> CDB:

  1* select file_name from dba_data_files
10:21:48 SQL> /

FILE_NAME
-----------------------------------------------
/data03/CDB/users01.dbf
/data03/CDB/undotbs01.dbf
/data03/CDB/system01.dbf
/data03/CDB/sysaux01.dbf

4 rows selected.

==> PDB:

10:22:17 SQL> select name, open_mode from v$pdbs;

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

==> Creating directories:

cd /data03/CDB

mkdir PDB1
mkdir PDB3

1.) Connecting on the PDB1;

alter session set container=PDB1;

10:27:25 SQL>  SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') pdb from dual;

PDB
----------
PDB1

10:28:01 SQL> select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
/oracle/oradata/CDB/pdb1/system01.dbf
/oracle/oradata/CDB/pdb1/sysaux01.dbf
/oracle/oradata/CDB/pdb1/ts_pdb1.dbf


2.) Moving datafiles:

alter database move datafile '/oracle/oradata/CDB/pdb1/system01.dbf' to '/data03/CDB/PDB1/system01.dbf';
alter database move datafile '/oracle/oradata/CDB/pdb1/sysaux01.dbf' to '/data03/CDB/PDB1/sysaux01.dbf';
alter database move datafile '/oracle/oradata/CDB/pdb1/ts_pdb1.dbf' to '/data03/CDB/PDB1/ts_pdb1.dbf';

3.) Checking:

10:30:34 SQL> select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
/data03/CDB/PDB1/sysaux01.dbf
/data03/CDB/PDB1/ts_pdb1.dbf
/data03/CDB/PDB1/system01.dbf

3 rows selected.

10:30:42 SQL> !ls -ltr /oracle/oradata/CDB/pdb1/
total 520
-rw-r----- 1 oracle oinstall 20979712 Mar  7 12:49 pdbseed_temp012016-01-07_08-28-45-AM.dbf

4.) Connecting on the PDB3;

alter session set container=PDB3;
 
10:32:13 SQL>  SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') pdb from dual;

PDB
----------
PDB3

10:32:26 SQL> select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
+DATA/CDB/PDB3/system01.dbf
+DATA/CDB/PDB3/sysaux01.dbf

5.) Moving datafiles, on this case from ASM:

alter database move datafile '+DATA/CDB/PDB3/system01.dbf' to '/data03/CDB/PDB3/system01.dbf';
alter database move datafile '+DATA/CDB/PDB3/sysaux01.dbf' to '/data03/CDB/PDB3/sysaux01.dbf';

6.) Checking:

10:35:22 SQL> select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
/data03/CDB/PDB3/system01.dbf
/data03/CDB/PDB3/sysaux01.dbf