ORACLE 資料遷移

dbhelper發表於2014-11-27
步驟:
備份資料庫
backup database
1、use rman backup database 
rman target / 
rman>backup as compressed backupset format 'f:\backup\full_%d_U' database; 
遷移使用者存放的資料檔案
1、tablespace offline 
sql>alter tablespace USERS offline normal; 
sql>alter tablespace BSCHIS_DATA offline normal; 
sql>alter tablespace MPI offline normal; 
sql>alter tablespace BSHIS offline normal; 
sql>alter tablespace PHIS offline normal; 
sql>alter tablespace BSLIS offline normal; 
sql>alter tablespace PFLIS offline normal; 
sql>alter tablespace PHIS23 offline normal; 
sql>alter tablespace HISTEST offline normal; 
sql>alter tablespace LIS offline normal; 
2、CP datafile to new destination 
3、alter tablespace rename datafile 
sql>alter tablespace USERS rename datafile 'N:\ORADATA\ORCL\USERS01.DBF' to 'E:\oradata\USERS01.DBF' ; 
sql>alter tablespace BSCHIS_DATA rename datafile 'N:\ORADATA\ORCL\BSCHIS_DATA.DBF' to 'E:\oradata\BSCHIS_DATA.DBF' ; 
sql>alter tablespace MPI rename datafile 'N:\ORADATA\ORCL\MPI.DBF' to 'E:\oradata\MPI.DBF' ; 
sql>alter tablespace BSHIS rename datafile 'N:\ORADATA\ORCL\BSHIS.DBF' to 'E:\oradata\BSHIS.DBF' ; 
sql>alter tablespace PHIS rename datafile 'N:\ORADATA\ORCL\PHIS.DBF' to 'E:\oradata\PHIS.DBF' ; 
sql>alter tablespace BSLIS rename datafile 'N:\ORADATA\ORCL\BSLIS.DBF' to 'E:\oradata\BSLIS.DBF' ; 
sql>alter tablespace PFLIS rename datafile 'N:\ORADATA\ORCL\PFLIS.DBF' to 'E:\oradata\PFLIS.DBF' ; 
sql>alter tablespace PHIS23 rename datafile 'N:\ORADATA\ORCL\PHIS23.DBF' to 'E:\oradata\PHIS23.DBF' ; 
sql>alter tablespace HISTEST rename datafile 'N:\ORADATA\ORCL\HISTEST.DBF' to 'E:\oradata\HISTEST.DBF' ; 
sql>alter tablespace LIS rename datafile 'N:\ORADATA\ORCL\LIS.DBF' to 'E:\oradata\LIS.DBF' ; 
4、alter tablespace online 
sql>alter tablespace USERS online; 
sql>alter tablespace BSCHIS_DATA online; 
sql>alter tablespace MPI online; 
sql>alter tablespace BSHIS online; 
sql>alter tablespace PHIS online; 
sql>alter tablespace BSLIS online; 
sql>alter tablespace PFLIS online; 
sql>alter tablespace PHIS23 online; 
sql>alter tablespace HISTEST online; 
sql>alter tablespace LIS online;
遷移資料庫redolog 檔案
1、add loggroup
sql>alter database add logfile group 4('E:\oradata\redo04.log') size 50M; 
sql>alter database add logfile member 'E:\oradata\redo004.log' to group 4; 
sql>alter database add logfile group 5('E:\oradata\redo05.log') size 50M; 
sql>alter database add logfile member 'E:\oradata\redo005.log' to group 5; 
sql>alter database add logfile group 6('E:\oradata\redo06.log') size 50M; 
sql>alter database add logfile member 'E:\oradata\redo006.log' to group 6; 
2、drop old loggroup file
sql>alter database drop logfile group 1;
sql>alter database drop logfile group 2;
sql>alter database drop logfile group 3;
3、sql>alter system switch logfile;
注意刪除舊的loggroup 需要確定 loggroup 為inactive 狀態。
select status ,group# from v$log 確定。

   遷移temp tablespace 臨時表空間檔案   
1、create a new temp tablespace 
sql>create temporary tablespace temp02 tempfile 'e:\oradata\temp02.dbf' size 512M autoextend on next 500m MAXSIZE UNLIMITED; 
2、set default temp tablespace 
sql>alter database default temporary tablespace temp02; 
3、drop old temp tablespace 
sql>drop tablespace temp including contents and datafiles;

資料庫undotablespace 檔案
sql> CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE 'e:\oradata\undotbs02.dbf' SIZE 5120M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED ONLINE RETENTION NOGUARANTEE BLOCKSIZE 8K FLASHBACK ON; 
sql>alter system set undo_tablespace ='UNDOTBS2'; 
sql>ALTER SYSTEM SWITCH LOGFILE; 
sql>drop tablespace undotbs1 including contents;
  
遷移資料庫的control 檔案
change control file location 
1、sql>create pfile from spfile 
2、shutdown database 
sql>shutdown immediate 
3、edit pfile change location 
cp old control file to new destination 
4、startup database 
sql>startup pfile='xxx.ora'; 
5、create new spfile 
sql>create spfile from pfile='xxx.ora' 
6、shutdown database 
sql>shutdown immediate 
7、startup database 
sql>startup 
備份資料庫
backup database
1、use rman backup database 
rman target / 
rman>backup as compressed backupset format 'f:\backup\20140729full2221_%d_U' database; 
結束
在原來資料檔案目錄(N:\oradata\orcl\) 下有system.dbf 和sysaux.dbf 檔案,為資料庫本身系統檔案 是資料庫存放資料字典的檔案,不建議改動,未做遷移。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8494287/viewspace-1349498/,如需轉載,請註明出處,否則將追究法律責任。

相關文章