Oracle遷移資料資料表空間

來源:互聯網
上載者:User

為了一些大量基礎資料的測試案例,IMP匯入資料速度太慢,則使用下面方法可以對當前Oracle資料庫中個某個資料表空間資料快速備份恢複;下面的方法也適合兩個資料庫(必須相同作業系統,相同資料庫版本,相同字元集)之間的資料資料表空間移植。

實驗環境:
source:192.168.1.249    tablespace: anenjoy 
Target:192.168.1.248      tablespace:anenjoy02
步驟一:先確保你oracle啟動並執行平台支援transport tablespace (基本上都是支援的,學習下查看平台的命令)
SQL> select * from v$transportable_platform; (查看當前oracle下支援的平台)
SQL>  select platform_name from v$database;(查看當前oracle 啟動並執行平台)
SQL> select d.platform_name,endian_format from v$transportable_platform tp , v$database d where tp.platform_name=d.platform_name; (查看oracle啟動並執行平台是否在oracle 支援平台下,返回資料則為true)

步驟二:在source 上建立一個資料資料表空間和資料檔案
SQL> create tablespace anenjoy datafile '/opt/oracle/oradata/test05/test05.dbf' size 50m extent management local autoallocate;
Tablespace created.
基於資料表空間建立表
SQL> create table test (name varchar2(15),work varchar2(10))  tablespace anenjoy; (兩個欄位 name和work)
Table created.
    插入一些資料,
insert into test (name,work) values ('frank','IT');
SQL> select * from test;

NAME                          WORK
------------------------------ --------------------
frank                          IT
alex                          caiwu
leon                          yanfa

步驟三:Pick a Self-Contained Set of Tablespaces (查看是不是自含,也就是說需要傳輸的資料表空間是獨立的)
execute dbms_tts.transport_set_check('anenjoy',true);
如果你有多個資料表空間的話呢,用逗號隔開如:’anenjoy01,anenjoy02‘
輸出日誌:
PL/SQL procedure successfully completed.
執行命令,檢查下是否存在不能傳輸的資料表空間
SQL> select * from transport_set_violations;  如果有返回行,則需要處理後才可以傳輸

步驟四:產生傳輸字元集
首先要先將源資料表空間置於唯讀狀態,以防資料表空間資料的修改
SQL> alter tablespace anenjoy read only;
接下來就是資料的匯出步驟了(重要)

執行匯入操作。匯入操作應該與匯出操作相對應,若是以exp匯出的,需要以imp匯入,若是以expdp匯出的,需要以impdp匯入,參考使用官方的expdp和impdp
Host expdp system  dumpfile=expdat.dmp directory=data_pump_dir transport_tablespaces='anenjoy' logfile=tts_export.log;
中間會提示輸入system的密碼,如果你忘記這個密碼的話呢,可以參考上篇文章,學習下如何更改密碼
提示點一:這裡使用的是system的使用者,如果你使用的是你自己定義的使用者,那麼你需要在target 主機上建立此使用者
提示點二:命令列directory 參數data_pump_dir的路徑是在/opt/oracle/admin/test05/dpdump下,test05是資料庫名,這個目錄在oracle database安裝好之後就會建立的
可以通過SQL命令查看data_pump_dir 路徑
select * from dba_directories;
日誌輸出為:
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 13:36:16

步驟五:copy資料到target 主機上
Transport both the datafiles and the export (dump) file of the tablespaces to a place that is accessible to the destination database.
scp test05.dbf  oracle@192.168.1.248:/opt/oracle/oradata/test02/ (到target database 下)
scp -r dpdump/ oracle@192.168.1.248:/home/oracle/ (這個是export files)
然後呢,再將dpdump的檔案copy到target 相應的data_pump_dir下,也就是你/opt/oracle/admin/ORALE_SID/dpdump

步驟六:資料匯入
impdp system dumpfile=expdat.dmp directory=data_pump_dir transport_datafiles='/opt/oracle/oradata/test02/test05.dbf' logfile=tts_import.log
正常的日誌輸出:
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 00:41:33
之後,更改源和目標主機上的資料表空間屬性
Alter tablespace anenjoy read write; (兩台server上都去執行下)
驗證階段:
在target上,通過SQL 命令查看是否同步過來資料表空間anenjoy
SQL> select * from v$tablespace;

      TS# NAME  INCLUD BIGFIL FLASHB ENCRYP
6 ANENJOY  YES NOYES
查看錶空間anenjoy下的表資料
SQL> select * from test;

NAME                          WORK
------------------------------ --------------------
frank                          IT
alex                          caiwu
leon                          yanfa

現在就可以向表test中插入資料,也可以再target anenjoy 資料表空間下建立新的資料表和索引

[Oracle]資料表空間之間的資料移轉記錄 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.