Skip Headers

Oracle® Database Backup and Recovery Advanced User's Guide
10g Release 1 (10.1)

Part Number B10734-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

12
Migrating Databases To and From ASM with Recovery Manager

This chapter describes how to migrate a database into and out of an ASM disk group using Recovery Manager. It covers the following topics:

Migrating a Database into ASM

To take advantage of Automatic Storage Management with an existing database you must migrate that database into ASM. This migration is performed using Recovery Manager (RMAN) even if you are not using RMAN for your primary backup and recovery strategy.

A database can be moved from non-ASM disk storage directly into ASM, or you can back the database up to tape and then from tape backups move it into ASM. Moving the database to tape backup and then into ASM is recommended if your database is so large that you cannot have copies of the database on non-ASM disk storage and ASM disk storage simultaneously. You can back the database up to tape, convert your non-ASM disk storage into an ASM disk group, and then restore from tape to the ASM disk group.

Limitation on ASM Migration with Transportable Tablespaces

The procedure described here does not work for transportable (foreign) tablespaces. Such tablespaces needs to be made read-write and imported into the database, before they can be migrated into ASM using this procedure.

Preparing to Migrate a Database to ASM

There are several steps required to prepare your database for migration and collect useful information you will need later, before you start the actual migration process.

Determine Your DBID

If you are not using a recovery catalog, you may need to know your DBID. You must restore your control file from autobackup during the migration process, and you will need to set your DBID before you restore the control file.

Your DBID should be part of the permanent records you keep about your database. If you do not have it in your records, the easiest way to find out your DBID is to connect the RMAN client to the database to be migrated. RMAN displays the DBID whenever it starts up. For example:

% rman TARGET /
Recovery Manager: Release 10.1.0.2.0 - Production

Copyright (c) 1995, 2003, Oracle.  All rights reserved.

connected to target database: RDBMS (DBID=774627068)

RMAN> exit

Make a note of this value.

Determine Names of Database Files

Obtain the filenames of the control files, datafiles, and online redo logs for your database. This information will useful if you decide to migrate back to old (non-ASM) storage later. Information about datafiles is available by querying V$DATAFILE, and the control file names can be found in the CONTROL_FILES initialization parameter.

Generate RMAN Command File to Undo ASM Migration

If you need to migrate your database back to non-ASM storage later, this process will be simplified if you generate an RMAN command file now with the necessary commands to perform this migration. Even if you make changes to your database later, such as adding datafiles, the command file you create now will serve as a useful starting point.

There is a PL/SQL script described in "Generating ASM-to-Non-ASM Storage Migration Script" which will generate the necessary RMAN commands for you. Run this script and save the output as part of the permanent records you keep for your database.

Disk-Based Migration of a Database to ASM

If you have enough disk space that you can have both your entire non-ASM database and your ASM disk group on disk at the same time, you can do the migration directly without using tapes.

Once you have completed the preparations in "Preparing to Migrate a Database to ASM", begin the migration procedure.

The procedure differs slightly between primary and standby databases. A number of the steps described in this procedure apply only in one or the other case. There are also a few steps where the procedure is different depending upon whether you are using a recovery catalog. The steps that vary are identified as necessary in the description of the process.

To perform the migration, carry out the following steps:

  1. Disable change tracking.
    SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
    
    
    
  2. If this is standby database, stop managed recovery mode.
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    
    
  3. Shut down the database consistently. For example:
    SQL> SHUTDOWN IMMEDIATE
    
    
    
  4. Modify the initialization parameter file of the target database as follows:

At this point the migration is complete. The original datafiles, still in non-ASM storage, are cataloged as datafile copies in the RMAN repository. You can use them as backups, or reclaim the disk space by deleting them.

If you were using change tracking for incremental backups, you can re-enable it now. For example:

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

If you decide to migrate back to old storage, you can switch back to the original datafiles, using the script created in "Preparing to Migrate a Database to ASM". If you have not yet deleted your original datafiles, you can also use the SWITCH DATABASE TO COPY command to switch back rather than going through the whole migration process.

Cleanup of Non-ASM Files After ASM Migration

You can delete the old database files to free disk space. The RMAN repository has records of the old datafiles, so you can delete these with an RMAN command. The old control files and online redo logs, however, are not in the repository and must be deleted with host operating system commands. This example shows how to perform this under Unix, using the rm command for the online redo logs and control files:

# delete datafiles
RMAN> DELETE COPY OF DATABASE;
RMAN> HOST 'rm old_online_redo_logs';
RMAN> HOST 'rmold_control_files';

Using Tape Backups to Migrate a Database to ASM

This alternative procedure is useful when you do not have enough disk space to hold both the non-ASM version of your database and the ASM disk group that will hold your database after the migration. The database is backed up from non-ASM storage to tape using RMAN, then restored from tape into ASM storage.

Once you have completed the preparations in "Preparing to Migrate a Database to ASM", begin the migration procedure.

Performing Migration of a Database to ASM Storage using RMAN Tape Backup

To migrate your non-ASM database into ASM storage using a tape backup, use the following procedure:

  1. Backup the whole database to tape using RMAN. For example:
         RMAN> BACKUP DEVICE TYPE SBT DATABASE;
      
    

    After backup is done, disable change tracking. For example:

    SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
    
    
    

    If this is standby database, stop managed recovery mode.

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    
    

Shut down the database consistently. For example:

SQL> SHUTDOWN IMMEDIATE

At this point you can delete the old database files and create your ASM disk groups.

  1. Modify the initialization parameter file of the target database as follows:

Running this PL/SQL code causes the SQL*Plus client to display an RMAN script which you can save to a file and run as a command file in the RMAN client.

After this operation all datafiles are in ASM.

Now you must create new tempfiles for the temporary tablespaces. For each temporary tablespace, execute the following command:

RMAN> SQL "ALTER TABLESPACE tablespacename ADD TEMPFILE;"

If this a primary database, then recover the database and perform an OPEN RESETLOGS on the database.

RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;

Note that you must use the RESETLOGS option because the control file is restored from backup.

If you were using change tracking for incremental backups, you can re-enable it now. For example:

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

If you are migrating a standby database, do not open the database at this time. If your standby database has standby online logs stored in the flash recovery area, then you must move standby online log files into ASM storage. For each standby online redo log file, you must create a new one in ASM, and delete an old one from the non-ASM storage. For a PL/SQL script that can perform this task for you, see "PL/SQL Scripts Used in Migrating to ASM Storage".

Migrating the Flash Recovery Area to ASM

The following procedure assumes that you have a flash recovery area in non-ASM disk storage and you need to move it to an ASM disk group, possibly preserving its contents.

  1. If logging for Flashback Database is enabled, then disable it. This is needed because the logs for Flashback Database are located in the flash recovery area. For example:
    SQL> ALTER DATABASE FLASHBACK OFF;
    
    
    
  2. If this database is a primary database and your online logs, control file or archived redo logs are in the flash recovery area, then perform a consistent shutdown of your database. For example:
    SQL> SHUTDOWN IMMEDIATE
    
    
    

    If this database is a standby database and your standby online logs, controlfile, or archive logs are in recovery area, then stop managed recovery mode and shutdown database.

  3. Modify the initialization parameter file of the target database as follows:
    • Set DB_RECOVERY_FILE_DEST to the desired ASM disk group.
    • Modify DB_RECOVERY_FILE_DEST_SIZE if you need to change the size of the flash recovery area.
  4. If you shut down the database in step 2, then bring the database to a NOMOUNT state. For example:
    RMAN> STARTUP NOMOUNT
    
    

    If the old recovery area has copy of the current controlfile, then restore controlfile from the old DB_RECOVERY_FILE_DEST and mount the database again.

    RMAN> RESTORE CONTROLFILE FROM 'filename_of_old_control_file';
    RMAN> ALTER DATABASE MOUNT;
    
    
  5. If you are using tape backups, then you should back up the entire flash recovery area to tape at this time. For example:
    RMAN> BACKUP RECOVERY AREA;
    
    
    

    You can also use the DELETE INPUT option when backing up the flash recovery area to tape, if you want to immediately free the non-ASM space previously used to store flash recovery area files:

    RMAN> BACKUP RECOVERY AREA DELETE INPUT;
    
    
    

    Note: If you do not have tape, you should not delete the flash recovery area storage.

  6. If you were using flashback logging before to support flashback database, you can re-enable it now. For example:
    SQL> ALTER DATABASE FLASHBACK ON;
    
    
    

    Now, optionally, you can move your backups from old recovery area to the new location. To move the existing backupsets and archived redo log files, use these two commands:

    RMAN> BACKUP AS COPY ARCHIVELOG ALL DELETE INPUT;
    RMAN> BACKUP DEVICE TYPE DISK BACKUPSET ALL DELETE INPUT;
    
    
    

    Then you must move your datafile copies. For each datafile copy in the old recovery area, use this command:

    RMAN> BACKUP AS COPY DATAFILECOPY "name" DELETE INPUT;
    
    
    

    where name is the path to the datafile copy in the old recovery area location.

    If the old recovery area location contains a large number of files, you can use the following PL/SQL script to generate the RMAN commands required to relocate the files:

    set serveroutput on;
    declare
      cursor dfc is select name from v$datafile_copy
                     where status = 'A'
                       and is_recovery_dest_file = 'YES';
    begin
      dbms_output.put_line('run');
      dbms_output.put_line('{');
        dbms_output.put_line('backup as copy archivelog all delete input;');
        dbms_output.put_line('backup device type disk backupset all delete 
    input;');
      for dfcrec in dfc loop
        dbms_output.put_line('backup as copy datafilecopy ''' ||
                             dfcrec.name || '''delete input;');
      end loop;
      dbms_output.put_line('}');
    end;
    
    
    
  7. If this database is a standby database, then do not open the database at this point. If this database is a physical standby database, then restart managed recovery mode.

    If this is a primary database (that is, not a standby database), then open the database:

    RMAN> alter database open;  
    
       
    
  8. If this is a standby database, then the online logs cannot be renamed at this point. You must delete the files containing the online redo logs at the operating system level. When the standby database is activated, new online logs will automatically be added as ASM files.

    If this is a primary database and you had online redo log files in the flash recovery area, then you should set up your database to store the online redo logs in the ASM disk group. For each online redo log group, you must create a new online redo log in the ASM disk group, archive the current logs, and delete the old log member. For a PL/SQL script that can perform this task for you, see "Migrating Online Redo Logs to ASM Storage".

  9. If this is a standby database and you had standby online logs in the recovery area, you should move standby online logs into ASM. For a PL/SQL script that can perform this task for you, see "Migrating Standby Online Redo Log Files to ASM Storage".

At this point the migration of the flash recovery area is complete.

Migrating a Database from ASM to Non-ASM Storage

Migrating a database back from ASM storage to non-ASM storage is similar to the original migration to ASM. The process described here assumes that you can perform the migration through tape. It is very similar to the process described in "Using Tape Backups to Migrate a Database to ASM". You can also migrate from ASM to non-ASM storage using only disk, using a process similar to the one used to migrate into ASM storage using only disk.

  1. If you are not using a recovery catalog, then determine your DBID, as described in "Determine Your DBID". Write it down, because you will use it in restoring your control file into non-ASM storage.
  2. Backup the database to tape. For example:
    RMAN> BACKUP DEVICE TYPE SBT DATABASE;
    
    
  3. After backup is done, disable change tracking. For example:
    SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
    
      
    
  4. If this is a standby database, stop managed recovery mode.
  5. Perform a consistent shutdown of the database. For example:
    SQL> SHUTDOWN IMMEDIATE
    
    
    
  6. Delete the ASM disk groups.
  7. Modify the initialization parameter file of the database as follows:
    • Remove DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_LOG_DEST_n parameters.
    • Add the CONTROL_FILES parameter that specifies locations of the control file.
  8. Startup the database in NOMOUNT mode. For example:
    RMAN> STARTUP NOMOUNT;
    
    
    
  9. Restore the control file into new locations from backup.

    If you are not using a recovery catalog, then you must use a control file autobackup. Set your DBID and restore the control file, as follows:

    RMAN> SET DBID 320066378;
    RMAN>  RUN {
       ALLOCATE CHANNEL ctape DEVICE TYPE SBT 
          PARMS='...';
       ALLOCATE CHANNEL cdisk DEVICE TYPE DISK;
       RESTORE CONTROLFILE FROM AUTOBACKUP;
    }
    
    

    If you use a recovery catalog, then you do not need to use a control file autobackup, because the recovery catalog contains a record of the control file backup location. Restore the control file, as follows:

    RMAN>  RUN {
       ALLOCATE CHANNEL ctape DEVICE TYPE SBT 
          PARMS='...';
       ALLOCATE CHANNEL cdisk DEVICE TYPE DISK;
       RESTORE CONTROLFILE;
    }
    
    
  10. Mount the database. For example:
    RMAN> ALTER DATABASE MOUNT;
    
    
    
  11. Now restore database into new location. Use the RMAN script generated by the procedure described in "Generating ASM-to-Non-ASM Storage Migration Script". As noted in that section, you may need to alter the script if you have made structural changes to your database since you first migrated to ASM, or if you want to the location where you wish to store the datafiles. After this operation all datafiles will be in the locations specified in the file.
  12. Now you must create new tempfiles for the temporary tablespaces. For each temporary tablespace, execute the following command:
    RMAN> SQL "ALTER TABLESPACE tablespacename ADD TEMPFILE tempfilename;"
    
    
  13. If this a standby database, then do not open the database at this time.

    If this is a primary database, then recover and open the database. Note that you must perform an OPEN RESETLOGS because the control file is restored from backup.

    RMAN> RECOVER DATABASE;
    RMAN> ALTER DATABASE OPEN RESETLOGS;
    
    
  14. If this is a primary database, then move your online logs back into old location. For each online redo log group, carry out the following steps in SQL*Plus:
        ALTER DATABASE ADD LOGFILE SIZE BYTES FILENAME new_name;
        ALTER DATABASE ARCHIVE LOG CURRENT;
        ALTER DATABASE DROP LOGFILE old_name;
    
    
    

    If this is a standby database, then you should move standby online logs back to the old location. For each standby online log, execute the following commands in SQL*Plus:

    ALTER DATABASE ADD STANDBY LOGFILE SIZE BYTES FILENAME new_name;
    ALTER DATABASE DROP STANDBY LOGFILE old_name;
    
    
    
    
  15. If this is a standby database, then start managed recovery mode at this time.

At this point, the migration from ASM to non-ASM storage is complete. You may want to enable change tracking for incremental backups, if you were using it before the migration. For example:

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

PL/SQL Scripts Used in Migrating to ASM Storage

The following PL/SQL scripts perform tasks which arise in more than one of the migration scenarios described in this chapter.

Generating ASM-to-Non-ASM Storage Migration Script

You can use the following PL/SQL script to generate a series of RMAN commands that you can use to migrate your database back from ASM to non-ASM disk storage.

set serveroutput on;
declare
    cursor df is select file#, name from v$datafile;
begin
    dbms_output.put_line('run');
    dbms_output.put_line('{');
    for dfrec in df loop
        dbms_output.put_line('set newname for datafile ' ||
            dfrec.file# || ' to ''' || dfrec.name ||''' ;');
    end loop;
    dbms_output.put_line('restore database;');
    dbms_output.put_line('switch all;');
    dbms_output.put_line('}');
end;

Running this PL/SQL code causes the SQL*Plus client to display an RMAN script which you can save to a file and later run as a command file in the RMAN client to migrate your datafiles back out of ASM storage.

The script queries V$DATAFILE to find out the filenames for your datafiles before they are moved to ASM. Running this script later will restore the same set of datafiles to their pre-ASM locations. If you decide to store the files in a different disk location when moving them out of ASM, update the generated RMAN commands to use different destination filenames. If you add datafiles to your database, edit the script to include SET NEWNAME commands to specify locations for the new datafiles. If you delete datafiles, remove the corresponding commands from the migration script.

Migrating Online Redo Logs to ASM Storage

The following PL/SQL script can be used to migrate your online redo log groups into ASM, as part of migrating a database or a flash recovery area into ASM. For each online redo log group, the script adds a log file stored in ASM, archives the current redo logs, and then drops the non-ASM log file.

Save this script into a file and run it from within SQL*Plus to migrate the online logs.

declare
   cursor orlc is select lf.member, l.bytes
                    from v$log l, v$logfile lf
                   where l.group# = lf.group#
                     and lf.type = 'ONLINE'
                   order by l.thread#, l.sequence#;
   type numTab_t is table of number index by binary_integer;
   type charTab_t is table of varchar2(1024) index by binary_integer;
   byteslist numTab_t;
   namelist  charTab_t;
   procedure migrateorlfile(name IN varchar2, bytes IN number) is
      retry    number;
      stmt     varchar2(1024);
      als      varchar2(1024) := 'alter system switch logfile';
   begin
      select count(*) into retry from v$logfile;
      stmt := 'alter database add logfile size ' || bytes;
      execute immediate stmt;
      stmt := 'alter database drop logfile ''' || name || '''';
      for i in 1..retry loop
         begin
            execute immediate stmt;
            exit;
         exception
            when others then
            if i > retry then
               raise;
            end if;
            execute immediate als;
        end;
     end loop;
   end;
begin
   open orlc;
   fetch orlc bulk collect into namelist, byteslist;
   close orlc;
   for i in 1..namelist.count loop
      migrateorlfile(namelist(i), byteslist(i));
   end loop;
end;

Migrating Standby Online Redo Log Files to ASM Storage

The following PL/SQL script can be used to migrate your standby online redo log files into ASM, as part of migrating your whole database into ASM.

Save this script into a file and run it from within SQL*Plus to migrate the standby online logs.

declare
   cursor srlc is select lf.member, l.bytes
                    from v$standby_log l, v$logfile lf
                   where l.group# = lf.group#
                     and lf.type = 'STANDBY';
   type numTab_t is table of number index by binary_integer;
   type charTab_t is table of varchar2(1024) index by binary_integer;
   byteslist numTab_t;
   namelist  charTab_t;
   procedure migratesrl(name IN varchar2, bytes IN number) is
      stmt     varchar2(1024);
   begin
      stmt := 'alter database add standby logfile size ' || bytes;
      execute immediate stmt;
      stmt := 'alter database drop standby logfile ''' || name || '''';
      execute immediate stmt;
   end;
begin
   open srlc;
   fetch srlc bulk collect into namelist, byteslist;
   close srlc;
   for i in 1..namelist.count loop
      migratesrl(namelist(i), byteslist(i));
   end loop;
end;