用 rman copy 的方法更改数据文件名称或者迁移到其他的磁盘中。

全部在rman下操作:

用 rman copy 的方法更改数据文件名称或者迁移到其他的磁盘中。


select tablespace_name,file_id,file_name from dba_data_files where tablespace_name = 'TBS_TRANS' ;

TABLESPACE_NAME                         FILE_ID     FILE_NAME
--------------------------  ----------  -------------------------------------------------- 
TBS_TRANS                                   12         /u01/app/oracle/oradata/testdb2/df_trans.dbf

12 rows selected.



现在要将数据文件 '/u01/app/oracle/oradata/testdb2/df_trans.dbf' 名称改为 '/u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf' 



必须在归档模式下才可以,先打开归档模式:

SQL> archive log list ;
Database log mode                 Archive Mode
Automatic archival               Enabled
Archive destination               /home/oracle/arch1
Oldest online log sequence     6
Next log sequence to archive   8
Current log sequence             8



backup AS copy datafile 12 format '/u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf';
SQL 'alter database datafile 12 offline';
switch datafile 12 TO copy;
recover datafile 12;
SQL 'alter database datafile 12 online';



[oracle@testdb ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 13 15:15:50 2019

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

connected to target database: TESTDB2 (DBID=1329834865)

RMAN> backup AS copy datafile 12 format '/u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf';

Starting backup at 13-MAY-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=140 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00012 name=/u01/app/oracle/oradata/testdb2/df_trans.dbf
output file name=/u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf tag=TAG20190513T151619 RECID=5 STAMP=1008170179
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 13-MAY-19

RMAN> SQL 'alter database datafile 12 offline';

sql statement: alter database datafile 12 offline

RMAN> switch datafile 12 TO copy;

datafile 12 switched to datafile copy "/u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf"

RMAN> recover datafile 12;

Starting recover at 13-MAY-19
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 13-MAY-19

RMAN> SQL 'alter database datafile 12 online';

sql statement: alter database datafile 12 online




查看最终结果
select tablespace_name,file_id,file_name from dba_data_files where tablespace_name = 'TBS_TRANS' ;

TABLESPACE_NAME                          FILE_ID                            FILE_NAME
--------------------------  ---------------------------------- -------------------------------------------------------------------------------------------------------------
TBS_TRANS                                   12                                 /u01/app/oracle/oradata/testdb2/df_trans_test20190514.dbf

 

上一篇:linux基础—课堂随笔05_文本三剑客之SED


下一篇:Migrating Oracle 11g R2 To Oracle 19c