有关如何创建ASM实例及ASM磁盘管理请参考
Linux Oracle10gR2 创建ASM实例安装数据库
一、主要步骤(假定ASM实例已创建)
1.计算目标数据库(文件系统)的大小
2.根据目标数据库的大小,为新ASM数据库(辅助数据库)准备可用磁盘空间
3.为辅助数据库配置初始化参数文件,密码文件,创建目录
4.备份目标数据库
5.迁移目标数据库到辅助数据库
二、实施迁移
本次迁移在同一台主机实现,因此采用不同的ORACLE_SID
环境:Oracle Linux 5.4 + Oracle 10g R2
目标数据库:orcl
辅助数据库:orclasm
1.计算目标数据库(文件系统)的大小
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string orcl
SQL> select * from v$version where rownum select sum(bytes)/1024/1024 ||'MB' from dba_segments;
SUM(BYTES)/1024/1024||'MB'
------------------------------------------
1195.5MB
2.为辅助数据库准备可用空间,下面显示DG1中有3016MB可用空间,可以满足迁移的需要
ASMCMD> ls -s
Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Name
512 4096 1048576 6134 6032 0 3016 0 DG1/
512 4096 1048576 2047 1997 0 1997 0 REV/
3.配置辅助数据库
a.启动目标数据库,并为目标数据库创建pfile
[oracle@oradb ~]$ echo $ORACLE_SID
orcl
[oracle@oradb ~]$ sqlplus / as sysdba
idle> startup
sys@ORCL> create pfile from spfile;
b.复制目标数据库的pfile来生成辅助数据库的pfile并对其进行修改
[oracle@oradb dbs]$ cd $ORACLE_HOME/dbs
[oracle@oradb dbs]$ cp initorcl.ora initorclasm.ora
修改initorclasm.ora
对文件中所有的orcl使用替换命令替换为orclasm(使用vi工具 :%s/orcl/orclasm/g来替换)
修改控制文件为1个(磁盘DG1使用了normal redundancy),路径为'+DG1/orclasm/controlfile/'--使用ASM应注意目录结构的变化
修改db_recovery_file_dest路径为'+REV'
修改log_archive_dest_1路径为'LOCATION=+REV/orclasm'
修改db_create_file_dest路径为'+DG1'
增加下列参数(恢复完毕后清除)
*.db_file_name_convert=("orcl","orclasm")
*.log_file_name_convert=("orcl","orclasm")
下面列出发生变化的几个重要参数
*.audit_file_dest='/u01/app/oracle/admin/orclasm/adump'
*.background_dump_dest='/u01/app/oracle/admin/orclasm/bdump'
*.control_files='+DG1/orclasm/controlfile/control01.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orclasm/cdump'
*.db_name='orclasm'
*.db_recovery_file_dest='+REV/orclasm'
*.log_archive_dest_1='LOCATION=+REV/orclasm'
*.user_dump_dest='/u01/app/oracle/admin/orclasm/udump'
*.db_create_file_dest='+DG1'
*.db_file_name_convert=("orcl","orclasm")
*.log_file_name_convert=("orcl","orclasm")
c.根据刚刚修改过的参数创建目录
[oracle@oradb ~]$ mkdir -p $ORACLE_BASE/admin/orclasm/{a,b,c,u}dump
[oracle@oradb ~]$ ls $ORACLE_BASE/admin/orclasm
adump bdump cdump udump
d.创建密码文件
[oracle@oradb dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworclasm password=oracle entries=8
4.备份目标数据库
a.目标数据库应处于归档模式下
SQL> select name,log_mode from v$database;
NAME LOG_MODE
--------- ------------
ORCL ARCHIVELOG
b.连接到RMAN并进行备份,此处使用了非catalog方式
[oracle@oradb ~]$ uniread rman target sys/oracle@orcl nocatalog
RMAN> crosscheck archivelog all; --校验归档日志
RMAN> delete expired archivelog all; --删除无效的归档日志
RMAN> report obsolete;
RMAN> delete noprompt obsolete; --删除废弃的备份
RMAN> show channel; --查看缺省的备份路径
RMAN configuration parameters are:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/bk/orcl/data_%d_%U';
RMAN> show controlfile autobackup; --查看控制文件的自动备份启用情况
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> show controlfile autobackup format; --查看控制文件的备份路径、格式
RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/bk/orcl/auto_ctl_%d_%F';
RMAN> run{ --对目标数据库进行备份,此备份为0级增量包含了归档日志,控制文件spfile将自动备份
2> allocate channel ch1 device type disk;
3> backup as compressed backupset
4> incremental level 0 database format '/u01/bk/orcl/data_%d_%U'
5> plus archivelog format '/u01/bk/orcl/bk_lg_%U'
6> tag='Inc0_log';
7> release channel ch1;}
5.迁移目标数据到ASM
a.查看目标数据库的SEQUENCE,当前为10,便于恢复时指定SEQUENCE
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 9 52428800 1 YES ACTIVE 520445 30-OCT-10
2 1 10 52428800 1 NO CURRENT 520585 30-OCT-10
b.查看目标数据库的数据文件的相关信息,后续需要为datafile指定文件名
RMAN> report schema;
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 480 SYSTEM *** /u01/app/oracle/oradata/orcl/system01.dbf
2 25 UNDOTBS1 *** /u01/app/oracle/oradata/orcl/undotbs01.dbf
3 240 SYSAUX *** /u01/app/oracle/oradata/orcl/sysaux01.dbf
4 5 USERS *** /u01/app/oracle/oradata/orcl/users01.dbf
5 100 EXAMPLE *** /u01/app/oracle/oradata/orcl/example01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 /u01/app/oracle/oradata/orcl/temp01.dbf
c.查看asm实例是否已正常提供服务,以及磁盘的状态并启动新的orclasm实例
SQL> show parameter instance_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string +ASM
SQL> select group_number,name,state,type,total_mb,free_mb,usable_file_mb from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TYPE TOTAL_MB FREE_MB USABLE_FILE_MB
------------ ------------------------------ ----------- ------ ---------- ---------- --------------
1 DG1 MOUNTED NORMAL 6134 6032 3016
2 REV MOUNTED EXTERN 2047 1997 1997
d.启动辅助数据库到nomount状态
[oracle@oradb ~]$ export ORACLE_SID=orclasm
[oracle@oradb ~]$ sqlplus / as sysdba
idle> startup nomount
ORACLE instance started.
e.使用RMAN连接到目标数据库和辅助数据库来完成迁移
[oracle@oradb dbs]$ rman auxiliary / target sys/RedHat@orcl
connected to target database: ORCL (DBID=1263182651)
connected to auxiliary database: ORCLASM (not mounted)
RMAN> run {
2> allocate auxiliary channel ach1 device type disk;
3> set until sequence 10 thread 1;
4> set newname for datafile 1 to '+DG1';
5> set newname for datafile 2 to '+DG1';
6> set newname for datafile 3 to '+DG1';
7> set newname for datafile 4 to '+DG1';
8> set newname for datafile 5 to '+DG1';
9> set newname for tempfile 1 to '+DG1';
10> duplicate target database to orclasm logfile
11> group 1('+DG1') size 5m reuse,
12> group 2('+DG1') size 5m reuse;
13> }
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 30-OCT-10