手工轉移資料庫Step By Step

來源:互聯網
上載者:User

[原創] 手工轉移資料庫Step By Step

 

http://www.chinaunix.net 作者:seraphim
  發表於:2004-01-26 17:34:09

轉自:http://www.chinaunix.net/jh/19/236232.html

【發表評論

【查看原文

【Oracle討論區
】【關閉

手工轉移資料庫Step By Step

Author:Seraphim

Mail:kamus@itpub.net

Date:2004-1

有時候我們會遇到這樣的情況,現有的資料庫要從一個機器轉移到另外一個機器上,一般我們會使用匯出,匯入。但是如果資料庫的資料非常多,資料檔案
尺寸很大,那麼在匯出匯入的過程就很可能會出現問題,並且漫長的過程也是我們無法容忍的。在這種情況下,我們可以簡單地使用作業系統的copy命令,直接
進行資料庫的轉移。

以下樣本均在Redhat Fedora Core 1上的Oracle9.2.0.1中操作,其它作業系統和Oracle版本同樣適用。

假設我們的資料庫在伺服器A上,$ORACLE_BASE是/oracle,$ORACLE_HOME是/oracle/product
/9.2.0。現在我們要將此資料庫轉移到伺服器B上,並且新的$ORACLE_BASE是/u01/oracle,$ORACLE_HOME是/u01
/oracle/product/9.2.0。SID是oralinux。

操作步驟如下:

一.在伺服器B上安裝Oracle,安裝過程中不要建立資料庫。使用者的profile直接從伺服器A上copy過來即可,注意需要修改原先的$ORACLE_HOME到現在的位置。

二.如果伺服器A上的Oracle使用的是spfile,那麼根據此spfile建立pfile:

create pfile from spfile;

三.關閉伺服器A上的資料庫,shutdown immediate。如果資料庫不允許關閉,那麼可以使用聯機備份,這種情況資料庫必須處於archivelog模式,轉移的原理和允許關閉的情況一樣,此處不作討論。

四.備份伺服器A上的所有資料檔案,包括以下:

a)所有的datafile(臨時檔案可以不copy,比如temp01.dbf)

b)所有的online redo log

c)所有的archive redo log

d)所有的control file

e)$ORACLE_HOME/dbs/init<SID>;.ora(此檔案是在上面第二步中建立的)

f)$ORACLE_HOME/dbs/orapw<SID>;(這是password file)

g)$ORACLE_HOME/network/listener.ora(這步可以省略,以後重建也可以)

h)$ORACLE_BASE/admin/<SID>;/下的所有目錄,一般是udump, cdump, bdump(這步可以省略,以後手工建立目錄也可以)

五.
通過FTP或者別的工具將上述的備份檔案,全部上傳到伺服器B的相應目錄中。比如說原來在伺服器A上$ORACLE_BASE/oradata
/<SID>;/system01.dbf,現在就上傳到伺服器B上$ORACLE_BASE/oradata/<SID>;
/system01.dbf,保證目錄的邏輯結構一樣,實際上物理結構已經發生了變化(A上$ORACLE_BASE是/oracle,而B上是/u01
/oracle)。其它的檔案均作相同處理,如果伺服器B上還沒有相應的目錄,那麼就手工建立。

六.編輯上傳到伺服器B上的init<SID>;.ora檔案,將其中涉及的目錄結構全部改為B中目前的目錄結構,比如本例中就是將/oracle改為/u01/oracle。

七.在伺服器B上,sqlplus “/ as sysdba”,提示進入空閑進程。

八.根據修改過的pfile建立spfile,create spfile from pfile;

九.啟動資料庫到mount狀態,startup mount;

十.修改control file中所有資料檔案的位置,可以通過spool產生所有的SQL:

SQL>; alter database rename file '/oracle/oradata/oralinux/system01.dbf'

  2  to '/u01/oracle/oradata/oralinux/system01.dbf';

按照以上文法修改所有的資料檔案位置。

十一.此時資料庫已經可以使用了,alter database open;

十二.將臨時檔案添加到TEMP資料表空間中:

alter tablespace TEMP add tempfile ‘'/u01/oracle/oradata/oralinux/temp01.dbf’ size 20M;

十三.
還有一些後續工作,包括更新資料庫B上的監聽設定檔(其實可以不用管,因為9i的執行個體已經可以自動註冊到監聽程式上了,如果是先起監聽再起資料庫,那麼
立刻就會註冊,如果是先起資料庫再起監聽,那麼會稍微有些延時才註冊),修改/etc/oratab檔案,以能夠使用dbstart和dbshut指令碼。

這樣資料庫就算完全轉移了,如果有什麼問題,可以給我發郵件。

 eagle_fan
回複於:2004-01-05 13:06:10

有個疑問:

如果不shutdown資料庫,online redo log可以備份嗎?

 seraphim
回複於:2004-01-05 17:45:46

沒問題,只要全部online都在,但是因為是online備份,所以如果業務繁忙,缺少一些資料是無法避免的。

如果是線上備份需要先recover database。

如下:

[zhangleyi@as orcl]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Jan 5 17:33:38 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL>; startup

ORACLE instance started.

Total System Global Area  118035836 bytes

Fixed Size                   451964 bytes

Variable Size              96468992 bytes

Database Buffers           20971520 bytes

Redo Buffers                 143360 bytes

Database mounted.

ORA-01113: file 1 needs media recovery

ORA-01110: data file 1: '/oracle/oradata/orcl/system01.dbf'

SQL>; recover database

Media recovery complete.

SQL>; shutdown

ORA-01109: database not open

Database dismounted.

ORACLE instance shut down.

SQL>; startup

ORACLE instance started.

Total System Global Area  118035836 bytes

Fixed Size                   451964 bytes

Variable Size              96468992 bytes

Database Buffers           20971520 bytes

Redo Buffers                 143360 bytes

Database mounted.

Database opened.

SQL>;

 OCPHUI
回複於:2004-01-05 19:40:45

用rman duplicate database 更方便哦。

而且不用shutdown。

 melonm
回複於:2004-01-06 10:54:19

對於OracleDatabase Backup而言,**不要備份Online Redo Log**。

SQL>; recover database 

Media recovery complete.

這是從archive logs裡恢複。

當Cold/Offline 備份,備份兩類Oracle檔案:

* Database files

* Control files

當Hot/Online備份,備份三類Oracle檔案:

* Database files

* Control Files

* Archive logs

 seraphim
回複於:2004-01-06 12:29:53

引用:原帖由 "melonm" 發表:

對於OracleDatabase Backup而言,**不要備份Online Redo Log**。

SQL>; recover database 

Media recovery complete.

這是從archive logs裡恢複。

當Cold/Offline 備份,備份兩類Oracle檔案:

* Databas..........

對於備份來說確實不應該備份Online Redo,原因在於避免誤將備份的Online Redo在恢複的時候覆蓋了當前的online Redo,這是意義所在。

本例中主旨在於移動資料庫,和備份沒有關係,所以copy了online redo。

另外recover database不僅僅是從archive中恢複,如果需要恢複的SCN在online redo中,自然也同樣會用到online redo,否則不是archivelog模式的怎麼recover?

 paulyang88
回複於:2004-01-26 17:34:09

我們能夠恢複各種原因造成的SQL SERVER資料庫損壞,詳細請看http://www.haou.net/sqlother/

ms sql server database recover

I can recover all type of ms sql server database losing.please contact me at cn9526@163.net

or contact me with msn: paulyang8848@hotmail.com

I can chat with u.thanks!

 

 

原文連結:http://bbs.chinaunix.net/viewthread.php?tid=236232

轉載請註明作者名及原文出處

 

 類似文檔:

 

轉自:http://space.itpub.net/673608/viewspace-614299

oracle 移動資料檔案

上一篇
/
下一篇
 2009-09-09 22:36:26

/ 個人分類:oracle-admin

查看( 41 )
/
評論( 0 )
/
評分( 0
/ 0
)

某天晚上,被告之資料庫


不能正常使用,sqlplus登陸的時候,報錯,沒有空間,然後去伺服器上看,df,果然100%。這就是把資料檔案和oracle


安裝



錄裝一起的壞處。忍痛刪掉幾kb檔案之後,能用dba登陸,然後想到個方案,把資料檔案轉移到閒置其他區。用mv命令,轉移之後依然100%。絕望的把
對應的tablespace
rename在新位置,並且online之後,關庫,重啟伺服器,發現df能正確的顯示百分比了,隨即一點一點的挪完。途中還碰到ORA-01525
ora-01533 等錯誤,在rename的時候,只能不移對應的資料檔案,還原回去online。

收集一下網上正確移動資料檔案的方法如下:

如果資料庫處於非歸檔模式下,可以通過如下步驟變更檔路徑:
1.關閉資料庫
2.系統級進行檔案複製
3.啟動資料庫到mount狀態
3.通過SQL


修改資料檔案位置
4.開啟資料庫
以下是實際操作的步驟示範:

1.資料庫處於非歸檔模式

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradata/conner/archive
Oldest online log sequence 150
Current log sequence 153

2.需要移動test.dbf檔案

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
/opt/oracle/test.dbf

3.關閉資料庫

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

4.複製檔案到新的位置

SQL> ! cp /opt/oracle/test.dbf /opt/oracle/oradata/conner/test.dbf

5.啟動資料庫到mount狀態

SQL> startup mount;
ORACLE instance started.

Total System Global Area 101782828 bytes
Fixed Size 451884 bytes
Variable Size 37748736 bytes
Database Buffers 62914560 bytes
Redo Buffers 667648 bytes
Database mounted.
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
/opt/oracle/test.dbf

6.修改檔案位置

SQL> alter database rename file '/opt/oracle/test.dbf' to '/opt/oracle/oradata/conner/test.dbf';

Database altered.

SQL> alter database open;

Database altered.


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
/opt/oracle/oradata/conner/test.dbf

SQL>

採用offline的方式

第一步,將資料表空間offline
alter tablespacetablespace_name
offline;
第二步,cp檔案到新的目錄並rename修改控制檔案
第三步,將相應資料表空間online
當然這種方式同樣會影響期間的資料表空間使用。

以下是簡單的示範步驟:
1.將資料表空間offline

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Nov 12 18:14:21 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 No Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradata/conner/archive
Oldest online log sequence 6
Current log sequence 9
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 offline;

Tablespace altered.

2.拷貝相應的資料檔案

SQL> ! cp /opt/oracle/oradata/conner/users01.dbf /opt/oracle/oradata/users01.dbf

SQL> alter tablespace users rename datafile '/opt/oracle/oradata/conner/users01.dbf'
to '/opt/oracle/oradata/users01.dbf';

Tablespace altered.

3.將資料表空間online

SQL> alter tablespace users online;

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

當然還有一些其他的方法可以採用.

以上兩種方法,可能在要求較高的24x7系統中不適合採用,因為會使資料表空間長時間不可用。
特別是當資料表空間資料檔案巨大時,物理拷貝可能需要較長的時間。

本文推薦另外一種方法,可以做一個折中,以下是一個簡單的步驟說明:
1.將資料表空間置於唯讀
唯讀狀態可以使資料仍然可為使用者訪問.
alter tablespacetablespace_name
read only;

2.物理拷貝檔案
3.將資料表空間offline
alter tablespacetablespace_name
offline;
4.rename資料檔案
alter database rename file'old_dir_file'
to'new_dir_file'
;
5.將資料表空間聯機
alter tablespacetablespace_name
online;
6.將資料表空間置於read write模式
alter tablespacetablespace_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>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.