Oracle Data Pump เป็นเครื่องมือใหม่ สำหรับ import-export ข้อมูล ทีมีความเร็ว และ ความยืดหยุ่น มากกว่า เครื่องมือ "exp" และ"imp" ที่ใช้ใน Oracle Database version ก่อนหน้านี้ ทั้งยังเพิ่มเติม PL/SQL API สำหรับการ import และ export เบื้องต้น รวมถึง สามารถใช้กับ external table ได้ด้วย
เริ่มแรก เราจะ unlock user SCOTT และ ให้มีสิทธิ CREATE ANY DIRECTORY เพราะ การ import-export จะใช้การอ้างชื่อ alias ของ directory แทนที่จะบอกเป็น physical path จริงๆ
[oracle@oracleskill~]# CONN sys/password@db10g AS SYSDBA
SQL> ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK;
SQL> GRANT CREATE ANY DIRECTORY TO scott;
SQL> CREATE OR REPLACE DIRECTORY test_dir
2> AS '/u01/app/oracle/oradata/';
SQL> GRANT READ, WRITE ON DIRECTORY test_dir TO scott;
การ Exports/Imports แบบเจาะจงตาราง
เราใช้ parameter ชื่อ TABLES ในการระบุตารางที่จะถูก export ออกมา ดังตัวอย่างต่อไปนี้[oracle@oracleskill~]# expdp scott/tiger@db10g tables=EMP,DEPT
directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log
[oracle@oracleskill~]# impdp scott/tiger@db10g tables=EMP,DEPT
directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log
เราสามารถดูผลได้ จาก log ไฟล์ ในที่นี้ คือ expdpEMP_DEPT.log และ impdpEMP_DEPT.log
เราสามารถเพิ่ม พารามิเตอร์ TABLE_EXISTS_ACTION=APPEND เพื่อเอาข้อมูลไปใส่ต่อ ในตารางที่มีอยู่แล้ว
การ Exports/ Imports ในระดับ Schema
ในเครื่องมือ exp เวอร์ชั่นก่อนๆ เราใช้ พารามิเตอร์ OWNER เพื่อระบุ Schema (ซึ่งก็คือชื่อ user เจ้าของตาราง นั่นแหละ) ที่เราจะ export ข้อมูลออกมา แค่ใน data pump export เราจะใช้ พารามิเตอร์ SCHEMAS แทน[oracle@oracleskill~]# expdp scott/tiger@db10g schemas=SCOTT
directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log
[oracle@oracleskill~]# impdp scott/tiger@db10g schemas=SCOTT
directory=TEST_DIR dumpfile=SCOTT.dmp logfile=impdpSCOTT.log
เราสามารถดูผลได้ จาก log ไฟล์ ในที่นี้ คือ expdpSCOTT.log and impdpSCOTT.log .
การ Exports/Imports ทั้ง database
พารามิเตอร์ FULL ใช้บอกว่าเป็นการ export ทั้ง database แบบสมบูรณ์ ซึ่ง user ที่ทำการ Exports/Import ต้องมีสิทธิ EXPORT FULL DATABASE และ IMPORT FULL DATABASE
ในที่นี้ เราจะใช้ user : system ทำการ import - export
[oracle@oracleskill~]# expdp system/password@db10g full=Y
directory=TEST_DIR dumpfile=DB10G.dmp logfile=expdpDB10G.log
[oracle@oracleskill~]# impdp system/password@db10g full=Y
directory=TEST_DIR dumpfile=DB10G.dmp logfile=impdpDB10G.log
เราสามารถดูผลได้ จาก log ไฟล์ ในที่นี้ คือ expdpDB10G.log
refer: http://www.oracleskill.com/oracle-tutorials/oracle-data-pump-import-export.html