How to switch datafiles to FRA and back again tools 15649 6401

How to switch datafiles to FRA and back again

If you, like me, like to use (rman) incrementally updated backups, a copy of all datafiles will be present in the Fast Recovery Area. That becomes quite handy if you are in sudden need of extra disk space for your database, and the FRA still has ample space left. By switching one or more datafiles to the copy in FRA, you can very quickly use this extra disk space for your database, while not even having to shut down. I developed a view to generate all the rman commands to execute the switch to FRA, and the switch back to it’s original location and name. Use it at your own discretion.

CREATE OR REPLACE FORCE VIEW rman_switch_datafiles
AS
SELECT tablespace_name
     , file_name
     , file_id
     , '==============================================='||chr(10)
     ||' switch datafile '||file_id||' to copy in FRA  '||chr(10)
     ||'==============================================='||chr(10)
     ||'run'||chr(10)
     ||'{'||chr(10)
     ||'sql ''alter tablespace '||tablespace_name||' offline'';' ||chr(10)
     ||'switch datafile '||file_id||' to copy;' ||chr(10)
     ||'recover datafile '||file_id||';' ||chr(10)
     ||'sql ''alter tablespace '||tablespace_name||' online'';'||chr(10)
     ||'}'||chr(10) rman_switch2copy
     , '======================================================='||chr(10)
     ||' switch datafile '||file_id||' in FRA back to original '||chr(10)
     ||'======================================================='||chr(10)
     ||'run'||chr(10)
     ||'{'||chr(10)
     ||'backup as copy datafile '||file_id||' format '''||file_name||''';'||chr(10)
     ||'sql ''alter tablespace '||tablespace_name||' offline'';' ||chr(10)
     ||'switch datafile '||file_id||' to copy;' ||chr(10)
     ||'recover datafile '||file_id||';' ||chr(10)
     ||'sql ''alter tablespace '||tablespace_name||' online'';' ||chr(10)
     ||'}'||chr(10) rman_switchback2original
FROM dba_data_files
WHERE tablespace_name IN ( select tablespace_name
                           from dba_tablespaces
                           where contents = 'PERMANENT'
                             and tablespace_name != 'SYSTEM' )
ORDER BY 1,2,3
/

One remark… if a datafile is switched to the FRA copy, your controlfile is updated , and the original path and filename is lost. So, before switching the datafile to FRA, it’s prudent to save the ‘back to original” stat.

2 Comments

  1. Harry Dragstra October 15, 2011
  2. Arnoud Roth October 15, 2011