asm下表空间的重命名与普通文件系统下的表空间重命名原理是一样的,只不过asm管理的数据文件有一些需要注意的地方,另外在asm下操作数据文件需要格外小心,稍有不慎将会造成数据文件丢失,如可以做备份最好需要备份。
需求:公司rac数据库asm存储原本采用normal模式,现在给数据库做了备份策略,不想在使用normal模式的asm管理,这样日常管理太浪费时间,为了平滑迁移,我新添加了一个磁盘组oradata,把日后增加的数据文件首先添加到oradata磁盘组下,然后没有业务发生时再去迁移原始数据。
实施步骤:
1、原始文件存储data磁盘组:
ASMCMD [+data/orcl/datafile] > ls -l
Type Redund Striped Time Sys Name
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.268.907265611
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.269.911467049
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.270.911467085
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.271.913894971
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.272.915559085
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y EFMIS.273.915613859
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y SYSAUX.257.907264709
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y SYSTEM.256.907264709
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y UNDOTBS1.258.907264709
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y UNDOTBS2.264.907264867
DATAFILE MIRROR COARSE JUN 27 14:00:00 Y USERS.259.907264709
N efmis01.dbf => +DATA/ORCL/DATAFILE/EFMIS.268.907265611
N efmis02.dbf => +DATA/ORCL/DATAFILE/EFMIS.269.911467049
N efmis03.dbf => +DATA/ORCL/DATAFILE/EFMIS.270.911467085
N efmis04.dbf => +DATA/ORCL/DATAFILE/EFMIS.271.913894971
N efmis05.dbf => +DATA/ORCL/DATAFILE/EFMIS.272.915559085
N efmis06.dbf => +DATA/ORCL/DATAFILE/EFMIS.273.915613859
2、目标文件存储oradata磁盘组:
ASMCMD [+oradata/orcl/datafile] > ls -l
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE JUN 27 22:00:00 Y EFMIS.256.915634603
DATAFILE UNPROT COARSE JUN 27 22:00:00 Y EFMIS.257.915634643
DATAFILE UNPROT COARSE JUN 27 22:00:00 Y EFMIS.258.915634663
DATAFILE UNPROT COARSE JUN 27 22:00:00 Y EFMIS.259.915634679
N efmis07.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.256.915634603
N efmis08.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.257.915634643
N efmis09.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.258.915634663
N efmis10.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.259.915634679
3、这里需要将data磁盘组下的efmis数据表空间下的文件都迁移到oradata下:
1)首先关闭数据库:
[grid@node2 ~]$ serctl stop database -d orcl
2)启动数据库一个节点实例到mount状态(也可以open下迁移数据,这里因为数据库暂时不会发生业务,所以直接在mount下迁移)并查询数据库数据文件组成:
[oracle@node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jun 27 22:28:42 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 1073742728 bytes
Database Buffers 3187671040 bytes
Redo Buffers 12107776 bytes
Database mounted.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/orcl/datafile/system.256.907264709
+DATA/orcl/datafile/sysaux.257.907264709
+DATA/orcl/datafile/undotbs1.258.907264709
+DATA/orcl/datafile/users.259.907264709
+DATA/orcl/datafile/undotbs2.264.907264867
+DATA/orcl/datafile/efmis01.dbf
+DATA/orcl/datafile/efmis02.dbf
+DATA/orcl/datafile/efmis03.dbf
+DATA/orcl/datafile/efmis04.dbf
+DATA/orcl/datafile/efmis05.dbf
+DATA/orcl/datafile/efmis06.dbf
+ORADATA/orcl/datafile/efmis07.dbf
+ORADATA/orcl/datafile/efmis08.dbf
+ORADATA/orcl/datafile/efmis09.dbf
+ORADATA/orcl/datafile/efmis10.dbf
15 rows selected.
3)asm上迁移物理文件:
ASMCMD [+data/orcl/datafile] > cp +DATA/ORCL/DATAFILE/EFMIS.273.915613859 +ORADATA/ORCL/DATAFILE/efmis06.dbf
copying +DATA/ORCL/DATAFILE/EFMIS.273.915613859 -> +ORADATA/ORCL/DATAFILE/efmis06.dbf
ASMCMD [+data/orcl/datafile] > cp +DATA/ORCL/DATAFILE/EFMIS.272.915559085 +ORADATA/ORCL/DATAFILE/efmis05.dbf
copying +DATA/ORCL/DATAFILE/EFMIS.272.915559085 -> +ORADATA/ORCL/DATAFILE/efmis05.dbf
ASMCMD [+data/orcl/datafile] > cp +DATA/ORCL/DATAFILE/EFMIS.271.913894971 +ORADATA/ORCL/DATAFILE/efmis04.dbf
copying +DATA/ORCL/DATAFILE/EFMIS.271.913894971 -> +ORADATA/ORCL/DATAFILE/efmis04.dbf
ASMCMD [+data/orcl/datafile] > cp +DATA/orcl/datafile/EFMIS.270.911467085 +ORADATA/orcl/datafile/efmis03.dbf
copying +DATA/orcl/datafile/EFMIS.270.911467085 -> +ORADATA/orcl/datafile/efmis03.dbf
ASMCMD [+data/orcl/datafile] > cp +DATA/ORCL/DATAFILE/EFMIS.269.911467049 +ORADATA/ORCL/DATAFILE/efmis02.dbf
copying +DATA/ORCL/DATAFILE/EFMIS.269.911467049 -> +ORADATA/ORCL/DATAFILE/efmis02.dbf
ASMCMD [+data/orcl/datafile] > cp +DATA/ORCL/DATAFILE/EFMIS.268.907265611 +ORADATA/orcl/datafile/efmis01.dbf
copying +DATA/ORCL/DATAFILE/EFMIS.268.907265611 -> +ORADATA/orcl/datafile/efmis01.dbf
ASMCMD [+data/orcl/datafile] > cp USERS.259.907264709 +ORADATA/orcl/datafile/USERS
copying +data/orcl/datafile/USERS.259.907264709 -> +ORADATA/orcl/datafile/USERS
ASMCMD [+oradata/orcl/datafile] > ls -l
Type Redund Striped Time Sys Name
DATAFILE UNPROT COARSE JUN 27 23:00:00 Y EFMIS.256.915634603
DATAFILE UNPROT COARSE JUN 27 23:00:00 Y EFMIS.257.915634643
DATAFILE UNPROT COARSE JUN 27 23:00:00 Y EFMIS.258.915634663
DATAFILE UNPROT COARSE JUN 27 23:00:00 Y EFMIS.259.915634679
N USERS => +ORADATA/ASM/DATAFILE/USERS.266.915663721
N efmis01.dbf => +ORADATA/ASM/DATAFILE/efmis01.dbf.265.915663163
N efmis02.dbf => +ORADATA/ASM/DATAFILE/efmis02.dbf.264.915662267
N efmis03.dbf => +ORADATA/ASM/DATAFILE/efmis03.dbf.263.915662067
N efmis04.dbf => +ORADATA/ASM/DATAFILE/efmis04.dbf.262.915662031
N efmis05.dbf => +ORADATA/ASM/DATAFILE/efmis05.dbf.261.915661983
N efmis06.dbf => +ORADATA/ASM/DATAFILE/efmis06.dbf.260.915661893
N efmis07.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.256.915634603
N efmis08.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.257.915634643
N efmis09.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.258.915634663
N efmis10.dbf => +ORADATA/ORCL/DATAFILE/EFMIS.259.915634679
4)数据库下重命名数据文件:
SQL> alter database rename file '+DATA/orcl/datafile/efmis01.dbf' to '+ORADATA/orcl/datafile/efmis01.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/efmis02.dbf' to '+ORADATA/orcl/datafile/efmis02.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/efmis03.dbf' to '+ORADATA/orcl/datafile/efmis03.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/efmis04.dbf' to '+ORADATA/orcl/datafile/efmis04.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/efmis05.dbf' to '+ORADATA/orcl/datafile/efmis05.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/efmis06.dbf' to '+ORADATA/orcl/datafile/efmis06.dbf';
Database altered.
SQL> alter database rename file '+DATA/orcl/datafile/users.259.907264709' to '+ORADATA/orcl/datafile/USERS';
Database altered.
5)查看迁移后数据文件分布情况:
SQL> SELECT NAME FROM V$DATAFILE;
NAME
--------------------------------------------------------------------------------
+DATA/orcl/datafile/system.256.907264709
+DATA/orcl/datafile/sysaux.257.907264709
+DATA/orcl/datafile/undotbs1.258.907264709
+ORADATA/orcl/datafile/users
+DATA/orcl/datafile/undotbs2.264.907264867
+ORADATA/orcl/datafile/efmis01.dbf
+ORADATA/orcl/datafile/efmis02.dbf
+ORADATA/orcl/datafile/efmis03.dbf
+ORADATA/orcl/datafile/efmis04.dbf
+ORADATA/orcl/datafile/efmis05.dbf
+ORADATA/orcl/datafile/efmis06.dbf
+ORADATA/orcl/datafile/efmis07.dbf
+ORADATA/orcl/datafile/efmis08.dbf
+ORADATA/orcl/datafile/efmis09.dbf
+ORADATA/orcl/datafile/efmis10.dbf
15 rows selected.
6)打开数据库:这里可以成功打开数据库,证明数据文件迁移是没有问题的。
SQL> alter database open;
Database altered.
7)设置grid管理数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
[grid@node2 ~]$ srvctl start database -d orcl
8)查看目前集群软件及数据库运行状态:
[grid@node2 ~]$ crsctl status resource -t
ora.asm
ONLINE ONLINE node1 Started
ONLINE ONLINE node2 Started
ora.orcl.db
1 ONLINE ONLINE node1 Open
2 ONLINE ONLINE node2 Open
ASMCMD [+oradata/orcl/datafile] > lsdg
State Type Total_MB Free_MB Req_mir_free_MB Usable_file_MB Voting_files Name
MOUNTED NORMAL 409592 358082 102398 127842 N DATA/
MOUNTED NORMAL 204796 204126 0 102063 N FLASH/
MOUNTED EXTERN 6134 5736 0 5736 Y GRIDDG/
MOUNTED EXTERN 409594 255077 0 255077 N ORADATA/
SQL> select name,round(total_mb/1024,2),round(free_mb/1024,2) from v$asm_diskgroup;
NAME ROUND(TOTAL_MB/1024,2) ROUND(FREE_MB/1024,2)
-------------------- ---------------------- ------------------------------------------------------------------------------
DATA 399.99 349.69
FLASH 200 199.34
GRIDDG 5.99 5.6
ORADATA 399.99 249.1