oracle rename数据文件的两种方法

2012-12-11 20:44 10925人阅读 评论(0) 收藏 举报
oracle rename数据文件的两种方法 分类:
oracle(98) oracle rename数据文件的两种方法

版权声明:本文为博主原创文章,未经博主允许不得转载。

第一种

alter tablespace users rename datafile '==' to ‘***';

这种方式需要数据库处于open状态,表空间在offline的状态下才能更改。

  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 in 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. [oracle@rac1 ~]$ cp /opt/ora10g/oradata/orcl/user0100.dbf /opt/ora10g/oradata/orcl/userrename1.dbf[oracle@rac1 ~]$ cp /opt/ora10g/oradata/orcl/user099.dbf /opt/ora10g/oradata/orc
  22. l/userrename2.dbf
  23. [oracle@rac1 ~]$ 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.

第二种

alter database rename file ‘==='  to '***';

这种方式需要数据库处于mount状态

  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. --这里不能open的原因是刚刚关闭数据库写了userrename2.dbf和userrename1.dbf这两个数据文件的scn,而user099.dbf和user0100.dbf的scn还是offline的时候的,这样控制文件的头和数据文件头不一致,所以数据库打不开。
  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.

另外附上批量修改数据文件名的语句

  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/%'
上一篇:从Java虚拟机角度分析类的实例化顺序


下一篇:Android中SQLite数据库操作(2)——SQLiteOpenHelper类