第一种
alter tablespace users rename datafile 'xxxx' to ‘xxxx';
这种方式需要数据库处于open状态,表空间在offline的状态下才能更改。
SQL> alter tablespace users offline;
$ mv /opt/ora10g/oradata/orcl/user01aa.dbf /opt/ora10g/oradata/orcl/user01bb.dbf
SQL> alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user01aa.dbf' to '/opt/ora10g/oradata/orcl/user01bb.dbf' ;
SQL> alter tablespace users online;
第二种
alter database rename file 'xxxx' to ‘xxxx';
这种方式需要数据库处于mount状态
SQL> startup mount
$ mv /opt/ora10g/oradata/orcl/user01bb.dbf /opt/ora10g/oradata/orcl/user01aa.dbf
SQL> alter database rename file '/opt/ora10g/oradata/orcl/user01bb.dbf' to '/opt/ora10g/oradata/orcl/user01aa.dbf';
SQL> alter database open;
注意事项:
1、临时表空间RENAME数据文件时,不能直接把临时表空间offline,会报错,要先把临时表空间的数据文件offline,然后再COPY,再RENAME,再ONLINE才可以
2、临时表空间RENAME数据文件,参考资料:http://blog.itpub.net/21374452/viewspace-2134752/
----------------------------------------
附上批量修改数据文件名的语句
----------------------------------------
set pagesize 999
set linesize 999
select 'alter database rename file '||''''||member||''''||' to '||chr(39)||replace(member,'/u01/app/oracle/oradata/ora11g/','/u03/app/oracle/oradata/ora11g/')||''';'
from v$logfile ;
select 'alter database rename file '||''''||name||''''||' to '||chr(39)||replace(name,'/u01/app/oracle/oradata/ora11g//','/u03/app/oracle/oradata/ora11g/')||''';'
from v$datafile ;
select 'alter database rename file '||''''||name||''''||' to '||chr(39)||replace(name,'/u01/app/oracle/oradata/ora11g/','/u03/app/oracle/oradata/ora11g/')||''';'
from v$tempfile ;
-- END --