Migrating the Database to Oracle ASM Using RMAN

The following procedure is intended to minimize database downtime. The steps differ slightly depending on whether you are migrating a primary or standby database. The procedure makes the same assumptions described in "Preparing to Migrate the Database to Oracle ASM Using RMAN". If you are not migrating the recovery area to Oracle ASM, then you must modify some steps, which are noted.

Note:

The following procedure switches between SQL*Plus and RMAN, so keep a terminal window open for each utility.

To migrate the database to Oracle ASM:

  1. Follow the steps in "Preparing to Migrate the Database to Oracle ASM Using RMAN".

  2. Restore or create a server parameter file in Oracle ASM storage.

    The steps depend on whether the database is using a server parameter file:

    • If the database is using a server parameter file, then restore it to the Oracle ASM disk group with the following commands, where sid is the SID of the instance:

      RMAN> STARTUP MOUNT;
      RMAN> RESTORE SPFILE TO '+DATA/spfilesid.ora';
      RMAN> SHUTDOWN IMMEDIATE;
      
    • If the database is not using a server parameter file, then create one in Oracle ASM. Run the CREATE SPFILE command in SQL*Plus as follows, where sid is the SID of the database:

      SQL> CREATE SPFILE='+DATA/spfilesid.ora' FROM PFILE='?/dbs/initsid.ora';
      
  3. Set Oracle Managed Files initialization parameters to Oracle ASM locations.

    Note:

    If you are not migrating the fast recovery area, then do not change the DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE initialization parameter settings. However, you must set DB_CREATE_ONLINE_LOG_DEST_n parameter to an Oracle ASM location for migration of the online redo logs.

    Set the DB_CREATE_FILE_DEST and optional DB_CREATE_ONLINE_LOG_DEST_n initialization parameters to Oracle ASM disk groups. If the database uses a recovery area, then change the recovery area location to the Oracle ASM disk group. Also, change the recovery area size.

    Run commands in SQL*Plus as shown in the following example. The example assumes that the size of the fast recovery area is 100 GB and specifies the disk group +FRA for the fast recovery area.

    SQL> STARTUP FORCE NOMOUNT;
    SQL> ALTER SYSTEM SET DB_CREATE_FILE_DEST='+DATA' SID='*';
    SQL> ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=100G SID='*';
    SQL> ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='+FRA' SID='*';
    
  4. Set the CONTROL_FILES initialization parameter to Oracle ASM locations.

    If you are migrating the fast recovery area, then enter the following commands in SQL*Plus to restart the database instance and set the control file locations to disk groups +DATA and +FRA:

    SQL> STARTUP FORCE NOMOUNT;
    SQL> ALTER SYSTEM SET CONTROL_FILES='+DATA','+FRA' SCOPE=SPFILE SID='*';
    

    If you are not migrating the fast recovery area, then enter the following commands in SQL*Plus to restart the database instance and set the control file locations to disk group +DATA:

    SQL> STARTUP FORCE NOMOUNT;
    SQL> ALTER SYSTEM SET CONTROL_FILES='+DATA','+DATA' SCOPE=SPFILE SID='*';
    
  5. Migrate the control file to Oracle ASM and mount the control file.

    Switch to the RMAN terminal to restore the control file. In the following example, original_cf_name is a control file name in the initialization parameter file before migration:

    RMAN> STARTUP FORCE NOMOUNT;
    RMAN> RESTORE CONTROLFILE FROM 'original_cf_name';
    RMAN> ALTER DATABASE MOUNT;
    
  6. Migrate the data files to Oracle ASM.

    Use RMAN to switch to the database copy that you created in step 5 "Back up the data files to the Oracle ASM disk group" in "Preparing to Migrate the Database to Oracle ASM Using RMAN". The switch renames all the data files to files on Oracle ASM disk groups. Afterward, recover the database. If incremental backups were taken, then RMAN applies them during recovery. For example, enter the following commands at the RMAN prompt:

    SWITCH DATABASE TO COPY;
    RUN
    {
      ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
      ALLOCATE CHANNEL dev2 DEVICE TYPE DISK;
      ALLOCATE CHANNEL dev3 DEVICE TYPE DISK;
      ALLOCATE CHANNEL dev4 DEVICE TYPE DISK;
      RECOVER DATABASE;
    }
    
  7. If the database uses block change tracking or Flashback Database, then enable these features.

    Note:

    If you are not migrating the recovery area, then you do not enable Flashback Database unless you had disabled it previously.

    For example, enter the following statements in SQL*Plus:

    SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA';
    SQL> ALTER DATABASE FLASHBACK ON;
    
  8. Place the database in its normal operation mode.

    The normal operational mode depends on whether the database is a primary or standby database:

    • If the database is a primary database, then open it as follows:

      SQL> ALTER DATABASE OPEN;
      
    • If the database is a standby database, then resume managed recovery mode as follows:

      SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
      
  9. Drop the tempfiles and re-create them in Oracle ASM.

    Use SQL*Plus to re-create the tempfiles. In the following example, the name of the tempfile in the original storage is tempfile_name. The name of the temporary tablespace is temp_tbs_name.

    SQL> ALTER DATABASE TEMPFILE 'tempfile_name' DROP;
    SQL> ALTER TABLESPACE temp_tbs_name ADD TEMPFILE;
    
  10. Migrate the online redo log files.

    If this is a primary database, then add new log group members in Oracle ASM and drop the old members. You can use the following PL/SQL script to migrate the online redo log groups into an Oracle ASM disk group. The PL/SQL script assumes that the Oracle Managed Files initialization parameters specified in step 3 "Set Oracle Managed Files initialization parameters to Oracle ASM locations" in "Migrating the Database to Oracle ASM Using RMAN" are set.

  11. Optionally, migrate backups and copies in the old fast recovery area to Oracle ASM as follows:

    1. If foreign archived logs exists in the recovery area, then you cannot migrate them to Oracle ASM. Run the following command at the RMAN prompt:

      RMAN> DELETE ARCHIVELOG ALL;
      
    2. Back up archived redo log files, backup sets, and data file copies to Oracle ASM. For example, run the following command at the RMAN prompt:

      RUN
      {
        ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
        ALLOCATE CHANNEL dev2 DEVICE TYPE DISK;
        ALLOCATE CHANNEL dev3 DEVICE TYPE DISK;
        ALLOCATE CHANNEL dev4 DEVICE TYPE DISK;
      
        BACKUP AS COPY ARCHIVELOG ALL DELETE INPUT;
        BACKUP BACKUPSET ALL DELETE INPUT;
        BACKUP AS COPY DATAFILECOPY ALL DELETE INPUT;
      }
      

Example 8-1 Migrating the online redo logs

SET SERVEROUTPUT ON;
DECLARE
   CURSOR rlc IS
      SELECT GROUP# GRP, THREAD# THR, BYTES, 'NO' SRL
      FROM   V$LOG
      UNION
      SELECT GROUP# GRP, THREAD# THR, BYTES, 'YES' SRL
      FROM   V$STANDBY_LOG
      ORDER BY 1;
   stmt     VARCHAR2(2048);
BEGIN
   FOR rlcRec IN rlc LOOP
      IF (rlcRec.srl = 'YES') THEN
         stmt := 'ALTER DATABASE ADD STANDBY LOGFILE THREAD ' ||
                 rlcRec.thr || ' SIZE ' || rlcRec.bytes;
         EXECUTE IMMEDIATE stmt;
         stmt := 'ALTER DATABASE DROP STANDBY LOGFILE GROUP ' || rlcRec.grp;
         EXECUTE IMMEDIATE stmt;
      ELSE
         stmt := 'ALTER DATABASE ADD LOGFILE THREAD ' ||
                 rlcRec.thr || ' SIZE ' ||  rlcRec.bytes;
         EXECUTE IMMEDIATE stmt;
         BEGIN
            stmt := 'ALTER DATABASE DROP LOGFILE GROUP ' || rlcRec.grp;
            DBMS_OUTPUT.PUT_LINE(stmt);
            EXECUTE IMMEDIATE stmt;
         EXCEPTION
            WHEN OTHERS THEN
               EXECUTE IMMEDIATE 'ALTER SYSTEM SWITCH LOGFILE';
               EXECUTE IMMEDIATE 'ALTER SYSTEM CHECKPOINT GLOBAL';
               EXECUTE IMMEDIATE stmt;
         END;
      END IF;
   END LOOP;
END;
/