环境:RHEL 6.4 + Oracle 11.2.0.4
需求:数据库存储由文件系统迁移到ASM
数据库存储迁移到ASM磁盘组
Reference
实验环境前期准备:
迁移前原数据库各文件存储信息查询如下:
--控制文件
select name from v$controlfile;
--数据文件
select name from v$datafile;
--临时文件
select name from v$tempfile;
--日志文件
select member from v$logfile;
--参数文件
show parameter pfile
--查询结果如下
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u02/oradata/jingyu/control01.ctl
/u02/app/oracle/fast_recovery_area/jingyu/control02.ctl
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u02/oradata/jingyu/system01.dbf
/u02/oradata/jingyu/sysaux01.dbf
/u02/oradata/jingyu/undotbs01.dbf
/u02/oradata/jingyu/users01.dbf
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u02/oradata/jingyu/temp01.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u02/oradata/jingyu/redo03.log
/u02/oradata/jingyu/redo02.log
/u02/oradata/jingyu/redo01.log
SQL> show parameter pfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u02/app/oracle/product/11.2.0
/dbhome_1/dbs/spfilejingyu.ora
SQL> create pfile='/tmp/pfile.ora' from spfile;
SQL> shutdown immediate
-- 修改controlfile参数值
$ vi /tmp/pfile.ora
controlfile='+DATA1/control01.ctl'
SQL> startup nomount pfile='/tmp/pfile.ora'
注意Oracle用户需要有读写ASM磁盘的权限
RMAN> restore controlfile from '/u02/oradata/jingyu/control01.ctl';
RMAN> alter database mount;
RMAN> backup as copy database format '+DATA1';
RMAN> switch database to copy;
RMAN> run {
set newname for tempfile 1 to '+DATA1';
switch tempfile all;
}
RMAN> ALTER DATABASE OPEN;
set linesize 200
col member for a60
SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;
SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA1' TO GROUP 1;
SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA1' TO GROUP 2;
SQL> ALTER DATABASE ADD LOGFILE MEMBER '+DATA1' TO GROUP 3;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u02/oradata/jingyu/redo01.log';
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u02/oradata/jingyu/redo02.log';
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u02/oradata/jingyu/redo03.log';
SQL> ALTER SYSTEM CHECKPOINT;
SQL> SELECT a.group#, b.member, a.status FROM v$log a, v$logfile b WHERE a.group#=b.group#;
-- 在ASM磁盘组中创建服务器参数文件
SQL> create spfile='+DATA1' from pfile='/tmp/pfile.ora';
-- 正常关闭数据库
SQL> shutdown immediate
-- 删除$ORACLE_HOME/dbs/spfilejingyu.ora
$ rm $ORACLE_HOME/dbs/spfilejingyu.ora
-- 建立$ORACLE_HOME/dbs/initjingyu.ora,编辑内容指定ASM磁盘组中的服务器参数文件。
$ vi initjingyu.ora
spfile='+DATA1/JINGYU/PARAMETERFILE/spfile.266.897474951'
--启动数据库(会自动找到参数文件进而转到ASM磁盘组中的服务器参数文件)
SQL> startup
select name from v$datafile union all
select name from v$tempfile union all
select member from v$logfile union all
select name from v$controlfile;
show parameter pfile
结果如下:
SQL> select name from v$datafile union all
2 select name from v$tempfile union all
3 select member from v$logfile union all
4 select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
+DATA1/jingyu/datafile/system.257.897474123
+DATA1/jingyu/datafile/sysaux.258.897474149
+DATA1/jingyu/datafile/undotbs1.259.897474165
+DATA1/jingyu/datafile/users.261.897474169
+DATA1/jingyu/tempfile/temp.262.897474267
+DATA1/jingyu/onlinelog/group_1.263.897474349
+DATA1/jingyu/onlinelog/group_2.264.897474359
+DATA1/jingyu/onlinelog/group_3.265.897474363
+DATA1/control01.ctl
9 rows selected.
Elapsed: 00:00:00.02
SQL> show parameter pfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA1/jingyu/parameterfile/sp
file.266.897474951
至此,数据库存储已经成功由文件系统全部迁移到ASM。