使用RMAN迁移文件系统数据库到ASM
--==================================
-- 使用RMAN迁移文件系统数据库到ASM
--==================================
在实际的工作过程中,由于ASM磁盘管理的便利性,因此很多时候需要将文件系统的数据库迁移到ASM,本文演示了如何将文件系统数据库迁移到ASM实例。
有关如何创建ASM实例及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<2;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
SQL> 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
6.后续处理
a.查看数据库状态并关闭数据库
[oracle@oradb ~]$ export ORACLE_SID=orclasm
[oracle@oradb ~]$ sqlplus / as sysdba
SQL> select name,open_mode from v$database;
NAME OPEN_MODE
--------- ----------
ORCLASM READ WRITE
SQL> shutdown immediate;
b.使用vi工具编辑initorclasm.ora
清除下列参数
*.db_file_name_convert=("orcl","orclasm")
*.log_file_name_convert=("orcl","orclasm")
c.启动数据库并创建spfile
SQL> startup
SQL> create spfile from pfile;
SQL> startup force; --如果是生产库建议先shutdown immediate,然后startup
7.验证迁移结果
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string orclasm
SQL> col name format a60
SQL> select name,status from v$datafile;
NAME STATUS
------------------------------------------------------------ -------
+DG1/orclasm/datafile/system.256.752170937 SYSTEM
+DG1/orclasm/datafile/undotbs1.259.752170937 ONLINE
+DG1/orclasm/datafile/sysaux.257.752170937 ONLINE
+DG1/orclasm/datafile/users.260.752170937 ONLINE
+DG1/orclasm/datafile/example.258.752170937 ONLINE
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 5 5242880 2 YES INACTIVE 563716 27-MAY-11
2 1 6 5242880 2 NO CURRENT 583985 27-MAY-11
SQL> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- -------------------------------------------------- ---
2 ONLINE +DG1/orclasm/onlinelog/group_2.263.752171103 NO
1 STALE ONLINE +DG1/orclasm/onlinelog/group_1.262.752171103 NO
1 STALE ONLINE +REV/orclasm/onlinelog/group_1.256.752171103 YES
2 ONLINE +REV/orclasm/onlinelog/group_2.257.752171105 YES
SQL> select file#,creation_change#, status,enabled,bytes,name from v$tempfile;
FILE# CREATION_CHANGE# STATUS ENABLED BYTES NAME
---------- ---------------- ------- ---------- ---------- --------------------------------------------------
1 464714 ONLINE READ WRITE 20971520 +DG1/orclasm/tempfile/temp.264.752171113
--如果在使用duplicate时没有生成tempfile文件,可以使用下面的方式来手动添加tempfile文件。
alter tablespace temp add tempfile '+DG1' size 100m autoextend off;
--可以添加归档目录,并修改一下归档路径
--连接到ASM实例创建归档目录
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
------------------------------ ------------
+ASM STARTED
SQL> alter diskgroup REV add directory '+REV/orclasm/arch';
Diskgroup altered.
--在orclasm实例中修改归档路径
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orclasm OPEN
SQL> alter system set log_archive_dest_1='LOCATION=+REV/orclasm/arch';
System altered.
SQL> select name from v$archived_log where rownum<2 order by stamp;
NAME
--------------------------------------------------
+REV/orclasm/1_1_752171102.arc
三、快捷参考
有关性能优化请参考
有关ORACLE体系结构请参考
Oracle 联机重做日志文件(ONLINE LOG FILE)
Oracle 实例和Oracle数据库(Oracle体系结构)
有关闪回特性请参考
Oracle 闪回特性(FLASHBACK DATABASE)
Oracle 闪回特性(FLASHBACK DROP & RECYCLEBIN)
Oracle 闪回特性(Flashback Query、Flashback Table)
Oracle 闪回特性(Flashback Version、Flashback Transaction)
有关基于用户管理的备份和备份恢复的概念请参考
Oracle 基于用户管理恢复的处理(详细描述了介质恢复及其处理)
有关RMAN的备份恢复与管理请参考
RMAN 备份路径困惑(使用plus archivelog时)
有关ORACLE故障请参考
对参数FAST_START_MTTR_TARGET = 0 的误解及设定
有关ASM请参考
有关SQL/PLSQL请参考
SQL 基础--> 集合运算(UNION 与UNION ALL)
SQL 基础--> 层次化查询(START BY ... CONNECT BY PRIOR)
SQL 基础--> ROLLUP与CUBE运算符实现数据汇总
有关ORACLE其它特性
使用OEM,SQL*Plus,iSQL*Plus 管理Oracle实例
日志记录模式(LOGGING 、FORCE LOGGING 、NOLOGGING)
使用外部表管理Oracle 告警日志(ALAERT_$SID.LOG)
簇表及簇表管理(Index clustered tables)
ORACLE_SID、DB_NAME、INSTANCE_NAME、DB_DOMIAN、GLOBAL_NAME