环境:
OS:Oracle Linux Server release 5.6
DB:oracle11.2.0.1
1.创建一个新的表空间用于实验;
itkaifang@SYS> create tablespace txt datafile'/u01/app/oracle/oradata/itkaifang/txt01.dbf' size 10M; Tablespace created. itkaifang@SYS> select file_name from dba_data_files where tablespace_name='TXT'; FILE_NAME -------------------------------------------------- /u01/app/oracle/oradata/itkaifang/txt01.dbf itkaifang@SYS>
2.使用RMAN工具更换数据文件位置及文件名;
[oracle@itkaifang ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Sat Apr 8 16:38:25 2017 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ITKAIFAN (DBID=3506788363) RMAN> RMAN> run { 2> sql "alter tablespace txt offline immediate"; 3> set newname for datafile'/u01/app/oracle/oradata/itkaifang/txt01.dbf' to '/home/oracle/txt1.dbf'; 4> restore tablespace 'TXT'; 5> switch datafile all; 6> recover tablespace 'TXT'; 7> sql "alter tablespace txt online"; 8> } sql statement: alter tablespace txt offline immediate executing command: SET NEWNAME Starting restore at 08-APR-17 using channel ORA_DISK_1 creating datafile file number=7 name=/home/oracle/txt1.dbf restore not done; all files read only, offline, or already restored Finished restore at 08-APR-17 datafile 7 switched to datafile copy input datafile copy RECID=3 STAMP=940783454 file name=/home/oracle/txt1.dbf Starting recover at 08-APR-17 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 08-APR-17 sql statement: alter tablespace txt online RMAN>
3.验证;
itkaifang@SYS> select file_name from dba_data_files where tablespace_name='TXT'; FILE_NAME -------------------------------------------------- /home/oracle/txt1.dbf itkaifang@SYS>
---End---Good Luck---