如何rename datafile name中存在乱码的数据文件

存在这样的情况create tablespace.. datafile or alter tablespace add datafile时加入数据文件的datafile name中存在乱码,例如以下例子:

 

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

     FILE# NAME
---------- --------------------------------------------------
        20 /s01/锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟dbf

SQL> alter database rename file '/s01/锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟dbf' to '/s01/rename.dbf';
alter database rename file '/s01/锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟dbf' to '/s01/rename.dbf'
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01516: nonexistent log file, datafile, or tempfile
"/s01/锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟dbf"

 

 

以上直接rename存在乱码的数据文件可能遇到ORA-01516错误,对于这种由于存在乱码导致的数据文件管理问题,可以参考以下几种方案:

方法1. 通过alter database backup controlfile to trace; 修改backup controlfile to trace生成的CREATE CONTROLFILE脚本,把存在乱码的数据文件名修改为目标文件名; 这种方法稍微费力一点………….

 

方法2.
通过以下动态SQL执行alter database rename来修改数据文件名:

 

 

declare
x varchar2(600);
y varchar2(600);
begin
y:='/s01/rename.dbf';
select file_name into x from dba_data_files where file_id=20;
execute immediate 'alter database  rename file  '''||x||''' to '''||y||'''';
end;
/

PL/SQL procedure successfully completed.

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

NAME
--------------------------------------------------------------------------------
     FILE#
----------
/s01/rename.dbf
        20

 

这种方法通过动态SQL不涉及到乱码的输出和装换所以可以成功。请注意ONLINE 该数据文件!!

 

方法3.

 

 

RMAN> copy datafile 20 to '/s01/rename1.dbf';

RMAN> switch datafile 20 to copy
2> ;

datafile 20 switched to datafile copy "/s01/rename1.dbf"

RMAN> recover datafile 20;                  

RMAN> sql ' alter database datafile 20 online';

sql statement:  alter database datafile 20 online

 

 

直接使用RMAN COPY+ SWITCH DATAFILE TO COPY或者SETNAME都可以代劳帮助你解决该问题,因为RMAN可以直接使用FILE#指代而不需要如ALTER DATABASE RENAME FILE这样必须输入员文件名。


Posted

in

by

Tags:

Comments

One response to “如何rename datafile name中存在乱码的数据文件”

Leave a Reply

Your email address will not be published. Required fields are marked *