如何通過只讀方式更改Oracle數據文件位置
2024-08-29 13:36:58
供稿:網友
 
             
  在Oracle數據庫中,有多種方式可以移動數據文件的位置,之前介紹過幾種方法:Oracle HowTo:在非歸檔模式下如何更改數據文件位置,Oracle HowTo:如何移動數據文件的位置?
  
                                                                                              以上兩種方法,可能在要求較高的24x7系統中不適合采用,因為會使表空間長時間不可用。
  
  非凡是當表空間數據文件巨大時,物理拷貝可能需要較長的時間。
  
  本文推薦另外一種方法,可以做一個折中,以下是一個簡單的步驟說明:
  
  1.將表空間置于只讀
  
  只讀狀態可以使數據仍然可為用戶訪問.
  alter tablespace tablespace_name read only;
  
  2.物理拷貝文件
  
  3.將表空間offline
  alter tablespace tablespace_name offline;
  
  4.rename數據文件
  alter database rename file 'old_dir_file' to 'new_dir_file';
  
  5.將表空間聯機
  alter tablespace tablespace_name online;
  
  6.將表空間置于read write模式
  alter tablespace tablespace_name read write;
  
  以下是示范步驟:
  
  1.將表空間置于只讀狀態
  [oracle@jumper oracle]$ sqlplus "/ as sysdba"
  
  SQL*Plus: Release 9.2.0.4.0 - PRodUCtion on Sat Nov 12 21:10:49 2005
  
  Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
  
  Connected to:
  Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
  With the Partitioning option
  JServer Release 9.2.0.4.0 - Production
  
  SQL> archive log list;
  Database log mode       Archive Mode
  Automatic archival       Enabled
  Archive destination      /opt/oracle/oradata/conner/archive
  Oldest online log sequence   7
  Next log sequence to archive  10
  Current log sequence      10
  SQL> select name from v$datafile;
  
  NAME
  --------------------------------------------------------------------------
  /opt/oracle/oradata/conner/system01.dbf
  /opt/oracle/oradata/conner/undotbs01.dbf
  /opt/oracle/oradata/conner/users01.dbf
  
  SQL> alter tablespace users read only;
  
  Tablespace altered.
  
  2.物理拷貝文件
  
  SQL> ! cp /opt/oracle/oradata/conner/users01.dbf /opt/oracle/oradata/users01.dbf
  
  3.將表空間脫機
  SQL> alter tablespace users offline;
  
  Tablespace altered.
  
  4.修改文件名稱
  SQL> alter database rename file '/opt/oracle/oradata/conner/users01.dbf' to '/opt/oracle/oradata/users01.dbf';
  
  Database altered.
  
  5.將表空間聯機
  SQL> alter tablespace users online;
  
  Tablespace altered.
  
  6.將表空間置于讀寫狀態
  SQL> alter tablespace users read write;
  
  Tablespace altered.
  
  SQL> select name from v$datafile;
  
  NAME
  --------------------------------------------------------------------------
  /opt/oracle/oradata/conner/system01.dbf
  /opt/oracle/oradata/conner/undotbs01.dbf
  /opt/oracle/oradata/users01.dbf
  
  SQL>                          right">(出處:清風軟件下載學院)