7步,让你清楚“如何修改Oracle数据文件目录和数据文件名”!

文章来源掌数科技微信公众号:Hello_Dataknown

本篇内容适用于:

当表空间中的数据文件放错了位置,并且名字不符合要求,想要更改数据文件路径和数据文件名的场景。

前提条件:

1.打开了数据库的归档模式

2.必须在业务跑完,数据库没有外来链接时,对数据没有修改时才能进行

例如:原来数据文件: /oracle/dsg.dbf

改为:

/oracle/app/oracle/oradata/gao/shine.dbf

接下来就是具体的操作步骤,7步足矣:

Step1:

查看数据文件路径名字和文件号,

把文件号记下来。

SQL> select file_name,file_id from dba_data_files;

Step2:使用rman copy 来把dsg.dbf拷贝一份到想放到的路径下,并改名字。

rman target /

RMAN>copydatafile 6 to '/oracle/app/oracle/oradata/gao/shine.dbf';

Step3:

在sqlplus中让6号文件下线。

SQL> alter database datafile 6 offline;

Step4:

在sqlplus中重定义该数据文件的名字和目录

alter database rename file '/oracle/dsg.dbf' to '/oracle/app/oracle/oradata/gao/shine.dbf';

Step5:

在rman中恢复该数据文件。

rman target /

recover datafile 6;

Step6:

在sqlplus中让该数据文件online。

SQL>alter database datafile 6 online;

Step7:

查看数据文件路径名字和文件编号。

SQL> select name,file# from v$datafile;


下一篇:DBA日记之Oracle初始化参数说明(oracle 11g)