Scenario 7: Switchover from Source PDB to Target PDB

A switchover exchanges the source and target roles between the specified PDBs. This is generally a planned role transition, and, because both PDBs are online and accessible, there is no data loss. Switchovers are useful for load balancing and to facilitate planned maintenance operations. For the example DG PDB configuration, a switchover is used to faciliate adding PDB-level standby redo logs for the bos_sales PDB at the boston container database.

To add PDB-level SRLs to the current source PDB bos_sales, this PDB must first be placed in a target role. To do this, perform a switchover to the target PDB nyc_sales and then add PDB-level SRLs to the new standby PDB bos_sales.
DGMGRL> SWITCHOVER TO PLUGGABLE DATABASE nyc_sales AT NEWYORK; 
Verifying conditions for Switchover... 
  Source pluggable database is 'BOS_SALES' at database 'boston' 
Performing switchover NOW, please wait... 
  Closing pluggable database 'BOS_SALES'... 
  Switching 'BOS_SALES' to standby role... 
  Waiting for 'NYC_SALES' to recover all redo data... 
  Stopping recovery at 'NYC_SALES'... 
  Converting 'NYC_SALES' to primary role... 
  Opening new primary 'NYC_SALES'... 
  Waiting for redo data from new primary 'NYC_SALES'... 
  Starting recovery at new standby 'BOS_SALES'... 
Switchover succeeded, new primary is "NYC_SALES" 

DGMGRL> SHOW CONFIGURATION; 
Configuration - Boston 
  Protection Mode: MaxPerformance   
  Members: 
  boston - Primary database 
    newyork - Primary database in NewYork configuration 
Data Guard for PDB: Enabled in TARGET role 
Configuration Status: 
SUCCESS (status updated 29 seconds ago)
To create standby redo logs for PDB bos_sales, first stop redo apply:
DGMGRL> EDIT PLUGGABLE DATABASE bos_sales AT boston SET STATE='APPLY-OFF'; 
Succeeded. 
Then connect to the new target CDB boston as SYSDBA and issue the following SQL commands to add PDB-level SRLs:
SQL> ALTER SESSION SET CONTAINER=bos_sales; 
Session altered. 

SQL> ALTER DATABASE ADD STANDBY LOGFILE thread 1 
  2 group 4 ('$ORACLE_BASE/fast_recovery_area/BOSTON/onlinelog/standby_redo04.log') size 200M, 
  3 group 5 ('$ORACLE_BASE/fast_recovery_area/BOSTON/onlinelog/standby_redo05.log') size 200M, 
  4 group 6 ('$ORACLE_BASE/fast_recovery_area/BOSTON/onlinelog/standby_redo06.log') size 200M,   
  5 group 7 ('$ORACLE_BASE/fast_recovery_area/BOSTON/onlinelog/standby_redo07.log') size 200M; 
Database altered.
Use the VALIDATE PLUGGABLE DATABASE command to confirm successful creation of the PDB level standby redo logfiles:
DGMGRL> VALIDATE PLUGGABLE DATABASE bos_sales AT boston; 
   Ready for Switchover:      NO    
   Data Guard Role:           Physical Standby 
   Apply State:               Not Running 
   Standby Redo Log Files:    4 
   Source:                    NYC_SALES (con_id 3) at newyork
Finally, use DGMGRL to restart redo apply and check that the DG PDB configuration is now in a SUCCESS state and no longer lags the source PDB:
DGMGRL> EDIT PLUGGABLE DATABASE bos_sales AT boston SET STATE='APPLY-ON'; 
Succeeded. 

DGMGRL> SHOW CONFIGURATION; 
Configuration - Boston 
  Protection Mode: MaxPerformance   
  Members: 
  boston - Primary database   
    newyork - Primary database in NewYork configuration 
Data Guard for PDB: Enabled in TARGET role 
Configuration Status: SUCCESS (status updated 58 seconds ago) 

DGMGRL> SHOW PLUGGABLE DATABASE bos_sales AT boston; 
Pluggable database - BOS_SALES at boston 
  Data Guard Role: Physical Standby   
  Con_ID: 3 
  Source: con_id 3 at newyork 
  Transport Lag: (unknown) 
  Apply Lag: (unknown) 
  Intended State: APPLY-ON 
  Apply State: Running  
  Apply Instance: boston 
  Average Apply Rate: (unknown) 
  Real Time Query: OFF 
Pluggable Database Status: 
SUCCESS
Note that target PDB bos_sales has (unknown) transport lag and apply lag states. Connect to the source database newyork as SYSDBA and archive the current logfile a few times to initiate redo transport to the newly created standby redo logfiles:
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT; 
System altered. 

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT; 
System altered.
With redo now being shipped to and applied from the standby redo logfiles, the target PDB will become synchronized with the source PDB:
 DGMGRL> SHOW PLUGGABLE DATABASE bos_sales AT boston; 
Pluggable database - BOS_SALES at boston 
   Data Guard Role:        Physical Standby 
   Con_ID:                 3 
   Source:                 con_id 3 at newyork 
   Transport Lag:          0 seconds (computed 2 seconds ago) 
   Apply Lag:              0 seconds (computed 2 seconds ago) 
   Intended State:         APPLY-ON 
   Apply State:            Running 
   Apply Instance:         boston 
   Average Apply Rate:     27 KByte/s 
   Real Time Query:        OFF 
Pluggable Database Status: 
SUCCESS