oracle rename數據文件的兩種方法
阿新 • • 發佈:2017-08-02
ati oar online 技術 off target pen 分類 alt
oracle rename數據文件的兩種方法
2012-12-11 20:44 10925人閱讀 評論(0) 收藏 舉報 分類:版權聲明:本文為博主原創文章,未經博主允許不得轉載。
第一種
alter tablespace users rename datafile ‘==‘ to ‘***‘;
這種方式需要數據庫處於open狀態,表空間在offline的狀態下才能更改。
[sql] view plain copy
- 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 in 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.
第二種
alter database rename file ‘===‘ to ‘***‘;
這種方式需要數據庫處於mount狀態
[sql] view plain copy- 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‘
- --這裏不能open的原因是剛剛關閉數據庫寫了userrename2.dbf和userrename1.dbf這兩個數據文件的scn,而user099.dbf和user0100.dbf的scn還是offline的時候的,這樣控制文件的頭和數據文件頭不一致,所以數據庫打不開。
- 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.
另外附上批量修改數據文件名的語句
[sql] view plain copy- 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/%‘
oracle rename數據文件的兩種方法