Skip Headers
Oracle® Database Backup and Recovery Reference
10g Release 2 (10.2)

Part Number B14194-03
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

Syntax

switch::=

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

switchFile::=

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

Purpose

To specify that a datafile copy is now the current datafile, that is, the datafile pointed to by the control file. A SWITCH is equivalent to using the PL/SQL ALTER DATABASE RENAME FILE statement: the names of the files in the RMAN repository are updated, but the database does not actually rename the files at the operating system level. Note that this command deletes the RMAN repository records for the datafile copy from the recovery catalog and updates the control file records to status DELETED.

Restrictions and Usage Notes

Keywords and Parameters

switch

Syntax Element Description
DATABASE TO COPY 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 file.

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

DATAFILE datafileSpec TO COPY Specifies the datafile that you wish to rename. As with DATABASE TO COPY, specifies to switch this datafile to the latest image copy.

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

TABLESPACE 'tablespace_name' TO COPY Switches all datafiles within the tablespace, as with SWITCH DATAFILE ... TO COPY.

switchFile

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.
DATAFILE datafileSpec TO DATAFILECOPY {'filename' | TAG = 'tag_name' } Specifies the datafile that you wish to rename. After the switch, the control file no longer considers the specified file as current. For example, this command points the control file from tbs_1.f to cp1.f:
SWITCH DATAFILE '?/dbs/tbs_1.f' TO DATAFILECOPY '?/dbs/copies/cp1.f';

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 number as the switch target.

The filename or tag provided in the TO DATAFILECOPY clause specifies the input copy file for the switch, that is, the datafile copy that you wish to rename. Specify the file by filename or tag. For example, the following command sets df2.copy as the filename for datafile 2:

SWITCH DATAFILE 2 TO DATAFILECOPY '?/dbs/df2.copy';

Note that if you specify a tag and more than one copy uses this tag name, then RMAN uses the most current copy, that is, the one needing the least recovery.

The following command switches datafile 3 to the most recently created datafile copy tagged mondayPMcopy:

SWITCH DATAFILE 3 TO DATAFILECOPY TAG mondayPMcopy;
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 TO { quoted_string | NEW With quoted_string, renames the specified tempfile to the name specified by quoted_string. With NEW, renames the specified tempfile to an OMF filename in DB_CREATE_FILE_DEST. The tempfile is created when the database is opened, if it does not exist.

Examples

Switching Datafile Filenames After a Restore: Example This example allocates one disk device and one tape device to allow RMAN to restore from disk and tape.

RUN
{  
  ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;  
  ALLOCATE CHANNEL dev2 DEVICE TYPE sbt;  
  SQL "ALTER TABLESPACE tbs_1 OFFLINE IMMEDIATE";  
  SET NEWNAME FOR DATAFILE '/disk7/oracle/tbs11.f' 
    TO '/disk9/oracle/tbs11.f';  
  RESTORE TABLESPACE tbs_1; 
  SWITCH DATAFILE ALL;  
  RECOVER TABLESPACE tbs_1;  
  SQL "ALTER TABLESPACE tbs_1 ONLINE";  
}

Renaming a Tempfile Directly Using SWITCH TEMPFILE: Example This example renames a tempfile without using the SET NEWNAME command to specify the new name for the file. Note that the database must not be open for this operation.

RUN
{  
  SWITCH TEMPFILE 1 TO '/newdisk/dbs/temp1.f';
  }

Renaming a Tempfile Using SET NEWNAME and SWITCH TEMPFILE: Example This example demonstrates using SET NEWNAME to specify a new name for a tempfile, and SWITCH to actually rename the tempfile to the specified name. Note that the database is not open at the start of this procedure. The tempfile is re-created when the database is opened.

RUN
{  
  SET NEWNAME FOR TEMPFILE 1 TO '/newdisk/dbs/temp1.f';  
  SWITCH TEMPFILE 1;  
  RESTORE DATABASE;  
  RECOVER DATABASE;  
  ALTER DATABASE OPEN;  
}

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

RUN
{  
  SET NEWNAME FOR TEMPFILE 1 TO '/newdisk/dbs/temp1.f';  
  SET NEWNAME FOR TEMPFILE 2 TO '/newdisk/dbs/temp2.f';  
  SET NEWNAME FOR TEMPFILE 3 TO NEW; #use OMF for this one 
  SWITCH TEMPFILE ALL;  
  RESTORE DATABASE;  
  RECOVER DATABASE;  
  ALTER DATABASE OPEN;  
}

Renaming Tempfiles Using SET NEWNAME and SWITCH TEMPFILE ALL: Example This example illustrates specifying names for tempfiles when duplicating a database for standby.

RUN
{  
  SET NEWNAME FOR TEMPFILE 1 TO '/newdisk/dbs/temp1.f';  
  SET NEWNAME FOR TEMPFILE 2 TO '/newdisk/dbs/temp2.f';  
  SET NEWNAME FOR TEMPFILE 3 TO '/newdisk/dbs/temp3.f';  
DUPLICATE DATABASE FOR STANDBY;
}