Two methods of Oracle rename data files

Source: Internet
Author: User

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
  1. 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 ';
  2. 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 '
  3. *
  4. ERROR at line 1:
  5. Ora-01525:error in renaming data files
  6. Ora-01121:cannot Rename database file 107-file is on use or recovery
  7. Ora-01110:data file 107: '/opt/ora10g/oradata/orcl/user0100.dbf '
  8. Sql> alter tablespace users offline;
  9. Tablespace altered.
  10. 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 ';
  11. 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 '
  12. *
  13. ERROR at line 1:
  14. Ora-01525:error in renaming data files
  15. Ora-01141:error renaming data file 107-new file '/opt/ora10g/oradata/orcl/userrename1.dbf ' not found
  16. Ora-01110:data file 107: '/opt/ora10g/oradata/orcl/user0100.dbf '
  17. Ora-27037:unable to obtain file status
  18. linux-x86_64 error:2: No such file or directory
  19. Additional Information:3
  20. Sql>!
  21. [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
  22. L/userrename2.dbf
  23. [[Email protected] ~]$ exit
  24. Exit
  25. 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 ';
  26. Tablespace altered.
  27. Sql> alter tablespace users online;
  28. Tablespace altered.

The second Kind

Alter DATABASE rename file ' = = = ' to ' * * *;

This way requires the database to be in the Mount State

[SQL]View PlainCopy
  1. Sql> Startup Mount
  2. ORACLE instance started.
  3. Total System Global area 788529152 bytes
  4. Fixed Size 2087216 bytes
  5. Variable Size 423626448 bytes
  6. Database buffers 356515840 bytes
  7. Redo buffers 6299648 bytes
  8. Database mounted.
  9. 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 ';
  10. Database altered.
  11. sql> alter database open;
  12. Alter database open
  13. *
  14. ERROR at line 1:
  15. Ora-01113:file 106 Needs Media recovery
  16. Ora-01110:data file 106: '/opt/ora10g/oradata/orcl/user099.dbf '
  17. --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.
  18. 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 ';
  19. Database altered.
  20. sql> alter database open;
  21. Database altered.

Also attach a batch to modify the data file name of the statement

[SQL]View PlainCopy
  1. Set pagesize 999
  2. Set Linesize 999
  3. Select ' ALTER DATABASE rename file ' | | "'| | member| | "'| | ' to ' | | Chr (39) | | replace (Member,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | |   "'; '
  4. From V$logfile
  5. Where member like '/paic/hq/bk/restore/data/oradata/lass/% ';
  6. Select ' ALTER DATABASE rename file ' | | "'| | name| | "'| | ' to ' | | Chr (39) | | Replace (name,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | |   "'; '
  7. From V$datafile
  8. where name like '/paic/hq/bk/restore/data/oradata/lass/% '
  9. Select ' ALTER DATABASE rename file ' | | "'| | name| | "'| | ' to ' | | Chr (39) | | Replace (name,'/paic/hq/bk/restore/data/oradata/lass/','/paic/z4ah8020/stg/lass/oradata/ hs03lass/') | |   "'; '
  10. From V$tempfile
  11. where name like '/paic/hq/bk/restore/data/oradata/lass/% '

Two methods of Oracle rename data files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.