標籤:des style blog ar io color os 使用 sp
需求:把oracle資料庫的資料檔案,redo檔案,控制檔案遷移到本地的其它目錄。
1.測試環境:
作業系統redhat 6.3,資料庫oracle 11.2.0.1.0
[[email protected] ~]# uname -aLinux dbtest1 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
SQL> select * from v$version;BANNER--------------------------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionPL/SQL Release 11.2.0.1.0 - ProductionCORE 11.2.0.1.0 ProductionTNS for Linux: Version 11.2.0.1.0 - ProductionNLSRTL Version 11.2.0.1.0 - Production
來源資料檔案位置:/home/data/oracle/dbtest/
目標資料檔案位置:/oracle_data/
2.關閉資料庫監聽,禁止外部存取資料庫
-bash-4.1$ lsnrctl stopLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 18-DEC-2014 13:22:05Copyright (c) 1991, 2009, Oracle. All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=dbtest)))The command completed successfully
3.關閉oracle資料庫
SQL> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.
4.備份pfile,spfile,控制檔案(至少備份一個)
-bash-4.1$ cd /$ORACLE_HOME/dbs-bash-4.1$ cp initdbtest.ora initdbtest.ora.141218-bash-4.1$ cp spfiledbtest.ora spfiledbtest.ora.141218-bash-4.1$ cd /home/data/oracle/dbtest/-bash-4.1$ cp control01.ctl control01.ctl.141218
5.更新pfile,從spfile建立pfile
SQL> create pfile=‘$ORACLE_HOME/dbs/initdbtest.ora‘ from spfile=‘$ORACLE_HOME/dbs/spfiledbtest.ora‘;
註:預設位置的話,可以直接使用create pfile from spfile來建立的,建立後檢查一下時間戳記來確認。
6.修改pfile中的控制檔案的位置
把/home/data/oracle/dbtest/control01.ctl修改為/oracle_data/control01.ctl
-bash-4.1$ cd /$ORACLE_HOME/dbs/-bash-4.1$ lshc_dbtest.dat initdbtest.ora initdbtest.ora.141218 init.ora lkDBTEST orapwdbtest spfiledbtest.ora spfiledbtest.ora.141218-bash-4.1$ cat initdbtest.ora |grep control*.control_files=‘/home/data/oracle/dbtest/control01.ctl‘,‘/home/app/ora11g/flash_recovery_area/dbtest/control02.ctl‘使用vi編輯該檔案-bash-4.1$ cat initdbtest.ora |grep control*.control_files=‘/oracle_data/control01.ctl‘,‘/home/app/ora11g/flash_recovery_area/dbtest/control02.ctl‘
註:如果有多個要修改的話,方法是一樣的。
7.複製來源資料目錄下的檔案,包括控制檔案,資料檔案和redo檔案
-bash-4.1$ cp /home/data/oracle/dbtest/* /oracle_data/
8.使用pfile來啟動資料庫到mount狀態
SQL> startup pfile=‘$ORACLE_HOME/dbs/initdbtest.ora‘ mountORACLE instance started.Total System Global Area 1603411968 bytesFixed Size 2213776 bytesVariable Size 1241516144 bytesDatabase Buffers 352321536 bytesRedo Buffers 7360512 bytesDatabase mounted.
9.重新命名資料檔案,redo檔案的位置
SQL> ALTER DATABASE RENAME FILE ‘/home/data/oracle/dbtest/redo01.log‘ to ‘/oracle_data/redo01.log‘;Database altered.SQL>ALTER DATABASE RENAME FILE ‘/home/data/oracle/dbtest/system01.dbf‘ to ‘/oracle_data/system01.dbf‘;Database altered.......
10. 開啟資料庫
SQL> alter database open;Database altered.
11.檢查資料檔案,redo等檔案位置是否正確
SQL> select file_name from dba_data_files;FILE_NAME--------------------------------------------------------------------------------/oracle_data/users01.dbf/oracle_data/undotbs01.dbf/oracle_data/sysaux01.dbf/oracle_data/system01.dbf/oracle_data/laputa_dat.dbf/oracle_data/laputa_idx_01.dbf6 rows selected.SQL> select file_name from dba_temp_files;FILE_NAME--------------------------------------------------------------------------------/oracle_data/temp01.dbfSQL> select name from v$controlfile;NAME--------------------------------------------------------------------------------/oracle_data/control01.ctl/home/app/ora11g/flash_recovery_area/dbtest/control02.ctlSQL> select member from v$logfile;MEMBER--------------------------------------------------------------------------------/oracle_data/redo03.log/oracle_data/redo02.log/oracle_data/redo01.log
12.同步spfile到新的檔案(簡化寫法)
SQL> create spfile from pfile;File created.
13.重啟一次資料庫確認一切正常
SQL> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SQL> startupORACLE instance started.Total System Global Area 1603411968 bytesFixed Size 2213776 bytesVariable Size 1241516144 bytesDatabase Buffers 352321536 bytesRedo Buffers 7360512 bytesDatabase mounted.Database opened.SQL>
14.開啟資料庫監聽
-bash-4.1$ lsnrctl start
注意問題:
1.在rename檔案的時候,如果涉及到的檔案比較多,建議把語句放在一個sql檔案中,然後再在sqlplus中執行,否則可能會導致語句在中間斷裂(一條語句被命令列看成2行,會報錯)。如果發生了語句的斷裂,重新把語句放在sql檔案中執行即可,這些rename語句重複執行會報錯,但是不影響最終的結果。
2.遷移redo檔案可以線上執行,用添加redo group,刪除redo group的辦法。
3.非系統資料表空間可以在不關閉資料庫的方法遷移,對錶空間進行offline,移動對應資料檔案,rename資料檔案,online資料表空間。
ORACLE 本地冷遷移