天萃荷净
Oracle研究中心案例分析:运维DBA反映在做Oracle数据库500G~3T大小的数据进行迁移,涵盖单机、dataguard、rac迁移。
本站文章除注明转载外,均为本站原创: 转载自love wife & love life —Roger 的Oracle技术博客
最近做了很多套系统的迁移,大小500G~3T不等,方法差不多,有单机、dataguard、rac。
###### Single instance to rac(3 node)
1. create pfile
此时不用添加rac相关的参数,直接从原库create一份即可。
create pfile='/tmp/pfile.ora' from spfile;
恢复到asm需要修改pfile中control_files参数。
2. Restore controlfile;
rman target /
startup nomount pfile='/tmp/pfile.ora';
set dbid=2820248277;
restore controlfile from '/backup/backup_control.bak';
3. Restore datafiles
---restore_database.sh
rman target / <
4. 拷贝原主库中archivelog到该主机
(此时原生产机还未停止)
11gR2中 如果你archivelog存放在FRA磁盘组中,可以直接使用asmcmd命令进行cp拷贝,如下:
cp +fra/ucp/2012_10_08/thread_1_seq_323.291.796093125 /arch/thread_1_seq_323.291.796093125
cp +fra/ucp/2012_10_08/thread_1_seq_324.293.796094275 /arch/thread_1_seq_324.293.796094275
cp +fra/ucp/2012_10_08/thread_1_seq_325.294.796096147 /arch/thread_1_seq_325.294.796096147
cp +fra/ucp/2012_10_08/thread_1_seq_326.296.796100409 /arch/thread_1_seq_326.296.796100409
cp +fra/ucp/2012_10_08/thread_1_seq_327.297.796103579 /arch/thread_1_seq_327.297.796103579
cp +fra/ucp/2012_10_08/thread_1_seq_328.298.796106599 /arch/thread_1_seq_328.298.796106599
cp +fra/ucp/2012_10_08/thread_1_seq_329.299.796107497 /arch/thread_1_seq_329.299.796107497
cp +fra/ucp/2012_10_08/thread_1_seq_330.300.796108397 /arch/thread_1_seq_330.300.796108397
cp +fra/ucp/2012_10_08/thread_1_seq_331.301.796109067 /arch/thread_1_seq_331.301.796109067
5. Register archivelog
alter database register physical logfile '/arch/thread_1_seq_322.290.796091183';
alter database register physical logfile '/arch/thread_1_seq_323.291.796093125';
alter database register physical logfile '/arch/thread_1_seq_325.294.796096147';
alter database register physical logfile '/arch/thread_1_seq_326.296.796100409';
alter database register physical logfile '/arch/thread_1_seq_327.297.796103579';
alter database register physical logfile '/arch/thread_1_seq_328.298.796106599';
alter database register physical logfile '/arch/thread_1_seq_329.299.796107497';
alter database register physical logfile '/arch/thread_1_seq_330.300.796108397';
alter database register physical logfile '/arch/thread_1_seq_331.301.796109067';
当然你也可以使用更简单如下命令来注册archivelog:
rman target /
catalog start with '/arch';
6. Recover database
rman target /
recover database;
7. 第一次recover完成以后,由于我们业务系统还在运行,可能后面又会产生一些archivelog。
在该步骤停止业务系统,同时停库,停监听。
SQLPLUS > alter system checkpoint;
SQLPLUS > alter system switch logfile;
SQLPLUS > alter system switch logfile;
SQLPLUS > shutdown immediate
lsnrctl stop
8. 追加archivelog,进行recover。
拷贝上面第7步骤原生产库产生的archivelog,到恢复主机上,进行注册。
这样我们再进行recover,最后open数据库,这样可以最大程度的减少停机时间,速度快的话
保持在10~30分钟是没有任何问题的。
9. rename redo logfiles
alter database rename file '/dev/raw/raw7' to '+DATA/ucp/onlinelog/redo1_1';
alter database rename file '/dev/raw/raw12' to '+DATA/ucp/onlinelog/redo1_2';
alter database rename file '/dev/raw/raw8' to '+DATA/ucp/onlinelog/redo2_1';
alter database rename file '/dev/raw/raw13' to '+DATA/ucp/onlinelog/redo2_2';
alter database rename file '/dev/raw/raw9' to '+DATA/ucp/onlinelog/redo3_1';
alter database rename file '/dev/raw/raw14' to '+DATA/ucp/onlinelog/redo3_2';
alter database rename file '/dev/raw/raw10' to '+DATA/ucp/onlinelog/redo4_1';
alter database rename file '/dev/raw/raw15' to '+DATA/ucp/onlinelog/redo4_2';
alter database rename file '/dev/raw/raw11' to '+DATA/ucp/onlinelog/redo5_1';
alter database rename file '/dev/raw/raw16' to '+DATA/ucp/onlinelog/redo5_2';
alter database rename file '/dev/raw/raw17' to '+DATA/ucp/onlinelog/redo6_1';
alter database rename file '/dev/raw/raw22' to '+DATA/ucp/onlinelog/redo6_2'
10. Check checkpoint_change#是否一致
select max(checkpoint_change#) from v$datafile_header;
select min(checkpoint_change#) from v$datafile_header;
11. open resetlogs打开数据库
SQLPLUS > alter database open resetlogs;
说明:
1) 使用backup controlfile进行恢复,正常情况下必须以open resetlogs方式打开,即使你把原库的redo拷贝过来进行恢复也一样;
2) 如果想noresetlogs open数据库,唯一的方式就是重建controlfile,以noresetlogs方式重建即可。
3) 上面的open resetlogs操作会重建redo,tempfile,所以你观察alert log中出现一些相关的错误,可以忽略掉。
12. Create rac redo logfile
alter database add logfile thread 2 group 6 size 512m;
alter database add logfile thread 2 group 7 size 512m;
alter database add logfile thread 2 group 8 size 512m;
alter database add logfile thread 2 group 9 size 512m;
alter database add logfile thread 2 group 10 size 512m;
alter database add logfile thread 3 group 11 size 512m;
alter database add logfile thread 3 group 12 size 512m;
alter database add logfile thread 3 group 13 size 512m;
alter database add logfile thread 3 group 14 size 512m;
alter database add logfile thread 3 group 15 size 512m;
13. Create undo tablespace
create undo tablespace undotbs2 datafile '+DATA' size 20480m autoextend off;
create undo tablespace undotbs3 datafile '+DATA' size 20480m autoextend off;
14. create spfile
SQLPLUS > create spfile from pfile='/tmp/pfile.ora';
SQLPLUS > shutdown immediate
SQLPLUS > startup mount
15. Modify cluster parameters
alter system set cluster_database=true scope=spfile;
alter system set cluster_database_instances = 3 scope = spfile;
alter system set instance_number=1 scope=spfile sid='UCP1';
alter system set instance_number=2 scope=spfile sid='UCP2';
alter system set instance_number=3 scope=spfile sid='UCP3';
16. Restart instance
export ORACLE_SID=UCP3
sqlplus "/as sysdba"
shutdown immediate;
startup
17. 根据该rac实例spfile,创建pfile,用于启动其他2个rac 节点
sqlplus "/as sysdba"
create pfile='/tmp/pfile.ora' from spfile;
19. 启动剩余的2个rac 实例
20. 修改undo_tablespace
alter system set undo_tablespace=undotbs1 scope=both sid='UCP1';
alter system set undo_tablespace=undotbs2 scope=both sid='UCP2';
alter system set undo_tablespace=undotbs3 scope=both sid='UCP3';
21. 注册数据库实例到crs中
srvctl add database -d UCP -o $ORACLE_HOME
srvctl add instance -d UCP -i UCP1 -n node1
srvctl add instance -d UCP -i UCP2 -n node2
srvctl add instance -d UCP -i UCP3 -n node3
22. 配置listener.ora、tnsnames.ora
23. 启动listener,测试业务.
说明:本来还是从10gR2 rac(raw)开始恢复,然后到10g单实例asm(该节点已经安装好11gR2 grid和db,但是我tar了10g的 $ORACLE_HOME,使用10g创建了asm diskgroup),然后直接升级到11gR2,最后再从该11gR2单节点恢复到另外一个3节点的11gR2 rac中。
由于第一次操作完成后,即升级完成之后,最后主机重启出现故障,无法启动,故作罢。最后可以花了将近10个小时的时间直接从10g中exp导入到11gR2中,后面我接着从11gR2 恢复到3节点rac。
中间省略了很多的内容,不过大体上思路都差不多,没有什么复杂的东西,故不做过多描述。
--------------------------------------ORACLE-DBA----------------------------------------
最权威、专业的Oracle案例资源汇总之【案例】Oracle数据库500G~3T大小迁移 详细方法步骤