Skip Headers

< td align="left" valign="top">Oracle® Database Backup and Recove ry 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
Previou s
Go to next pag
e
Next
View PDF
< /a>

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 to pics:

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 strateg y.

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 A SM 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 imp orted into the database, before they can be migrated into ASM using this procedure.

There are several steps required to prepare your database for mi gration 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 r estore your control file from autobackup during the migration process, and you will need to set your DBID before you restore the cont rol file.

Your DBID should be part of the permanent records you keep about your database. I f 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 migra ted. 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, O
racle.  All rights reserved.

connected to target database: RDBMS (D
BID=774627068)

RMAN> exit

< /a>

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 d ecide to migrate back to old (non-ASM) storage later. Information about datafiles is available by querying V$DATAFILE, a nd the control file names can be found in the CONTROL_FILES initialization parameter.

Generate RMAN Command File to Undo ASM Migr ation

If you need to migrate your database back to non-ASM storage l ater, 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 st arting point.

There is a PL/SQL script described in "Generatin g ASM-to-Non-ASM Storage Migration Script" which will generate the necessary RMAN commands for y ou. 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 u sing tapes.

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

< p class="BP">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.

< p class="BP">To perform the migration, carry out the following steps:

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

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

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

SQL>
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

If you decide to mig rate back to old storage, you can switch back to the original datafiles, using the script created in "Pr eparing 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 f iles 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;
RMA
N> HOST 'rm old_online_redo_logs';
RMAN> HOST 'rmold_control_files';

Using Tape Backups to Mi grate a Database to ASM

This alternative procedure is useful when yo u 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 Migrat e a Database to ASM", begin the migration procedure.

Performing Migration of a Database to ASM Storage us ing RMAN Tape Backup

To migrate your non-ASM database into ASM stora ge 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 tracki ng. 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 c lient.

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 th e RESETLOGS option because the control file is restored from backup.

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

SQ
L> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

If you are mig rating a standby database, do not open the database at this time. If your standby database has standby online logs stored in the flas h 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 t hat 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 cont ents.

  1. If logging for Flashback Database is ena bled, then disable it. This is needed because the logs for Flashback Database are located in the flash recovery area. For example: < pre class="CE1">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 exampl e:
    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 are a to tape at this time. For example:
    RMAN> BACKUP RECOVERY AREA;
    
    <
    a name="1014827">
    

    You can also use the DELETE INPUT option when backin g 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 st orage.

  6. If you were using flashback logging before to support flashb ack 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 DEV
    ICE 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 th e 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$dataf
    ile_copy
                     where status = 'A'
                       and is_recovery_dest_file
     = 'YES';
    begin
      dbms_output.put_line('run');
      dbms_output.put_li
    ne('{');
        dbms_output.put_line('backup as copy archivelog all delete input;');
        dbm
    s_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 ma naged recovery mode.

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

    RMAN> alter database open;  
    
       
    
  8. If this is a standby database, then the online l ogs cannot be renamed at this point. You must delete the files containing the online redo logs at the operating system level. When th e 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 shou ld move standby online logs into ASM. For a PL/SQL script that can perform this task for you, see "Migra ting 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 proce ss 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 recov ery 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 DEV
    ICE TYPE SBT DATABASE;
    
    
  3. After backup is d one, disable change tracking. For example:
    SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKI
    NG;
    
      
    
  4. If this is a standby database, stop managed recovery mode.
  5. Perform a consistent s hutdown 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 param eter that specifies locations of the control file.
  8. Startup th e database in NOMOUNT mode. For example:
    RMAN> STARTUP NOMOUNT;
    
    
    
  9. Restore the control file into new location s from backup.

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

    RMAN> SET DBID 32
    0066378;
    RMAN>  RUN {
       ALLOCATE CHANNEL ctape DEVICE TYPE SBT 
          PARMS='...';
       ALLOCATE CHANNEL cdisk DEVICE TYPE DISK;
       RESTORE CONTROLFILE FR
    OM AUTOBACKUP;
    }
    
    

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

    RMAN>  RUN {
    
     ALLOCATE CHANNEL ctape DEVICE TYPE SBT 
          PARMS='...';
       ALLOCATE CHANNEL cdisk DEV
    ICE TYPE DISK;
       RESTORE CONTROLFILE;
    }
    
    
  10. Mount the database. For example:
    RMAN> ALTE
    R DATABASE MOUNT;
    
    
    
  11. < /a>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 a lter 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 tempora ry tablespace, execute the following command:
    RMAN> SQL "ALTER TABLESPACE tablespacename A
    DD 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 OPE N RESETLOGS because the control file is restored from backup.

    RMAN> RECOVER DATA
    BASE;
    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 l og 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, execu te 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 da tabase, then start managed recovery mode at this time.

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

SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

PL/SQL Scripts Us ed 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 c ommands that you can use to migrate your database back from ASM to non-ASM disk storage.

se
t 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 th is 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 t he 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 t he same set of datafiles to their pre-ASM locations. If you decide to store the files in a different disk location when moving them o ut 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 databa se 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 fro m 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      var
char2(1024) := 'alter system switch logfile';
   begin
      select count(*) into retry f
rom v$logfile;
      stmt := 'alter database add logfile size ' || bytes;
      execute i
mmediate stmt;
      stmt := 'alter database drop logfile ''' || name || '''';
      for
i in 1..retry loop
         begin
            execute immediate stmt;
<
/a>            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 n
amelist, byteslist;
   close orlc;
   for i in 1..namelist.count loop
<
/a>      migrateorlfile(namelist(i), byteslist(i));
   end loop;
end;

Migrating Standby Online Redo Log Files to ASM Storage

The following PL/SQL script can be use d 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;
<
a name="1021791">   namelist  charTab_t;
   procedure migratesrl(name IN varchar2, bytes IN number) is
      stmt     varchar2(1024);
   begin
      stmt := 'alter database a
dd standby logfile size ' || bytes;
      execute immediate stmt;
      stmt := 'alter da
tabase drop standby logfile ''' || name || '''';
      execute immediate stmt;
   end;
begin
   open srlc;
   fetch srlc bulk collect into namelist, bytesli
st;
   close srlc;
   for i in 1..namelist.count loop
      migrate
srl(namelist(i), byteslist(i));
   end loop;
end;


Go to previous page
Previous
Go to next page< br> Next
Oracle
Copyright © 2003 Oracle Corporation
All Rights Reserved. Go to Table of Contents< br> Contents
Go
to Documentation Home
Home
Go to Book List
Book List
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback