Two methods of Oracle rename data files2012-12-11 20:44 10925 People read comments (0) favorite reports Classification:Oracle (98)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
First Kind
Alter tablespace users rename datafile ' = = ' to ' * * * ';
This way requires the database to be in the open state, and the tablespace can be changed in a offline state.
[SQL]View PlainCopy
- Sql> alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user0100.dbf ','/opt/ora10g/ ORADATA/ORCL/USER099.DBF ' to '/opt/ora10g/oradata/orcl/userrename1.dbf ','/opt/ora10g/oradata/orcl/ USERRENAME2.DBF ';
- Alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user0100.dbf ','/opt/ora10g/oradata/orcl/ USER099.DBF ' to '/opt/ora10g/oradata/orcl/userrename1.dbf ','/opt/ora10g/oradata/orcl/userrename2.dbf '
- *
- ERROR at line 1:
- Ora-01525:error in renaming data files
- Ora-01121:cannot Rename database file 107-file is on use or recovery
- Ora-01110:data file 107: '/opt/ora10g/oradata/orcl/user0100.dbf '
- Sql> alter tablespace users offline;
- Tablespace altered.
- Sql> alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user0100.dbf ','/opt/ora10g/ ORADATA/ORCL/USER099.DBF ' to '/opt/ora10g/oradata/orcl/userrename1.dbf ','/opt/ora10g/oradata/orcl/ USERRENAME2.DBF ';
- Alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user0100.dbf ','/opt/ora10g/oradata/orcl/ USER099.DBF ' to '/opt/ora10g/oradata/orcl/userrename1.dbf ','/opt/ora10g/oradata/orcl/userrename2.dbf '
- *
- ERROR at line 1:
- Ora-01525:error in renaming data files
- Ora-01141:error renaming data file 107-new file '/opt/ora10g/oradata/orcl/userrename1.dbf ' not found
- Ora-01110:data file 107: '/opt/ora10g/oradata/orcl/user0100.dbf '
- Ora-27037:unable to obtain file status
- linux-x86_64 error:2: No such file or directory
- Additional Information:3
- Sql>!
- [Email protected] ~]$ Cp/opt/ora10g/oradata/orcl/user0100.dbf/opt/ora10g/oradata/orcl/userrename1.dbf[[email Protected] ~]$ Cp/opt/ora10g/oradata/orcl/user099.dbf/opt/ora10g/oradata/orc
- L/userrename2.dbf
- [[Email protected] ~]$ exit
- Exit
- Sql> alter tablespace users rename datafile '/opt/ora10g/oradata/orcl/user0100.dbf ','/opt/ora10g/ ORADATA/ORCL/USER099.DBF ' to '/opt/ora10g/oradata/orcl/userrename1.dbf ','/opt/ora10g/oradata/orcl/ USERRENAME2.DBF ';
- Tablespace altered.
- Sql> alter tablespace users online;
- Tablespace altered.
The second Kind
Alter DATABASE rename file ' = = = ' to ' * * *;
This way requires the database to be in the Mount State
[SQL]View PlainCopy
- Sql> Startup Mount
- ORACLE instance started.
- Total System Global area 788529152 bytes
- Fixed Size 2087216 bytes
- Variable Size 423626448 bytes
- Database buffers 356515840 bytes
- Redo buffers 6299648 bytes
- Database mounted.
- sql> alter database rename file '/opt/ora10g/oradata/orcl/userrename2.dbf ','/opt/ora10g/oradata/ ORCL/USERRENAME1.DBF ' to '/opt/ora10g/oradata/orcl/user099.dbf ','/opt/ora10g/oradata/orcl/ USER0100.DBF ';
- Database altered.
- sql> alter database open;
- Alter database open
- *
- ERROR at line 1:
- Ora-01113:file 106 Needs Media recovery
- Ora-01110:data file 106: '/opt/ora10g/oradata/orcl/user099.dbf '
- --This cannot open because just shut down the database wrote userrename2.dbf and userrename1.dbf the SCN of the two data files, while USER099.DBF and user0100.dbf SCN or offline time, so control the file header and data text The database cannot be opened because the header is inconsistent.
- sql> alter database rename file '/opt/ora10g/oradata/orcl/user099.dbf ','/OPT/ORA10G/ORADATA/ORCL /USER0100.DBF ' to '/opt/ora10g/oradata/orcl/userrename2.dbf ','/opt/ora10g/oradata/orcl/ USERRENAME1.DBF ';
- Database altered.
- sql> alter database open;
- Database altered.
Also attach a batch to modify the data file name of the statement
[SQL]View PlainCopy
- Set pagesize 999
- Set Linesize 999
- Select ' ALTER DATABASE rename file ' | | "'| | member| | "'| | ' to ' | | Chr (39) | | replace (Member,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | | "'; '
- From V$logfile
- Where member like '/paic/hq/bk/restore/data/oradata/lass/% ';
- Select ' ALTER DATABASE rename file ' | | "'| | name| | "'| | ' to ' | | Chr (39) | | Replace (name,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | | "'; '
- From V$datafile
- where name like '/paic/hq/bk/restore/data/oradata/lass/% '
- Select ' ALTER DATABASE rename file ' | | "'| | name| | "'| | ' to ' | | Chr (39) | | Replace (name,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | | "'; '
- From V$tempfile
- where name like '/paic/hq/bk/restore/data/oradata/lass/% '
Two methods of Oracle rename data files