Skip to content

Switch Datafile To Copy

Move Data File by RMAN

As usual, we use RMAN to change the location of a data file.

Check the file number.

SQL> select file# from v$datafile where name = '+DATA/ORCLCDB/ORCLPDB/example02.dbf';


Copy the file online.

RMAN> backup as copy datafile 18 format '+DATA/TESTCDB/ORCLPDB/example02.dbf';

Starting backup at 27-JAN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=120 instance=TESTCDB1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00018 name=+DATA/ORCLCDB/ORCLPDB/example02.dbf
output file name=+DATA/TESTCDB/ORCLPDB/example02.dbf tag=TAG20210127T162803 RECID=6 STAMP=1062952085
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
Finished backup at 27-JAN-21

Starting Control File and SPFILE Autobackup at 27-JAN-21
piece handle=+DATA/TESTCDB/AUTOBACKUP/2021_01_27/s_1062952087.364.1062952089 comment=NONE
Finished Control File and SPFILE Autobackup at 27-JAN-21

List the copy of the datafile.

RMAN> list copy of datafile 18;

List of Datafile Copies

Key     File S Completion Time Ckp SCN    Ckp Time        Sparse
------- ---- - --------------- ---------- --------------- ------
6       18   A 27-JAN-21       3616028    27-JAN-21       NO
        Name: +DATA/TESTCDB/ORCLPDB/example02.dbf
        Tag: TAG20210127T162803

Take the original file offline.

SQL> alter database datafile 18 offline;

Database altered.

Switch to new location.

RMAN> switch datafile 18 to copy;
datafile 18 switched to datafile copy "+DATA/TESTCDB/ORCLPDB/example02.dbf"

Recover the new file.

SQL> recover datafile 18;
Media recovery complete.

Take the new file online.

SQL> alter database datafile 18 online;

Database altered.

Basically, if you'd like to move more data files, the steps are the same.

Leave a Reply

Your email address will not be published. Required fields are marked *