9.7.5.4 Update the Test Master Database

You have two options for refreshing the test master database:

  • Allow Oracle Data Guard to refresh the test master database

    If the Oracle Data Guard replica has been used as a test master database for only a short period of time and you have all the redo generated during this time in archive logs on disk at the source database, then you can enable redo shipping and start redo apply. The test master database will use regular Oracle Data Guard protocols to retrieve archive logs and apply the logs until it is caught up with the primary database. Once the Oracle Data Guard replica is as current as you need it to be, disable redo shipping, stop redo apply and repeat the test master and snapshot creation cycle described in Setting Up the Test Master and Creating Snapshots.

    This option has the benefit of being able to stop redo apply at some intermediate point rather than bringing the test master database totally current.

    To let Oracle Data Guard refresh the standby, enable log shipping to the standby and redo apply on the standby:

    DGMGRL> edit database TESTMASTER set property logshipping=ON; 
    Property "logshipping" updated 
    DGMGRL> edit database TESTMASTER set state=apply-on; 
    Succeeded
    
  • Use RMAN RECOVER...FROM SERVICE to roll forward the test master database

    If the Oracle Data Guard replica has been used as a test master database for a long period of time or if you no longer have the redo available on disk to enable Oracle Data Guard to automatically refresh the test master database, use RMAN to perform live incremental apply over the network.

    A major advantage to using this method is that no additional disk space is required. RMAN will bring changed blocks to the standby from the primary over the network and apply them directly. Also RMAN greatly simplifies the process by determining which blocks need to be retrieved based on the SCN of the data files on the test master. With this method you cannot recover to an intermediate point in time; the refresh will bring the test master database current with the primary. For more information on this method refer to Performing RMAN Recovery: Advanced Scenarios in Oracle Database Backup and Recovery User’s Guide.

To refresh the test master database using RMAN Network Incrementals:

  1. Prepare Oracle Net Services for the RMAN connections.

    These steps need to be performed only once.

    1. Create a listener.ora entry for the test master database (the Oracle Data Guard replica).

      The listener entry allows RMAN to connect to the target using the SID because the service is not started when the database is opened in NOMOUNT mode. The following is an example of the entry:

      SID_LIST_LISTENER = 
        (SID_LIST =   
          (SID_DESC = 
            (SID_NAME = TESTMASTER1)
            (ORACLE_HOME = /u01/app/oracle/product/12.1.0.2/dbhome_1)
          )
        )
      
    2. Reload the listener to pick up the changes to the listener.ora.
       $ lsnrctl reload listener 
    3. Create a TNS entry on the test master environment pointing to the SID of the local test master instance.
      The entry should use the local host name rather than the SCAN name to ensure the connection request goes to the correct host.
      TESTMASTER1 = 
        (DESCRIPTION = 
          (ADDRESS = (PROTOCOL = TCP)(HOST = standbydb01.example.com)(PORT = 1521))
          (CONNECT_DATA = 
            (SERVER = DEDICATED) 
            (SID = TESTMASTER1) 
            (UR=A) 
          ) 
        ) 
      
  2. Connect via RMAN to the test master database and save the CURRENT_SCN for later.
    This value will be used to determine if newly created files since the last refresh need to be restored from the source database.
    RMAN> select current_scn from v$database;
    CURRENT_SCN# 
    ------------------ 
              17081990 
  3. List the names and group identifiers of the redo log files.
    The names of the online redo log files and standby redo log files of the Oracle Data Guard replica might be required in a later step.
    RMAN> SELECT type, group#, member FROM v$logfile;
  4. Refresh the standby control file of the Oracle Data Guard replica from the source database to make the control file current.
    1. Reconnect to the Oracle Data Guard replica as the RMAN target.
    2. Restart the target in NOMOUNT mode.
      RMAN> startup nomount force;
    3. Restore the standby control file by using the control file on the source database.

      The following example restores the control file on the Oracle Data Guard replica by using the database control file from SOURCEMASTER, the source database.

      RMAN> RESTORE STANDBY CONTROLFILE FROM SERVICE SOURCEMASTER;
      
    4. Mount the Oracle Data Guard replica.
      RMAN> ALTER DATABASE MOUNT;
  5. Update the names of the data files and the temp files in the standby control file.

    If you are not using an RMAN catalog, the names of files in the standby control file are the names that were used in the source database, not the standby.

    Use the CATALOG command and the SWITCH command to update all the data file names. The SWITCH command will be used after restoring any newly created files from the source database in step 7.

    In the following example, +DATA/TESTMASTER/DATAFILE/ is the location of the data files on the Oracle Data Guard replica. All data files must be stored in this location.

    RMAN> CATALOG START WITH '+DATA/TESTMASTER/DATAFILE/';
    
  6. Determine if new files were added that need to be restored from the source database.

    Use the CURRENT_SCN from step 2.

    RMAN> SELECT file# FROM v$datafile WHERE creation_change# >= 17081990;
     FILE#
    ---------- 
             9 
            10 
    
  7. If there are files returned by the previous query, restore those data files from the source database.

    Run an RMAN command block similar to the following using the list of FILE# values returned by the previous step. If no FILE# values were returned, then skip this step.

    RMAN> run{ 
    2> set newname for database to '+DATA';
    3> restore datafile 9,10 from service SOURCEMASTER;
    4> } 
    
  8. If not using an RMAN catalog, rename the data files in the standby control file.

    Switch to the copies cataloged in step 5.

    RMAN> SWITCH DATABASE TO COPY;
    
  9. Update the names of the online redo logs and standby redo logs in the standby control file.
    Use one of the following methods:
    • Use the ALTER DATABASE CLEAR command to clear the log files in all redo log groups of the Oracle Data Guard replica. RMAN then recreates all the standby redo logs and the online redo log files.

      Note:

      Clearing log files is recommended only if the Oracle Data Guard replica does not have access to the online redo log files and standby redo log files of the source database. If the Oracle Data Guard replica has access to the redo log files of the source database and the redo log file names of the source database are OMF names, then the ALTER DATABASE command will delete log files on the source database.

      Also, the clearing of the log files will create new log files. Any existing log files are not used because the control file is not aware of those existing files. To conserve space, delete the existing log files from Oracle ASM prior to running the ALTER DATABASE CLEAR commands.

      The GROUP# column of the V$LOGFILE view queried in step 5 provides the redo log group identifiers of the log groups that must be cleared. Use separate ALTER DATABASE CLEAR commands to clear each redo log group.

      For example, the following command clears the redo log group with identifier 2.

      SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;
      
    • Use the ALTER DATABASE RENAME FILE command to rename the redo log files. Use a separate command to rename each log file listed in step 5.

      To rename log files, the STANDBY_FILE_MANAGEMENT initialization parameter must be set to MANUAL. Renaming log files is recommended when the number of online redo logs files and standby redo log files is the same in the source database and the Oracle Data Guard replica.

  10. Use RMAN RECOVER....FROM SERVICE to roll forward the data files to current state.
    No additional space is required for this operation. Note that this process can only bring the files totally current; it cannot bring the files to a previous point in time. Connect via RMAN to the Oracle Data Guard replica as target using the TNS entry created in step 3. The service specified should point to the primary.
    RMAN> recover database noredo from service SOURCEMASTER;
    
  11. Enable redo shipping to the Oracle Data Guard replica and start redo apply.
    This is necessary to update the control file with the blocks applied as part of step 10.
    DGMGRL> edit database TESTMASTER set property logshipping=ON;
    Property "logshipping" updated
    DGMGRL> edit database TESTMASTER set state=apply-on;
    Succeeded.
    
  12. After redo has been applied, repeat the process you used to convert the Oracle Data Guard replica into a test master database and then create Exadata database snapshots.
    Remember to once again disable log shipping and redo apply at the standby.