实验环境:WinXP SP2
数据库版本:10.2.0.1
准备迁移的数据库实例名:TEST
ASM实例名:+ASM
ASM磁盘组:+TEST
创建ASM实例和磁盘组的步骤这里不再重复,请参考:http://space.itpub.net/498744/viewspace-247789
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/WINDOWS>set ORACLE_SID=test
C:/WINDOWS>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 27 20:56:54 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With thePartitioning, OLAPand Data Mining options
1、修改参数文件中的control_files参数,指向ASM
TEST>show parameter control
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL01.CTL, F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL02.CTL, F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL03.CTL
TEST>alter system set control_files ='+test/test/control01.ctl' scope=spfile;
System altered.
修改完成后关闭数据库
TEST>shut immediate
2、使用RMAN将controlfile迁移至ASM
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/WINDOWS>rmantarget=sys/oracle@test
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Mar 27 20:58:22 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)
RMAN> startup nomount
Oracle instance started
Total System Global Area 209715200 bytes
Fixed Size 1248116 bytes
Variable Size 71304332 bytes
Database Buffers 130023424 bytes
Redo Buffers 7139328 bytes
RMAN> restore controlfile from 'F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL01.CTL';
Starting restore at 27-MAR-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 03/27/2008 21:02:46
ORA-19504: failed to create file "+TEST/test/control01.ctl"
ORA-17502: ksfdcre:3 Failed to create file +TEST/test/control01.ctl
ORA-15001: diskgroup "TEST" does not exist or is not mounted
ORA-15077: could not locate ASM instance serving a required diskgroup
ORA-19600: input file is control file (F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL01.CTL)
ORA-19601: output file is control file (+TEST/test/control01.ctl)
出现了错误:提示磁盘组TEST不存在,连入ASM实例看看为什么
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/WINDOWS>set ORACLE_SID=+asm
C:/WINDOWS>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 27 21:04:33 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
原来是上次做试验,把磁盘组删除后没有重建-.-!
+ASM>select * from v$asm_diskgroup;
no rows selected
重新建立磁盘组
+ASM>create diskgroup test normal redundancy
2 failgroup controller1 disk 'H:/asmDISKS/_FILE_DISK1','H:/asmDISKS/_FILE_DISK2'
3 failgroup controller2 disk 'H:/asmDISKS/_FILE_DISK3','H:/asmDISKS/_FILE_DISK4';
Diskgroup created.
回到RMAN中,再次执行成功
RMAN> restore controlfile from 'F:/ORACLE/PRODUCT/ORADATA/TEST/CONTROL01.CTL';
Starting restore at 27-MAR-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: copied control file copy
output filename=+TEST/test/control01.ctl
Finished restore at 27-MAR-08
这时候control file已经迁移成功,启动至mount
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
3、备份全部数据文件到ASM
RMAN> backup as copy database format '+test';
Starting backup at 27-MAR-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=152 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=F:/ORACLE/PRODUCT/ORADATA/TEST/SYSTEM01.DBF
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 03/27/2008 21:07:21
ORA-19504: failed to create file "+TEST"
ORA-17502: ksfdcre:4 Failed to create file +TEST
ORA-15041: diskgroup space exhausted
出现错误:提示磁盘组的空间不足,磁盘组用的是4个200m的模拟磁盘,又使用了normal redundancy冗余模式,造成了空间不足,(尝试将冗余模式改为extenal redundancy也不够),再添加4块200m的模拟磁盘
+ASM>alter diskgroup test add disk 'H:/asmDISKS/_FILE_DISK5','H:/asmDISKS/_FILE_DISK6','H:/asmDISKS/_FILE_DISK7','H:/asmDISKS/_FILE_DISK8';
Diskgroup altered.
可以看到添加磁盘后,ASM实例自动进行了rebalance
+ASM>select * from v$asm_operation;
GROUP_NUMBER OPERATION STATE POWER ACTUAL SOFAR EST_WORK EST_RATE EST_MINUTES
------------ ---------- -------- ---------- ---------- ---------- ---------- ---------- -----------
1 REBAL RUN 1 1 1 226 0 0
再次备份整个数据库到ASM,成功完成
RMAN> backup as copy database format '+test';
Starting backup at 27-MAR-08
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=F:/ORACLE/PRODUCT/ORADATA/TEST/SYSTEM01.DBF
output filename=+TEST/test/datafile/system.258.650496175 tag=TAG20080327T212252 recid=3 stamp=650496208
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=F:/ORACLE/PRODUCT/ORADATA/TEST/SYSAUX01.DBF
output filename=+TEST/test/datafile/sysaux.257.650496219 tag=TAG20080327T212252 recid=4 stamp=650496238
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=F:/ORACLE/PRODUCT/ORADATA/TEST/UNDOTBS01.DBF
output filename=+TEST/test/datafile/undotbs1.259.650496245 tag=TAG20080327T212252 recid=5 stamp=650496246
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=F:/ORACLE/PRODUCT/ORADATA/TEST/USERS01.DBF
output filename=+TEST/test/datafile/users.260.650496247 tag=TAG20080327T212252 recid=6 stamp=650496248
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=+TEST/test/controlfile/backup.261.650496251 tag=TAG20080327T212252 recid=7 stamp=650496252
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=F:/ORACLE/PRODUCT/ORADATA/TEST/TEST_BIG.DBF
output filename=+TEST/test/datafile/test_big.262.650496255 tag=TAG20080327T212252 recid=8 stamp=650496254
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 27-MAR-08
channel ORA_DISK_1: finished piece 1 at 27-MAR-08
piece handle=+TEST/test/backupset/2008_03_27/nnsnf0_tag20080327t212252_0.263.650496257 tag=TAG20080327T212252 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 27-MAR-08
4、使用10g的新特性,切换数据库到刚才备份到ASM的备份上,至此datafile和controlfile的迁移已经完成了
RMAN> switch database to copy;
datafile 1 switched to datafile copy "+TEST/test/datafile/system.258.650496175"
datafile 2 switched to datafile copy "+TEST/test/datafile/undotbs1.259.650496245"
datafile 3 switched to datafile copy "+TEST/test/datafile/sysaux.257.650496219"
datafile 4 switched to datafile copy "+TEST/test/datafile/users.260.650496247"
datafile 5 switched to datafile copy "+TEST/test/datafile/test_big.262.650496255"
RMAN>
5、Redo log还在文件系统上,也需要进行迁移
TEST>alter database open;
Database altered.
在ASM中建立3组新的redo log
TEST>alter database add logfile group 4 '+test/redo04.log' size 10m;
Database altered.
TEST>alter database add logfile group 5 '+test/redo05.log' size 10m;
Database altered.
TEST>alter database add logfile group 6 '+test/redo06.log' size 10m;
Database altered.
查看6组redolog的状态,可以看到当前使用的是第3组
TEST>select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
3 CURRENT
4 UNUSED
5 UNUSED
6 UNUSED
因为要删除1-3组redolog,先进行redo log的切换
TEST>alter system switch logfile;
System altered.
TEST>/
System altered.
TEST>/
System altered.
可以看到当前使用的是第6组
TEST>select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 ACTIVE
2 INACTIVE
3 INACTIVE
4 ACTIVE
5 ACTIVE
6 CURRENT
但是第1组redo log的状态仍然为ACTIVE,手工执行一次checkpoing
TEST>alter system checkpoint;
1-5组redo log的状态都为INACTIVE了
TEST>select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
3 INACTIVE
4 INACTIVE
5 INACTIVE
6 CURRENT
删除1-3组redo log
TEST>alter database drop logfile group 1;
Database altered.
TEST>alter database drop logfile group 2;
Database altered.
TEST>alter database drop logfile group 3;
Database altered.
6、目前临时表空间也还在文件系统上,也需要进行迁移
查看目前数据库中tempfile的位置
TEST>select file_name,tablespace_name from dba_temp_files;
FILE_NAME TABLESPACE_NAME
--------------------------------------------- -----------------------
F:/ORACLE/PRODUCT/ORADATA/TEST/TEMP01.DBF TEMP
在temp表空间中新添加一个在ASM中的tempfile
TEST>alter tablespace temp add tempfile '+test/temp01.dbf' size 30m;
Tablespace altered.
删除原来在文件系统中的tempfile
TEST>alter tablespace temp drop tempfile 'F:/ORACLE/PRODUCT/ORADATA/TEST/TEMP01.DBF';
Tablespace altered.
7、目前系统只有一个controlfile,为了保证系统的安全性,再添加一个controlfile
TEST>shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
idle>startup mount
ORACLE instance started.
Total System Global Area 209715200 bytes
Fixed Size 1248116 bytes
Variable Size 71304332 bytes
Database Buffers 130023424 bytes
Redo Buffers 7139328 bytes
Database mounted.
将controlfile备份到ASM中(和目前的controlfile是一样的,可以直接使用)
TEST>alter database backup controlfile to '+test';
Database altered.
修改参数文件中的control_files参数
TEST>show parameter control
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string +TEST/test/control01.ctl
TEST>alter system set control_files='+TEST/test/control01.ctl','+TEST/test/control02.ctl' scope=spfile;
System altered.
使用asmcmd给备份至ASM的controlfile起个别名,以方便使用
C:/WINDOWS>set ORACLE_HOME=F:/oracle/product/10.2.0
C:/WINDOWS>set ORACLE_SID=+asm
C:/WINDOWS>asmcmd
ASMCMD> ls
BACKUPSET/
CONTROLFILE/
DATAFILE/
ONLINELOG/
TEMPFILE/
control01.ctl
ASMCMD> cd controlfile
ASMCMD> ls -l
Type Redund Striped Time Sys Name
CONTROLFILE UNPROT FINE MAR 27 22:00:00 Y Backup.268.650498443
CONTROLFILE UNPROT FINE MAR 27 22:00:00 Y backup.256.650495709
ASMCMD> mkalias +TEST/TEST/CONTROLFILE/Backup.268.650498443 control02.ctl
ASMCMD> ls -l
Type Redund Striped Time Sys Name
Y BACKUPSET/
Y CONTROLFILE/
Y DATAFILE/
Y ONLINELOG/
Y TEMPFILE/
N control01.ctl => +TEST/TEST/CONTROLFILE/backup.256.650495709
N control02.ctl => +TEST/TEST/CONTROLFILE/Backup.268.650498443
ASMCMD>
8、重启数据,整个数据库已成功迁移至ASM
TEST>startup force
ORACLE instance started.
Total System Global Area 209715200 bytes
Fixed Size 1248116 bytes
Variable Size 71304332 bytes
Database Buffers 130023424 bytes
Redo Buffers 7139328 bytes
Database mounted.
Database opened.