Renomear DATAFILE com RMAN
É fácil renomear DATAFILE com RMAN, o pulo do gato está no comando SWITCH, que faz a troca de nome no CONTROLFILE. Só a TABLESPACE do DATAFILE que será movido precisa estar OFFLINE.
Não é necessário fazer o Backup dentro do mesmo Bloco RUN, mas se for feito, o tempo de RECOVER será menor.
É interessante tentar executar o RECOVER antes do SWITCH: dá erro, pois no CONTROLFILE (onde o RECOVER va procurar o DATAFILE) ainda está o nome antigo. É considerado para o RECOVER não o nome do DATAFILE utilizado no Bloco RUN, mas no CONTROLFILE.
[oracle@nerv11 ~]$ rman TARGET /
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 23 09:16:34 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1249620830)
RMAN> RUN {
2> BACKUP DATAFILE 5;
3> SQL 'ALTER TABLESPACE EXAMPLE OFFLINE';
4> SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata/ORCL/example01.NEWNAME.dbf';
5> RESTORE DATAFILE 5;
6> SWITCH DATAFILE 5;
7> RECOVER DATAFILE 5;
8> SQL 'ALTER TABLESPACE EXAMPLE ONLINE';
9> }
Starting backup at 23-JUN-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/ORCL/example01.NEW.dbf
channel ORA_DISK_1: starting piece 1 at 23-JUN-10
channel ORA_DISK_1: finished piece 1 at 23-JUN-10
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_06_23/o1_mf_nnndf_TAG20100623T091708_623yt4lh_.bkp tag=TAG20100623T091708 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 23-JUN-10
sql statement: ALTER TABLESPACE EXAMPLE OFFLINE
executing command: SET NEWNAME
Starting restore at 23-JUN-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORCL/example01.NEWNAME.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_06_23/o1_mf_nnndf_TAG20100623T091708_623yt4lh_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2010_06_23/o1_mf_nnndf_TAG20100623T091708_623yt4lh_.bkp tag=TAG20100623T091708
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 23-JUN-10
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=722423834 file name=/u01/app/oracle/oradata/ORCL/example01.NEWNAME.dbf
Starting recover at 23-JUN-10
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 23-JUN-10
sql statement: ALTER TABLESPACE EXAMPLE ONLINE
RMAN>