OS文件系统数据文件迁移至磁盘组(ASM)

Posted by Harid七月 - 6 - 2014 Leave comments

首先在文件系统里面创建一个数据文件,使得在TEST表空间下面有一个存在于操作系统文件系统上的数据文件。

1
ALTER tablespace TEST ADD datafile '/opt/oracle/app/base/oradata/ora11g/test02.dbf' SIZE 500M autoextend off;

TEST_TBS

如图所示,目标是要将“/opt/oracle/app/base/oradata/ora11g/test02.dbf”这个数据文件迁移至DG_DATA上面去。下面使用rman来做迁移。

[oracle@RACA ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 – Production on Sun Jul 6 10:00:56 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORA11G (DBID=4247331602)
RMAN>

将TEST表空间离线:

RMAN> sql ‘alter tablespace TEST offline’;

using target database control file instead of recovery catalog
sql statement: alter tablespace TEST offline
RMAN>

在磁盘组上创建该表空间或数据文件的备份,这里因为只有一个数据文件要迁移,因此创建该数据文件的备份即可:

RMAN> backup as copy datafile ‘/opt/oracle/app/base/oradata/ora11g/test02.dbf’ format ‘+DG_DATA’;

Starting backup at 06-JUL-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/opt/oracle/app/base/oradata/ora11g/test02.dbf
output file name=+DG_DATA/ora11g/datafile/test.264.852199921 tag=TAG20140706T101200 RECID=3 STAMP=852199925
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 06-JUL-14

RMAN>

将该数据文件switch至使用DG_DATA上的备份:

RMAN> switch datafile ‘/opt/oracle/app/base/oradata/ora11g/test02.dbf’ to copy;

using target database control file instead of recovery catalog
datafile 7 switched to datafile copy “+DG_DATA/ora11g/datafile/test.264.852199921”
RMAN>

现在查看该表空间数据文件的位置,其结果显示已经迁移至DG_DATA磁盘组了:

TEST_TBS2

为了数据文件有一个可读性高的名字,切换至grid用户,在asmcmd中创建ASM中文件别名:

[grid@RACA ~]$ asmcmd
ASMCMD> mkalias ‘+DG_DATA/ora11g/datafile/test.264.852199921’ ‘+DG_DATA/test02.dbf’
ASMCMD>

在sqlplus中对使用rename切换使用可读性高的数据文件名:

sys@ORA11G> alter tablespace TEST offline;
alter tablespace TEST offline
*
ERROR at line 1:
ORA-01539: tablespace ‘TEST’ is not online

Elapsed: 00:00:00.07
sys@ORA11G> alter database rename file ‘+DG_DATA/ora11g/datafile/test.264.852199921’ to ‘+DG_DATA/test02.dbf’;

Database altered.

Elapsed: 00:00:00.11
sys@ORA11G>

最后将TEST表空间online就行了。

sys@ORA11G> alter tablespace TEST online;

Tablespace altered.

Elapsed: 00:00:00.16
sys@ORA11G> col file_name format A50;
sys@ORA11G> col tablespace_name format A10;
sys@ORA11G> select tablespace_name, file_name from dba_data_files where tablespace_name=’TEST’;

TABLESPACE FILE_NAME
———- ————————————————–
TEST +DG_DATA/test01.dbf
TEST +DG_DATA/test02.dbf

Elapsed: 00:00:00.05
sys@ORA11G>

最后删除原来操作系统文件系统上的不再使用的数据文件。

   声明:本文采用 BY-NC-SA 协议进行授权 | 星期九
   原创文章转载请注明:转自《OS文件系统数据文件迁移至磁盘组(ASM)


分享按钮