2.7 文件系统与ASM的切换
在进行表空间迁移时,如果是从文件系统到文件系统的迁移很容易实现,但是如果是从文件系统到ASM则需要多一点步骤。类似前面的测试,如果在ASM环境中执行同样的导入命令:
imp \'/ as sysdba\' tablespaces=trans transport_tablespace=y
file=exp_trans.dmp datafiles=/opt/oracle/trans.dbf
则简单地导入之后会出现如下的效果,新导入的文件位于文件系统之上,这显然是不希望看到的,我们需要将文件系统文件转移到ASM磁盘组上去:
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATADG/rac/datafile/system.259.722961061
+DATADG/rac/datafile/undotbs1.260.722961083
+DATADG/rac/datafile/sysaux.261.722961087
+DATADG/rac/datafile/undotbs2.263.722961097
+DATADG/rac/datafile/users.264.722961099
/opt/oracle/trans.dbf
文件转移可以通过RMAN来进行,但是首次尝试遇到了RMAN-20201错误:
[oracle@rac1 oracle]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on Wed Sep 1 14:24:37 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: RAC (DBID=2310943069)
RMAN> backup as copy datafile '/opt/oracle/trans.dbf' format '+DATADG';
Starting backup at 01-SEP-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=124 instance=rac1 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 09/01/2010 14:25:21
RMAN-20201: datafile not found in the recovery catalog
RMAN-06010: error while looking up datafile: /opt/oracle/trans.dbf
这个错误是由于 TRANS 表空间刚刚导入数据库中,处于只读状态,并未被 Catalog 记录感知,通过对这个文件进行特定操作,如读写变更,则可以消除此错误:
SQL> select tablespace_name,status from dba_tablespaces where tablespace_name=’TRANS’;
TABLESPACE_NAME STATUS
------------------------------ ---------
TRANS READ ONLY
RMAN中的Schema信息尚未记录该表空间:
RMAN> report schema;
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- ---------------- -------- ------------------------------------
1 300 SYSTEM *** +DATADG/rac/datafile/system.259.722961061
2 200 UNDOTBS1 *** +DATADG/rac/datafile/undotbs1.260.722961083
3 280 SYSAUX *** +DATADG/rac/datafile/sysaux.261.722961087
4 200 UNDOTBS2 *** +DATADG/rac/datafile/undotbs2.263.722961097
5 5 USERS *** +DATADG/rac/datafile/users.264.722961099
6 512 STREAM_TBS *** +DATADG/rac/datafile/stream_tbs.268.725126097
7 1 TESTTBS1 *** +DATADG/rac/datafile/testtbs1.269.726592535
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- ------------------ ----------- --------------------
1 20 TEMP 32767 +DATADG/rac/tempfile/temp.262.722961089
在数据库内部对该表空置读写访问:
SQL> alter tablespace trans read write;
Tablespace altered.
然后可以看到该表空间被Catalog所记录,当然这里的信息是来自控制文件的:
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- ------------------ --------- ------------------------
1 300 SYSTEM *** +DATADG/rac/datafile/system.259.722961061
2 200 UNDOTBS1 *** +DATADG/rac/datafile/undotbs1.260.722961083
3 280 SYSAUX *** +DATADG/rac/datafile/sysaux.261.722961087
4 200 UNDOTBS2 *** +DATADG/rac/datafile/undotbs2.263.722961097
5 5 USERS *** +DATADG/rac/datafile/users.264.722961099
6 512 STREAM_TBS *** +DATADG/rac/datafile/stream_tbs.268.725126097
7 1 TESTTBS1 *** +DATADG/rac/datafile/testtbs1.269.726592535
8 10 TRANS *** /opt/oracle/trans.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 +DATADG/rac/tempfile/temp.262.722961089
接下来将表空间状态再改为只读:
SQL> alter tablespace trans read only;
Tablespace altered.
通过RMAN进行镜像拷贝:
RMAN> backup as copy datafile '/opt/oracle/trans.dbf' format '+DATADG';
Starting backup at 01-SEP-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=130 instance=rac1 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00008 name=/opt/oracle/trans.dbf
output filename=+DATADG/rac/datafile/trans.270.728577593 tag=TAG20100901T143951 recid=2 stamp=728577592
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 01-SEP-10
切换之前需要将表空间离线,否则会出现错误:
RMAN> switch datafile '/opt/oracle/trans.dbf' to copy;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of switch to copy command at 09/01/2010 14:40:58
RMAN-06572: database is open and datafile 8 is not offline
将表空间离线:
SQL> alter tablespace trans offline;
Tablespace altered.
执行切换:
RMAN> switch datafile '/opt/oracle/trans.dbf' to copy;
datafile 8 switched to datafile copy "+DATADG/rac/datafile/trans.270.728577593"
现在转换后的表空间已经被转移到了ASM磁盘组中,此时可以将表空间Online,如果操作期间有过事务变更,还可能需要恢复:
SQL> alter tablespace trans online;
Tablespace altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATADG/rac/datafile/system.259.722961061
+DATADG/rac/datafile/undotbs1.260.722961083
+DATADG/rac/datafile/sysaux.261.722961087
+DATADG/rac/datafile/undotbs2.263.722961097
+DATADG/rac/datafile/users.264.722961099
+DATADG/rac/datafile/trans.270.728577593