SWITCH

Update the filenames for a database, tablespace, or datafile to the latest image copies available for the specified files

Update the filenames for datafiles and tempfiles for which you have issued a SETNEWNAME command

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.

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.

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 SETNEWNAME command in the RUN block for this file as the switch target.

TO DATAFILECOPY {'filename'| TAGtag_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 SETNEWNAME FOR TEMPFILE command has been issued in this job are switched to their new name.

TEMPFILEtempfileSpec

Specifies the tempfile that you are renaming. If you do not specify a TO option, then RMAN uses the filename specified on a prior SETNEWNAME 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:

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 SETNEWNAME 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.

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.