按照影响程度大小,方案A需要down库,方案B需要offline tablespace,方案C只需offline datafile即可。综合来看,下面的Testcase_C_2的方法来的最简单。影响也最小。
方案A:
Testcase_A_1: (用ASM的cp)
srvctl stop database -d ora11g
ASMCMD> cp /tmp/test.dbf test01.dbf
SQL> startup mount
SQL> alter database rename file '/tmp/test.dbf' to '+DATA/ora11g/datafile/test01.dbf';
SQL> alter database open;
srvctl stop instance -d ora11g -i ora11g1
srvctl start database -d ora11g
Testcase_A_2_a:(用rman的backup as copy)
srvctl stop database -d ora11g
RMAN> startup mount
RMAN> backup as copy datafile 7 format '+DATA';
RMAN> SWITCH DATAFILE 7 to COPY;
SQL> alter database open;
srvctl stop instance -d ora11g -i ora11g1
srvctl start database -d ora11g
Testcase_A_2_b:(用rman的copy)
srvctl stop database -d ora11g
RMAN> startup mount
RMAN> copy datafile 7 to '+DATA';
RMAN> switch datafile 7 to copy;
RMAN> alter database open;
srvctl stop instance -d ora11g -i ora11g1
srvctl start database -d ora11g
Testcase_A_2_c:(用rman的copy+sqlplus的rename)
srvctl stop database -d ora11g
RMAN> startup mount
RMAN> copy datafile 7 to '+DATA';
SQL> alter database rename file '/tmp/test.dbf' to '+DATA/ora11g/datafile/TEST.272.921855725';
SQL> alter database open;
srvctl stop instance -d ora11g -i ora11g1
srvctl start database -d ora11g
方案B:
Testcase_B_1(用asm的cp)
SQL> alter tablespace test offline;
ASMCMD> cp /tmp/test.dbf test.dbf
SQL> alter database rename file '/tmp/test.dbf' to '+data/ora11g/datafile/test.dbf';
SQL> alter tablespace test online;
Testcase_B_2: (用rman的copy)
SQL> alter tablespace test offline;
RMAN> copy datafile 7 to '+DATA';
RMAN> switch datafile 7 to copy;
SQL> alter tablespace test online;
方案C:
Testcase_C_1:(用create datafile as)
SQL> alter database datafile 7 offline;
SQL> alter database create datafile '/tmp/test.dbf' as '+DATA';
SQL> recover datafile 7;
auto
SQL> alter database datafile 7 online;
Testcase_C_2:(用rman的copy)
SQL> alter database datafile 7 offline;
RMAN> copy datafile 7 to '+DATA';
RMAN> switch datafile 7 to copy;
RMAN> recover datafile 7;
SQL> alter database datafile 7 online;
(具体的测试日志,见附件)
另外,邮件中方案C提到的,offline drop的方式,还是不建议采用,因为offline drop只是标记了一下数据文件,在控制文件中,还是会看到这个文件的信息。除非重建控制文件或者drop整个tablespace。
另外,recover datafile的时候,不建议使用SQL> alter database recover datafile 7。因为会挂住。
SQL> alter database recover datafile 7;
alter database recover datafile 7
*
ERROR at line 1:
ORA-00279: change 4025242 generated at 09/06/2016 15:28:47 needed for thread 1
ORA-00289: suggestion :
+FRA/ora11g/archivelog/2016_09_06/thread_1_seq_669.669.921857351
ORA-00280: change 4025242 for thread 1 is in sequence #669
建议使用:
- recover datafile XX,然后指定auto
- 用rman的recover datafile xx
- 在sqlplus中set autorecovery on之后,再alter database recover datafile xx
- Alter database recover automatic datafile xxx