Using datafile copy to rename a data file, datafilecopy
Ideas:
O use RMAN to copy data files
O offline
O switch file name. This step changes the file name corresponding to the data file in the control file.
O recover data files
O online data files and restore production
Note: You can also use this method for database copy, switch database, and migrate the DATABASE...
The experiment process is as follows:
==============================================
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination/home/oracle/arch
Oldest online log sequence 63
Next log sequence to archive 65
Current log sequence 65
RMAN> report schema;
Using target database control file instead of recovery catalog
Report of database schema
List of Permanent Datafiles
======================================
File Size (MB) Tablespace RB segs Datafile Name
---------------------------------------------------------------
1 700 SYSTEM ***/u01/app/oracle/oradata/ora10g/system01.dbf
2 700 UNDOTBS1 ***/u01/app/oracle/oradata/ora10g/undotbs01.dbf
3 260 SYSAUX ***/u01/app/oracle/oradata/ora10g/sysaux01.dbf
4 5 USERS ***/u01/app/oracle/oradata/ora10g/users01.dbf
5 5 USERS ***/u01/app/oracle/oradata/ora10g/users02.dbf <I plan to rename the data file No. 5
List of Temporary Files
======================================
File Size (MB) Tablespace Maxsize (MB) Tempfile Name
---------------------------------------------------------------
1 30 TEMP 32767/u01/app/oracle/oradata/ora10g/temp01.dbf
RMAN> backup as copy datafile 5 format'/u01/app/oracle/oradata/ora10g/users02_new.dbf ';
Starting backup at 05-FEB-15
Using target database control file instead of recovery catalog
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: sid = 146 devtype = DISK
Channel ORA_DISK_1: starting datafile copy
Input datafile fno = 00005 name =/u01/app/oracle/oradata/ora10g/users02.dbf
Output filename =/u01/app/oracle/oradata/ora10g/users02_new.dbf tag = TAG20150205T225207 recid = 1 stamp = 870907927
Channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 05-FEB-15
SQL> alter database datafile 5 offline;
Database altered.
SQL> recover datafile 5;
Media recovery complete.
SQL> alter database datafile 5 online;
Database altered.
RMAN> report schema;
Report of database schema
List of Permanent Datafiles
======================================
File Size (MB) Tablespace RB segs Datafile Name
---------------------------------------------------------------
1 700 SYSTEM ***/u01/app/oracle/oradata/ora10g/system01.dbf
2 700 UNDOTBS1 ***/u01/app/oracle/oradata/ora10g/undotbs01.dbf
3 260 SYSAUX ***/u01/app/oracle/oradata/ora10g/sysaux01.dbf
4 5 USERS ***/u01/app/oracle/oradata/ora10g/users01.dbf
5 5 USERS ***/u01/app/oracle/oradata/ora10g/users02_new.dbf <the file name has been replaced
List of Temporary Files
======================================
File Size (MB) Tablespace Maxsize (MB) Tempfile Name
---------------------------------------------------------------
1 30 TEMP 32767/u01/app/oracle/oradata/ora10g/temp01.dbf