Skip Headers
Oracle® Database Backup and Recovery Reference
11g Release 2 (11.2)

Part Number E10643-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
Contact Us

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

SWITCH

Purpose

Use the SWITCH command to perform either of the following operations:

A SWITCH is equivalent to the SQL statement ALTER DATABASE RENAME FILE: the names of the files in the RMAN repository are updated, but the database does not rename the files at the operating system level.

Prerequisites

RMAN must be connected to a target database. When switching tablespaces, datafiles, or tempfiles, the files must be offline. When switching the whole database, the database must not be open.

Usage Notes

The SWITCH command deletes the RMAN repository records for the datafile copy from the recovery catalog and updates the control file records to status DELETED.

If RMAN is connected to a recovery catalog, and if the database is using a control file restored from backup, then SWITCH updates the control file with records of any datafiles known to the recovery catalog but missing from the control file.

Execute SWITCH ... TO COPY only at the RMAN prompt. Use SWITCH without TO COPY only within a RUN block.

Syntax

switch::=

Description of switch.gif follows
Description of the illustration switch.gif

(datafileSpec::=)

switchFile::=

Description of switchfile.gif follows
Description of the illustration switchfile.gif

(datafileSpec::=, tempfileSpec::=)

Semantics

switch

This subclause switches filenames for a database, tablespace, or datafile to the latest image copies available for the specified files. By executing this command, you avoid restoring datafiles from backups. Execute SWITCH ... TO COPY only at the RMAN prompt.

Syntax Element Description
DATABASE Renames the datafiles and control files to use the filenames of image copies of these files. RMAN switches to the latest image copy of each database file.

After a database switch, RMAN considers the previous database files as datafile copies.

DATAFILE datafileSpec Switches the specified datafiles to the latest image copies.

After the switch, the control file no longer considers the specified datafile as current.

TABLESPACE tablespace_name Switches all datafiles within the specified tablespace, as with SWITCH DATAFILE ... TO COPY (see Example 3-55).
   TO COPY Switches the specified active database files to image copies.

switchFile

This subclause updates the names for datafiles and tempfiles for which you have issued a SET NEWNAME command. Use this clause only within a RUN block.

Syntax Element Description
DATAFILE ALL Specifies that all datafiles for which a SET NEWNAME FOR DATAFILE command has been issued in this job are switched to their new name (see Example 3-56).
DATAFILE datafileSpec Specifies the datafile that are renaming. After the switch, the control file no longer considers the specified file as current. If you do not specify a TO option, then RMAN uses the filename specified on a prior SET NEWNAME command in the RUN block for this file as the switch target.

   TO DATAFILECOPY
   {'filename' |
    TAG tag_name}
Specifies the input copy file for the switch, that is, the datafile copy that you intend to rename (see Example 3-58).
TEMPFILE ALL Specifies that all tempfiles for which a SET NEWNAME FOR TEMPFILE command has been issued in this job are switched to their new name.
TEMPFILE tempfileSpec Specifies the tempfile that you are renaming. If you do not specify a TO option, then RMAN uses the filename specified on a prior SET NEWNAME command in the RUN block for this file as the switch target. The target database must be mounted but not open.
   TO 'filename' Renames the tempfile to the specified name (see Example 3-57). The target database must be mounted but not open.

Examples

Example 3-55 Switching to Image Copies to Avoid Restoring from Backup

Assume that a disk fails, rendering all datafiles in the users tablespace inaccessible. Image copies of all datafiles in this tablespace exist in the fast recovery area. After starting RMAN and connecting to the database as TARGET, you can run SWITCH to point to the control file to the new datafiles and then run RECOVER as follows:

SQL "ALTER TABLESPACE users OFFLINE IMMEDIATE";
SWITCH TABLESPACE users TO COPY;
RECOVER TABLESPACE users;
SQL "ALTER TABLESPACE users ONLINE";

Example 3-56 Switching Datafile Filenames After a Restore to a New Location

Assume that a disk fails, forcing you to restore a datafile to a new disk location. After starting RMAN and connecting to the database as TARGET, you can use the SET NEWNAME command to rename the datafile, then RESTORE to restore the missing datafile. You run SWITCH to point to the control file to the new datafile and then RECOVER. This example allocates both disk and tape channels.

RUN
{
  ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
  ALLOCATE CHANNEL dev2 DEVICE TYPE sbt;
  SQL "ALTER TABLESPACE users OFFLINE IMMEDIATE";
  SET NEWNAME FOR DATAFILE '/disk1/oradata/prod/users01.dbf'
                        TO '/disk2/users01.dbf';
  RESTORE TABLESPACE users;
  SWITCH DATAFILE ALL;
  RECOVER TABLESPACE users;
  SQL "ALTER TABLESPACE users ONLINE";
}

Example 3-57 Renaming Tempfiles Using SET NEWNAME and SWITCH TEMPFILE ALL

This example demonstrates using SET NEWNAME to specify new names for several tempfiles, and SWITCH TEMPFILE ALL to rename the tempfiles to the specified names. The database must be closed at the beginning of this procedure. The tempfiles are re-created at the new locations when the database is opened.

CONNECT TARGET /
STARTUP FORCE MOUNT
RUN
{  
  SET NEWNAME FOR TEMPFILE 1 TO '/disk2/temp01.dbf';
  SET NEWNAME FOR TEMPFILE 2 TO '/disk2/temp02.dbf';
  SET NEWNAME FOR TEMPFILE 3 TO '/disk2/temp03.dbf'; 
  SWITCH TEMPFILE ALL;  
  RESTORE DATABASE;  
  RECOVER DATABASE;  
  ALTER DATABASE OPEN;
}

Example 3-58 Switching to a Datafile Copy

The following command switches the datafile in the tools tablespace to the datafile copy named /disk2/tools.copy:

RUN
{ 
  SQL "ALTER TABLESPACE tools OFFLINE IMMEDIATE";
  SWITCH DATAFILE '/disk1/oradata/prod/tools01.dbf' 
  TO DATAFILECOPY '/disk2/tools.copy'; 
  RECOVER TABLESPACE tools;
  SQL "ALTER TABLESPACE tools ONLINE";
}