對於oracle常用的導入導出工具:exp\imp,expdp\impdp后者速度快,但是expdp屬於服務端工具,而exp屬於客戶端工具,expdp生成的文件默認是存放在服務端的,而exp生成的文件是可以存放在客戶端的
expdp是server端工具,但可以通過NETWORK_LINK參數實現遠端導出,但是前提是遠端也安裝有Oracle數據庫,只有CLIENT端是沒有辦法利用數據泵的。
使用expdpusername/password@connect_string這種格式導出數據,生成的文件存放在服務端,可以通過在expdp中使用network_link完成再遠端服務器通過expdp導出數據。對於impdp亦然。
如:expdp system/oracledba directory=my_dir dumpfile=test.dmp logfile=test.log network_link=DB_LINK_TEST schemas=test01,test02 parallel=4
1、使用dblink遠程導出導入數據的步驟為:
1.1 在源端創建到服務端的 dblink
create database link link_name connect to username identified by password using 'connect_string' ;
//username和 password是 server端的,並且特別注意該處的connect_string 就為tnsnames.ora中的服務名(連接服務端的串),
如:
SQL> create public database link yjtestlink connect to yjtest identified by "yjtest22324" using '//177.100.42.102:30145/orcl';
Database link created.
創建完成以后可以使用dblink,查詢遠程數據庫表數據進行驗證
SQL> select count(*) from yjtest.devicemodel@dbnmslink;
COUNT(*)
----------
7921574
驗證成功
1.2 在源端創建導入導出文件夾並賦權
語句:
sqlplus / as sysdba
create or replace directory DMPDIR as 'directory';
grant read,write on directory DMPDIR to username;
sqlplus / as sysdba
create or replace directory dir as 'directory';
grant read,write on directory dir to yjsource;
1.3 源端使用dblink遠程導出數據
expdp 'yjsource/"yjsource123"@orclsource' schemas=yjtest directory=DMPDIR dumpfile=yjtest20201013.dmp log=ytest20201013.log network_link=yjtestlink tables=ALARMLOGINHIS
分區表network_link的說明:
這里要指出的是:network_link不支持遠端導出分區表中的某一個分區,但可以導整個分區表
2、遠程導出導入示例
ORCL1 是源端,ORCL2是服務端
2.1. IMPDP + network_link, 直接將源端數據導入到目標庫中(DUMP文件不落地)
--在ORCL2上創建DBLINK到ORCL1
create [public] database link <link_name> connect to
create public database link scms_test connect to dbmt identified by dbmt using '//192.168.1.144:1521/scms';
create public database link to_orcl1 connect to system identified by oracle using 'ORCL1';
--在ORCL2上執行IMPDP
$ impdp localusername/"localpasswd"@localsid' directory=DUMP_DIR logfile=impdp_to_orcl2.log network_link=to_orcl1 schemas=scott
2.2 EXPDP + network_link, 直接將源端庫上的數據,導出到目標端服務器上
--在ORCL2上創建DBLINK到ORCL1
create public database link to_orcl1 connect to system identified by oracle using 'ORCL1';
--在ORCL2上執行EXPDP,導出的DUMP文件在ORCL2上
expdp 'localusername/"localpasswd"@localsid' directory=DUMP_DIR logfile=expdp_from_orcl1.log network_link=to_orcl1 schemas=scott parallel=2