使用RMAN将数据库迁移到ASM实例

1、修改spfile参数,添加如下参数

DB_CREATE_FILE_DEST=’+DATA’
DB_RECOVERY_FILE_DEST=’+RECOVERY’
DB_RECOVERY_FILE_DEST_SIZE=3g
DB_CREATE_ONLINE_LOG_DEST_1=DGLOG1
DB_CREATE_ONLINE_LOG_DEST_2=DGLOG2

如上参数,需要动态设置如下参数,由spfile生成pfile,然后删除控制文件信息,再有pfile生成spfile,达到动态修改spfile文件的目的。

sqlplus /nolog
conn / as sysdba
startup
SQL> alter system set db_create_file_dest='+DATA' scope=both;
SQL> alter system set db_recovery_file_dest='+RECOVERY' scope=both;
SQL> alter system set db_recovery_file_dest_size=3G;
SQL> alter system set db_create_online_log_dest_1='+DGLOG1' scope=both;
SQL> alter system set db_create_online_log_dest_2='+DGLOG2' scope=both;

2、把控制文件迁移到ASM

SQL> create pfile='/oracle/initmyrac1.ora' from spfile;

删除pfile内的控制文件参数,关闭数据库

SQL> shutdown immediate;
SQL> create spfile from pfile='/oracle/initmyrac1.ora';

启动数据库到nomount阶段,使用RMAN恢复控制文件到新的ASM磁盘位置

rman target /
RMAN> restore controlfile from '/oracle/oradata/myrac1/control01.ctl';

将数据库切换到mount

RMAN> alter database mount;

3、将数据库文件复制到ASM磁盘

RMAN> backup as copy database format '+DATA';

将所有的数据文件转换到ASM磁盘组+DATA中

RMAN> switch database to copy
RMAN> alter database open;

4、将重做日志迁移到ASM磁盘组

首先,我们先确认当前系统日志文件的位置

select group#,member from v$logfile;

进入RMAN,由上面的语句获取组号

RMAN> sql "alter database add logfile member '+DGLOG1','+DGLOG2' to group 1";
RMAN> sql "alter database add logfile member '+DGLOG1','+DGLOG2' to group 2";

删除原来的重做日志,在删除之前必须保证该日志文件不是当前正在使用的日志组
通过alter system switch logfile来切换日志组

SQL> alter database drop logfile member '/oracle/oradata/myrac1/redo01.log';
SQL> alter database drop logfile member '/oracle/oradata/myrac1/redo02.log';

5、临时表空间建立

在ASM磁盘组中创建临时文件,因为RMAN不会迁移临时文件,需要在ASM磁盘组中手动创建一个临时表空间。

select ts#,name from v$tempfile;
select ts#,name from v$tablespace where ts#=3;
RMAN> sql "alter tablespace temp add tempfile size 1024m";

删除旧的临时文件

RMAN> sql "alter database tempfile '/oracle/oradata/myrac1/temp01.dbf' drop";

附录:
ASM相关的视图

v$asm_diskgroup
v$adm_disk
v$asm_file
v$asm_alias
v$asm_template
v$asm_client