Monday, March 17, 2014

Oracle: Database Migration with Datafile location changed

1. Copy all the data files, control files to new server.
2. Modify init ora file accordingly
3. Start up the instance, and you will get some errors because data file location changed.
4. Run below command to extract all data files list.
$ SQLPLUS/NOLOG 
SQL> CONNECT / AS SYSDBA 
SQL> spool dfiles.lst
SQL> SELECT * from V$DBFILE; 
SQL> spool off 
SQL> SELECT * from V$LOGFILE; 
SQL> SHUTDOWN 
SQL> EXIT 
 
5.  create config.sql as below

STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "<ORACLE_SID>" RESETLOGS
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 200
    MAXINSTANCES 8
    MAXLOGHISTORY 1168
LOGFILE
  GROUP 1 '/data1/<ORACLE_SID>/redo01.log'  SIZE 100M,
  GROUP 2 '/data2/<ORACLE_SID>/redo02.log'  SIZE 100M,
  GROUP 3 '/data3/<ORACLE_SID>/redo03.log'  SIZE 100M
-- STANDBY LOGFILE
DATAFILE
'/data2/<ORACLE_SID>/system01.dbf',
'/data4/<ORACLE_SID>/undotbs01.dbf',
'/data1/<ORACLE_SID>/sysaux01.dbf',
'/data5/<ORACLE_SID>/users01.dbf',
'/data1/<ORACLE_SID>/csisdata01.dbf',
'/data2/<ORACLE_SID>/csisdata02.dbf',
'/data3/<ORACLE_SID>/csisdata03.dbf',
'/data4/<ORACLE_SID>/csisdata04.dbf',
'/data5/<ORACLE_SID>/csisdata05.dbf',
'/data6/<ORACLE_SID>/csisdata06.dbf',
'/data7/<ORACLE_SID>/csisdata07.dbf',
'/data8/<ORACLE_SID>/csisdata08.dbf',
'/data1/<ORACLE_SID>/csisindex01.dbf',
'/data2/<ORACLE_SID>/csisindex02.dbf',
'/data3/<ORACLE_SID>/csisindex03.dbf',
'/data4/<ORACLE_SID>/csisindex04.dbf',
'/data5/<ORACLE_SID>/csisindex05.dbf',
'/data8/<ORACLE_SID>/tfdindex08.dbf',
'/data6/<ORACLE_SID>/user02.dbf'
CHARACTER SET WE8ISO8859P1
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/DBF/QA/ORA_LOGS/1_1_705162525.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
-- All logs need archiving and a log switch is needed.
-- --ALTER SYSTEM ARCHIVE LOG ALL;
-- Database can now be opened normally.
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
-- --ALTER TABLESPACE TEMP ADD TEMPFILE '/data3/<ORACLE_SID>/temp01.dbf'
    -- -- SIZE 3000M REUSE AUTOEXTEND OFF;
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '/data3/<ORACLE_SID>/temp01.dbf' SIZE 500M REUSE AUTOEXTEND OFF;
COMMIT;

6. Move all old control files out of its location.
7. Run below command to create new control files
$ SQLPLUS/NOLOG
SQL> CONNECT / AS SYSDBA 
SQL> spool newControls.log
SQL> @config.sql
SQL> spool off
SQL> shutdown immediate
SQL> startup
 
8. Verify the migration. 

No comments:

Post a Comment