1. DIRECTORY
指定轉儲檔案和記錄檔所在的目錄
DIRECTORY=directory_object
Directory_object用於指定目錄對象名稱.需要注意,目錄對象是使用CREATE DIRECTORY語句建立的對象,而不是OS目錄
Expdp scott/tiger DIRECTORY= DMP DUMPFILE=a.dump
create or replace directory dmp
as 'd:/dmp'
expdp zftang/zftang@zftang directory=dmp dumpfile=test.dmp content=metadata_only
2. CONTENT
該選項用於指定要匯出的內容.預設值為ALL
CONTENT={ALL | DATA_ONLY | METADATA_ONLY}
當設定CONTENT為ALL時,將匯出對象定義及其所有資料.為DATA_ONLY時,只匯出對象資料,為METADATA_ONLY時,只匯出對象定義
expdp zftang/zftang@zftang directory=dmp dumpfile=test.dmp content=metadata_only
----------只匯出對象定義
expdp zftang/zftang@zftang directory=dmp dumpfile=test.dmp content=data_only
----------匯出出所有資料 3. DUMPFILE
用於指定轉儲檔案的名稱,預設名稱為expdat.dmp
DUMPFILE=[directory_object:]file_name [,….]
Directory_object用於指定目錄對象名,file_name用於指定轉儲檔案名稱.需要注意,如果不指定directory_object,匯出工具會自動使用DIRECTORY選項指定的目錄對象
expdp zftang/zftang@zftang directory=dmp dumpfile=test1.dmp
資料泵工具匯出的步驟:
1、建立DIRECTORY
create directory dir_dp as 'D:/oracle/dir_dp';
2、授權
Grant read,write on directory dir_dp to zftang;
--查看目錄及許可權
SELECT privilege, directory_name, DIRECTORY_PATH FROM user_tab_privs t, all_directories d
WHERE t.table_name(+) = d.directory_name ORDER BY 2, 1;
3、執行匯出
expdp zftang/zftang@fgisdb schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log;
串連到: Oracle Database 10g Enterprise Edition Release 10.2.0.1
With the Partitioning, OLAP and Data Mining options
啟動 "ZFTANG"."SYS_EXPORT_SCHEMA_01": zftang/********@fgisdb sch
ory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log; */
備忘:
1、directory=dir_dp必須放在前面,如果將其放置最後,會提示 ORA-39002: 操作無效
ORA-39070: 無法開啟記錄檔。
ORA-39087: 目錄名 DATA_PUMP_DIR; 無效
2、在匯出過程中,DATA DUMP 建立並使用了一個名為SYS_EXPORT_SCHEMA_01的對象,此對象就是DATA DUMP匯出過程中所用的JOB名字,如果在執行這個命令時如果沒有指定匯出的JOB名字那麼就會產生一個預設的JOB名字,如果在匯出過程中指定JOB名字就為以指定名字出現
如下改成:
expdp zftang/zftang@fgisdb schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log,job_name=my_job1;
3、匯出語句後面不要有分號,否則如上的匯出語句中的job表名為‘my_job1;’,而不是my_job1。因此導致expdp zftang/zftang attach=zftang.my_job1執行該命令時一直提示找不到job表
資料泵匯出的各種模式:
1、 按表模式匯出:
expdp zftang/zftang@fgisdb tables=zftang.b$i_exch_info,zftang.b$i_manhole_info dumpfile =expdp_test2.dmp logfile=expdp_test2.log directory=dir_dp job_name=my_job
2、按查詢條件匯出:
expdp zftang/zftang@fgisdb tables=zftang.b$i_exch_info dumpfile =expdp_test3.dmp logfile=expdp_test3.log directory=dir_dp job_name=my_job query='"where rownum<11"'
3、按資料表空間匯出:
Expdp zftang/zftang@fgisdb dumpfile=expdp_tablespace.dmp tablespaces=GCOMM.DBF logfile=expdp_tablespace.log directory=dir_dp job_name=my_job
4、匯出方案
Expdp zftang/zftang DIRECTORY=dir_dp DUMPFILE=schema.dmp SCHEMAS=zftang,gwm
5、匯出整個資料庫:
expdp zftang/zftang@fgisdb dumpfile =full.dmp full=y logfile=full.log directory=dir_dp job_name=my_job
impdp匯入模式:
1、按表匯入
p_street_area.dmp檔案中的表,此檔案是以gwm使用者按schemas=gwm匯出的:
impdp gwm/gwm@fgisdb dumpfile =p_street_area.dmp logfile=imp_p_street_area.log directory=dir_dp tables=p_street_area job_name=my_job
2、按使用者匯入(可以將使用者資訊直接匯入,即如果使用者資訊不存在的情況下也可以直接匯入)
impdp gwm/gwm@fgisdb schemas=gwm dumpfile =expdp_test.dmp logfile=expdp_test.log directory=dir_dp job_name=my_job
3、不通過expdp的步驟產生dmp檔案而直接匯入的方法:
--從來源資料庫中向目標資料庫匯入表p_street_area
impdp gwm/gwm directory=dir_dp NETWORK_LINK=igisdb tables=p_street_area logfile=p_street_area.log job_name=my_job
igisdb是目的資料庫與來源資料的連結名,dir_dp是目的資料庫上的目錄
4、更換資料表空間
採用remap_tablespace參數
--匯出gwm使用者下的所有資料
expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp SCHEMAS=gwm
註:如果是用sys使用者匯出的使用者資料,包括使用者建立、授權部分,用自身使用者匯出則不含這些內容
--以下是將gwm使用者下的資料全部匯入到資料表空間gcomm(原來為gmapdata資料表空間下)下
impdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcomm
資料泵是伺服器端工具,匯出的檔案是放在資料庫所在的伺服器上,當然我們知道可以通過directory目錄對象來控制。目錄對象預設有四個層級,當然是有優先順序順序的,優先順序從上往下
1.每個檔案單獨的指定具體的目錄
2.expdp匯出時,指定的目錄參數
3.使用者定義的環境變數DATA_PUMP_DIR指定的目錄
4.預設的目錄對象DATA_PUMP_DIR
當然了對於oracle11g R2來說,又引入了一個可選項,我們就當是5
5.DATA_PUMP_DIR_SCHEMA_NAME目錄
一、預設的目錄對象DATA_PUMP_DIR測試
SQL> desc dba_directories
Name Null? Type
----------------------------------------------------------------- -------- ---------------------- OWNER NOT NULL VARCHAR2(30)
DIRECTORY_NAME NOT NULL VARCHAR2(30)
DIRECTORY_PATH VARCHAR2(4000)
SQL> set linesize 120 pagesize 100
SQL> col OWNER for a5
SQL> col DIRECTORY_NAME for a22
SQL> col DIRECTORY_PATH for a80
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
----- ---------------------- ----------------------------------------------------------
SYS SUBDIR /u01/app/oracle/product/11.2.0/db/demo/schema/order_entry//2002/Sep
SYS SS_OE_XMLDIR /u01/app/oracle/product/11.2.0/db/demo/schema/order_entry/
SYS LOG_FILE_DIR /u01/app/oracle/product/11.2.0/db/demo/schema/log/
SYS MEDIA_DIR /u01/app/oracle/product/11.2.0/db/demo/schema/product_media/
SYS XMLDIR /u01/app/oracle/product/11.2.0/db/rdbms/xml
SYS DATA_FILE_DIR /u01/app/oracle/product/11.2.0/db/demo/schema/sales_history/
SYS DATA_PUMP_DIR /u01/app/oracle/admin/tj01/dpdump/
SYS ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/db/ccr/state
通過查詢我們看到,所有的目錄都屬於SYS使用者,而不管是哪個使用者建立的,在資料庫裡已經提前建好了這個目錄對象DATA_PUMP_DIR。如果在使用expdp匯出時,不指定目錄對象參數,Oracle會使用資料庫預設的目錄DATA_PUMP_DIR,不過如果想使用這個目錄的話,使用者需要具有exp_full_database的許可權才行
SQL> conn scott/tiger
Connected.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
SQL> create table demo as select empno,ename,sal,deptno from emp;
Table created.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
由於沒有exp_full_database,所以這樣的匯出會報錯,你可以選擇授權或者使用有許可權的使用者
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp.dmp tables=emp
Export: Release 11.2.0.3.0 - Production on Fri Nov 16 13:48:19 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39145: directory object parameter must be specified and non-null
[oracle@asm11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 13:58:14 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> grant exp_full_database to scott;
Grant succeeded.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
授權之後,匯出成功,並且匯出的檔案和日誌會到DATA_PUMP_DIR對象指定的目錄
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp.dmp tables=emp
Export: Release 11.2.0.3.0 - Production on Fri Nov 16 13:58:52 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** dumpfile=emp.dmp tables=emp
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."EMP" 8.562 KB 14 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
/u01/app/oracle/admin/tj01/dpdump/emp.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 13:59:05
對於oracle11g來說,我們還可以定義一個新的目錄對象,對象名稱是DATA_PUMP_DIR_SCHEMA_NAME,如果定義了這個目錄對象,並授予許可權,在使用者匯出沒有指定
具體的目錄參數的情況下,匯出檔案會到這個目錄
[oracle@asm11g ~]$ mkdir sdir
[oracle@asm11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 14:13:06 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options