Oracle 數據庫導入與出



Oracle 數據庫導入與出

導出( EXPORT )是用 EXP 將數據庫部分或全對象的結構和導出 。 導入( 導入( IMPORT )是用 )是用 IMP IMP將 OS 文件中的對象結構和數據裝載到庫過程。

EXP 和 IMP 用於實現邏輯備份和恢復,導入出的作如下:


1、使用導出和入可以重新組織表。


2、使用導出和入可以在戶之前移動對象。


3、使用導出和入可以在數據庫之間移動對象。

典型事例:傳輸表空間
4、使用導出和入可以升級數據庫到其它平台。


5、使用導出和入可以升級數據庫到更高版本。


6、使用導出和入可以實現邏輯備份恢復。

    



一、 獲取幫助 獲取幫助 獲取幫助


$ exp help=y
$ imp help=y


二、 三種工作方式



1.交互式 方

[oracle@localhost ~]$ exp

Export: Release 11.2.0.3.0 - Production on Sun Jul 15 16:41:02 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


Username: system
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Enter array fetch buffer size: 4096 > 4096

Export file: expdat.dmp > a.dmp

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3

Export table data (yes/no): yes > yes

Compress extents (yes/no): yes > yes

Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)

About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > scott.dept

Current user changed to SCOTT
. . exporting table                           DEPT         10 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >

Export terminated successfully with warnings.
[oracle@localhost ~]$

交互式導出數據庫

image

交互式導入數據庫

image





image

實例:


1) 導出整個數據庫
2) 導出數據庫中某個用戶的所有對象
3) 導出特定的表

2.命令行方式


在命令行中輸入所需的參數 即可,如下所示:

exp user/pwd@dbname file=/oracle/test.dmp full=y
[oracle@localhost ~]$ exp system/oracle tables=scott.dept file=b.dmp

Export: Release 11.2.0.3.0 - Production on Sun Jul 15 17:02:57 2018

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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)

About to export specified tables via Conventional Path ...
Current user changed to SCOTT
. . exporting table                           DEPT         10 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
[oracle@localhost ~]$ ls
a.dmp  database  extertablefile  h:1dept.sql  h:1.lst           h:emp.txt                 oyt.lst      rlwrap-0.37.tar.gz
b.dmp  Desktop   grid            h:1emp.txt   h:1spooltest.txt  oracle_system_files_back  rlwrap-0.37
[oracle@localhost ~]$
View Code




實例:1) 導出整個數據庫


導出整個數據庫,只需要 導出整個數據庫,只需要 FULL 和 FILE 二個參數, FULLL 表示導出整 個文件, 包括所有的數據庫對象FILE 表示備份后的數據文件名。

exp system/oracle full=y file= full.dmp


只導出數據庫的結構,不要表即包含全備份。

exp system/oracle full=y rows=n file=full a.dmp


實例:2) 導出數據庫中某個用戶的所有對象


導出當前數據庫 中某個用戶的所有對象,作為該備份,使用 備份,使用 owner 參數指定。 導出該用戶所擁有的數據庫對象定義,以及 導出該用戶所擁有的數據庫對象定義,以及 對象所擁有的數據。使用 system 用戶登錄數據庫,該具有 DBA 權限, 所以它擁有訪問 scott 用戶的數據庫對象權限,可以導出 用戶的數據庫對象權限,可以導出 scott 用戶的所有 數據庫對象,也可以使用 數據庫對象,也可以使用 scott 用戶登錄數據庫 ,導出它自已擁有的用戶登錄數據庫 ,導出它自已擁有的對象。

exp system/oracle owner=scott file= userback_scott .dmp


exp scott /scott owner=scott file= back_user_scott .dmp


exp scott /scott file= back_user_scott .dmp


實例:3) 導出特定的表


導出特定用戶的表需要 tables 參數, 該后可以有幾個表名參數, 該后可以有幾個表名如導出的表不是當前用 戶,需要使如導出的表不是當前用 戶,需要使schema_name.table_name 的形 式,告訴 式,告訴 exp 這個表屬於哪用戶。 System 具有對用戶 scott 中表的訪 問權,所以該用戶可導出 scott 用 戶的表,如果使用 戶的表,如果使scott 用戶登錄 用戶登錄 數據庫,在導出自已的表時可以直接寫名不用加模式。
導出一張表

exp userid=hr/hr tables=jobs file=hr_tables.dmp log=/home/oracle/jobs.log


導出多張表

exp  userid=system/oracle  tables=scott.dept,tables=scott.emp  file=tables.dmp



exp userid=system /oracle tables= scott.dept ,scott.emp file= tables.dmp



exp scott/scotttables=dept,emp file=backup_scott_tables.dmp


導出表的部分數據 ,使用 query 參數

exp userid=hr/hr  file= hr_tables_9000.dmp tables=jobs  query= \'where MAX_SALARY \=9000 \'


注意:對字符采用 注意:對字符采用 注意:對字符采用 注意:對字符采用 \轉義。 轉義。
導出表結構

exp userid=hr/hr tables=jobs file= hr_jobs_str .dmp rows=n


導出觸發器

exp userid=hr/hr tables=jobs file= hr_job.dmp triggers=n indexes=n grants=n constraints=n


實例:4) 導出特定的表空間


image

exp system/oracle tablespaces=users  file=backup_tablespaces_users.dmp



exp system/oracle tablespaces=users file=backup_tablespaces_users.dmp rows=no



exp userid=\'/ as sysdba '/ as sysdba '/ as sysdba \' tablespaces=TBS_SINGLE ' file=/tmp/ODU.dmp transport_tablespace=y


3.參數文件方式 ,在參數 文件中輸入所需的在參數

$ exp parfile=username.par
--參數文件 username.par 內容
userid= sys tem /oracle  buffer=8192000  compress=n  grants=y file=/ home/ oracle/test.dmp full=y


三、種模式

  • 1、表方式,將指定的數據導出  /導入
  • 2、用戶方式,將指定的所有對象及數據導出 /導入
  • 3、全庫方式,將數據中的所有對象導出 /導入



EXP 的參數: 的參數: 的參數:

    

[oracle@localhost ~]$ exp help =y

Export: Release 11.2.0.3.0 - Production on Sun Jul 15 14:38:38 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.



You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:

     Example: EXP SCOTT/TIGER

Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword    Description (Default)      Keyword      Description (Default)
--------------------------------------------------------------------------
USERID     username/password          FULL         export entire file (N)
BUFFER     size of data buffer        OWNER        list of owner usernames
FILE       output files (EXPDAT.DMP)  TABLES       list of table names
COMPRESS   import into one extent (Y) RECORDLENGTH length of IO record
GRANTS     export grants (Y)          INCTYPE      incremental export type
INDEXES    export indexes (Y)         RECORD       track incr. export (Y)
DIRECT     direct path (N)            TRIGGERS     export triggers (Y)
LOG        log file of screen output  STATISTICS   analyze objects (ESTIMATE)
ROWS       export data rows (Y)       PARFILE      parameter filename
CONSISTENT cross-table consistency(N) CONSTRAINTS  export constraints (Y)

OBJECT_CONSISTENT    transaction set to read only during object export (N)
FEEDBACK             display progress every x rows (0)
FILESIZE             maximum size of each dump file
FLASHBACK_SCN        SCN used to set session snapshot back to
FLASHBACK_TIME       time used to get the SCN closest to the specified time
QUERY                select clause used to export a subset of a table
RESUMABLE suspend
when
a
space
related error
is
encountered(N) RESUMABLE_NAME
text
string used
to
identify resumable statement RESUMABLE_TIMEOUT wait
timefor
RESUMABLE
TTS_FULL_CHECK       perform full or partial dependency check for TTS
VOLSIZE              number of bytes to write to each tape volume
TABLESPACES          list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE             template name which invokes iAS mode export

Export terminated successfully without warnings.
[oracle@localhost ~]$

注:關於 resumable  resumable_name resumable_timeout 的信息 請從本文的 《管理可恢復的空間分配》部分了解




image

     image        image






IMP  部分參數解釋:

[oracle@localhost ~]$ imp help =y

Import: Release 11.2.0.3.0 - Production on Sun Jul 15 15:37:17 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.



You can let Import prompt you for parameters by entering the IMP
command followed by your username/password:

     Example: IMP SCOTT/TIGER

Or, you can control how Import runs by entering the IMP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword  Description (Default)       Keyword      Description (Default)
--------------------------------------------------------------------------
USERID   username/password           FULL         import entire file (N)
BUFFER   size of data buffer         FROMUSER     list of owner usernames
FILE     input files (EXPDAT.DMP)    TOUSER       list of usernames
SHOW     just list file contents (N) TABLES       list of table names
IGNORE   ignore create errors (N)    RECORDLENGTH length of IO record
GRANTS   import grants (Y)           INCTYPE      incremental import type
INDEXES  import indexes (Y)          COMMIT       commit array insert (N)
ROWS     import data rows (Y)        PARFILE      parameter filename
LOG      log file of screen output   CONSTRAINTS  import constraints (Y)
DESTROY                overwrite tablespace data file (N)
INDEXFILE              write table/index info to specified file
SKIP_UNUSABLE_INDEXES  skip maintenance of unusable indexes (N)
FEEDBACK               display progress every x rows(0)
TOID_NOVALIDATE        skip validation of specified type ids
FILESIZE               maximum size of each dump file
STATISTICS             import precomputed statistics (always)
RESUMABLE              suspend when a space related error is encountered(N)
RESUMABLE_NAME         text string used to identify resumable statement
RESUMABLE_TIMEOUT      wait time for RESUMABLE
COMPILE                compile procedures, packages, and functions (Y)
STREAMS_CONFIGURATION  import streams general metadata (Y)
STREAMS_INSTANTIATION  import streams instantiation metadata (N)
DATA_ONLY              import only data (N)
VOLSIZE                number of bytes in file on each volume of a file on tape

The following keywords only apply to transportable tablespaces
TRANSPORT_TABLESPACE import transportable tablespace metadata (N)
TABLESPACES tablespaces to be transported into database
DATAFILES datafiles to be transported into database
TTS_OWNERS users that own data in the transportable tablespace set

Import terminated successfully without warnings.
[oracle@localhost ~]$



   imageimageimageimageimageimage







實例:1、 導入整個數據庫

image

exp system/oracle full=y file=full.dmp
SQL> drop user scott cascade;
SQL> drop user hr cascade;
imp system/oracle full=y file=full.dmp ignore=Y


實例:2、 導入 指定用戶 的全部數據庫對象,不建用戶

 exp scott /scott  file=back_user_scott.dmp
 exp system /orac le owner=scott file= back_user_scott1 .dmp
 SQL> drop user scott cascade;
 SQL> create user scott identified by scott DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA 10M ON users;
 SQL> grant create session to scott;
 imp scott/scott file= back_user_scott.dmp ignore=y


imp system /oracle full=y file= back_user_scott1.dmp ignore=y


imp system/oracle file=back_user_scott1.dmp ignore=y fromuser=scott touser=scott


實例:3、 導入 特定的表


將特定的表導入指用戶

imp system/oracle  tables=emp file=back_user_scott1.dmp fromuser=scott touser= system


向用戶 system 導入了 scott 用戶的表 emp ,當導入 emp 表時其實就是在新用戶 system 的用戶表空間中創建一個並填充數據,最后基於該觸發器。
導入一張表

exp userid=hr/hr tables=jobs file= hr_tables.dmp log=/home/oracle/jobs.log
drop table jobs cascade constraints;
imp userid=hr/hr tables=jobs file= hr_tables.dmp log=/home/oracle/jobs.log


導入多張表

exp userid=system/oracle tables=scott.dept ,scott.emp file=tables.dmp
SQL> drop table emp purge;
SQL> drop table dept purge;
imp userid=system/oracle tables=dept,emp file=tables.dmp fromuser=scott  touser=scott


導入表的部分數據

exp userid=scott/scott file=scott_tables_ 7902.dmp tables=emp query=\'where empno \=7902 \'
delete from emp where empno=7902 ;

imp userid=scott/scott file=scott_tables_7902.dmp tables=emp ignore=y



四、傳輸表空間

image

imageimageimage








image

image

理解:big /little andian

image


rman>convert tablespace test2 to platform 'solaris[tm] OE (32-bit)' format 'd:/expdp_trans.dmp';

image

imp sys/oracle file=expdp.dmp datafile=expdp_trans.dmp  transport_tablespace=y


---  查詢各自數據庫的環境的:字節序
SELECT des.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp,V$DATABASE des WHERE tp.PLATFORM_NAME=des.PLATFORM_NAME;


[oracle@localhost ~]$ rlwrap sqlplus / as sysdba;

SQL*Plus: Release 11.2.0.3.0 Production on Sun Jul 15 19:53:09 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS@orcl> SELECT des.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp,V$DATABASE des WHERE tp.PLATFORM_NAME=des.PLATFORM_NAME;

PLATFORM_NAME
--------------------------------------------------------------------------------
ENDIAN_FORMAT
--------------
Linux IA (32-bit)
Little


SYS@orcl>


傳輸表空間的限制


image

傳輸表空間的自包含特性

image

         image



實現 傳輸表空間的步驟

imageimage

image

image





--在orcl庫進行
create tablespace wl datafile '/u01/app/oracle/oradata/orcl/wl01.dbf' size 100M extent management local;

create user u1 identified by oracle default tablespace wl;

grant connect,resource to u1;

create table u1.tab1 tablespace wl as select * from sys.dba_objects;

--分別在orcl和prod庫進行
SELECT des.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp,V$DATABASE des WHERE tp.PLATFORM_NAME=des.PLATFORM_NAME;

--在orcl庫進行
EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('wl',true);

SELECT * FROM TRANSPORT_SET_VIOLATIONS;

alter tablespace wl read only;

exp userid=\'/ as sysdba\' tablespaces=wl file=/tmp/wl.dmp transport_tablespace=y

--將orcl庫的wl表空間的數據文件和導出的DMP文件,傳送到目標數據庫平台上prod,通過拷貝導出的DMP文件到目標平台:拷貝表空間的數據文件到目標平台:

--在prod庫操作

--創建用戶:
SQL> create user u1 identified by u1;

--授予connect,resource角色授予給u1用戶:
SQL> grant connect,resource to u1;

imp userid=\'/ as sysdba\' tablespaces=wl file=/tmp/wl.dmp transport_tablespace=y datafiles=/tmp/wl01.dbf  fromuser=u1 touser=u1

--在orcl庫操作
--將被導入的表空間設置為可讀可寫:
SQL> alter tablespace wl read write;

--在prod庫操作
--以sys用戶登錄數據庫,查看v$tablespace視圖:
SQL> conn / as sysdba
SQL> select name from v$tablespace;

--以u1用戶連接到數據庫,查看user_tables視圖:
SQL> conn u1/oracle
SQL> select table_name from user_tables;


修改字符集:


---查看數據庫的字符集
sqlplus system/manager
col parameter for a40
col value for a40
set lines 200
select * from nls_database_parameters where PARAMETER='NLS_CHARACTERSET';
ZHS16GBK

--如不對可按以下方法修改(建議先備份)
1.SHUTDOWN IMMEDIATE;   -- or NORMAL
2.<do a full backup>
3.STARTUP MOUNT;
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
ALTER DATABASE OPEN;
ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;
4.SHUTDOWN IMMEDIATE;   -- or NORMAL
5.STARTUP;
6.
col parameter for a40
col value for a40
set lines 200
select * from nls_database_parameters where PARAMETER='NLS_CHARACTERSET';









管理可恢復的空間分配


         可恢復的空間分配功能掛起需要更多磁盤空間的數據庫操作而不是將 其終止。掛起操作時,可以在目的地表空間上分配更多磁盤空間或增加用 戶的配額。解決空間不足問題后,數據庫操作將自動恢復。

      進行恢復的語句稱為可恢復語句。如果掛起的語句是事務的一部分,則 也會掛起事務。當提供了磁盤空間而且掛起的語句恢復時,無論事務中是 否有掛起的語句,都可以提交或回滾事務。

以下條件會觸發可恢復的空間分配:


1、永久表空間或臨時表空間中的磁盤空間不足
2、表空間達到是最大極限
3、超過了用戶空間配額

還可以控制掛起語句的時間,默認的時間間隔是二個小時,超過了 這段時間,語句將失敗,並且給用戶或應用程序返回一條錯誤消息,如 同完全未掛起語句的情況一樣。

有四種可以恢復的命令:

1、可以恢復的select 語句:只有select 用戶臨時表空間中的空間 時,才可以恢復select 語句,主要指select 語句執行orader by、 distinct、union 等排序操作。
2、可以恢復的DML 命令:如insert、update、delete 的DML 命令 也會導致空間不足的情況。
3、可以恢復的SQL*LOADER 操作:SQL*LOADER 導入操作可 能導致空間不足的情形。
4、分配磁盤空間的DDL 命令:為新段或現有段分配磁盤空間的 所有DDL 命令均可以恢復。
create table ….. as select ..
create index….


一、配置可恢復的空間分配


        啟用和禁用可恢復的空間分配可以使用resumable_timeout 初始化參數, 如果將初始化參數resumable_timeout 設置為非零值,則將啟用可恢復的 空間分配。為該初始化參數指定的值確定掛起操作等待分配更多資源的 時間,在超出此時限后將終止操作。

SYS@orcl> show parameter resumable_timeout

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
resumable_timeout                    integer     0
SYS@orcl>
注:resumable_timeout 值為0 
表示沒有啟用 可恢復的空間分配;如果把 0 改為 20 則表示 當表空間分配不足的時候,數據庫會掛起20分鍾的時間。如果在這 20分鍾內給分配更多的表空間,則20分鍾之后,就可以直接分配執行了
 
         

        默認情況下,值0 表示禁用可恢復的空間分配。如果在系統級別啟 用,則所有會話都可以利用可恢復的空間分配功能,如果控制哪些用戶 可以啟用可恢復的空間分配功能,則授予resumable 系統權限。


Grant resumable to hr;


       一旦擁有了resumable 系統權限,用戶就可以使用alter session 命令啟用 些功能。

Alter session enable resumable;


        如果未將resumable_timeout 參數設置為非零或使用alter session 重寫, 默認可恢復的時限值是7200 秒(二個小時)

Alter session enable resumable timeout 10000;


         為了更方便地在數據字典視圖dba_resumable 和user_resumable 中確定可 恢復語句,可以使用name 參數恢復啟用可恢復的空間分配功能。

Alter session enable resumable name ‘create big index’;


         查詢dba_resumable 和user_resumable 時,可以看到啟用了此功能的會話 的狀態及當前執行的SQL 語句。

Select user_id,session_id,status,name,sql_text from dba_resumable;


       可以使用alter session 禁用可恢復的空間分配功能。

Alter session disable resumable;


實例:為scott 用戶配置可恢復的空間分配功能

--1、為scott 授予resumable 系統權限
SYS@orcl> alter user scott identified by scott account unlock;   -- 修改 scott用戶的登錄密碼並解鎖SYS@orcl> grant resumable to scott;   --分配權限
 SYS@orcl> create tablespace test datafile  '/u01/app/oracle/oradata/orcl/test.dbf' size 90K autoextend off;  --創建一個表空間。該表空間大小只要90k且不能自動擴展 SYS@orcl> select tablespace_name,autoextensible from dba_data_files where tablespace_name ='TEST';
 SYS@orcl> conn scott/scott    -- 連接到 scott用戶 
-- 2、為scott 用戶創建空間,並分配此表空間中的所有空間
SCOTT@orcl> createtable t1 tablespace test asselect * from emp;
-- 3、表空間滿后,再創建表,收到錯語
SCOTT@orcl> createtable t2 tablespace test asselect * from emp;
 ERROR at line 1:
 ORA-01658: unable tocreate INITIAL extent for segment in
 tablespace TEST
 --4、在scott 會話中啟用可恢復的空間分配功能,時限是3600 秒(60分)
SCOTT@orcl> altersession enable resumable timeout 3600;
-- 5、當用戶scott 再創建表時,不會終止創建並發出錯語消息,進入掛 起狀態,查看警報日志顯示了掛起些語句的信息
SCOTT@orcl> createtable t2 tablespace test asselect * from emp;
--打開另一個會話,查看警告日志文件
[oracle@togogo ~]$ tail -f
 /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
-- 6、開啟另一會話查詢數據字典dba_resumable 了解掛起語句的其它信 息
SYS@orcl> select  user_id,session_id,instance_id,status,name,sql_text,error_msg from  dba_resumable;
 --7、DBA 為剛創建的表空間增加100M 的空間
SYS@orcl> alterdatabase datafile  '/u01/app/oracle/oradata/orcl/test.dbf' resize 300K;
-- 8、再次查詢數據字典dba_resumable,確認可恢復操作是否已經完成
SYS@orcl> select user_id,session_id,instance_id,status,name,sql_text,error_msg from dba_resumable;
 --9、scott 用戶的創建表語句成功完成
SCOTT@orcl> createtable t2 tablespace test asselect * from emp;
--由於用戶必須等待DBA 手動分配更多空間,所以響應速度不如用 戶想的那么快。



另例:

--啟用可恢復的空間分配功能
SYS@orcl> alter session enable resumable;
SYS@orcl> create tablespace test datafile
 '/u01/app/oracle/oradata/orcl/test.dbf' size 100K autoextend off;
 SYS@orcl> create table t1(id number) tablespace test;
--掛起
SYS@orcl> create table t2(id number) tablespace test;
--禁用可恢復的空間分配功能
SYS@orcl> alter session disable resumable;
--報錯
SYS@orcl> create table t2(id number) tablespace test;




數據泵 方式數據的導入和導出

數據泵導入導出技術的結構


         在數據泵導出導入技術中,涉及導出實用程序expdp和導入實用程序impdp,當啟動數據泵導入或導出程序時,在數據庫服務器端啟動相應的服務器進程,完成數據的導入及導出任務,所以也稱數據泵技術是基於oracle數據庫服務器的,導入及導出的數據文件也保存在數據庫服務器端。
         expdp程序啟動數據庫服務器端的服務器進程,服務器進程完成數據的備份並將備份文件寫入數據庫服務器端磁盤中,導出的備份文件在導入時只能數據泵的導入實用程序impdp完成。
使用數據泵技術的優點:
1、可以只處理某些對象,或者不處理某些對象,或只處理某些對象下滿足條件的數據
2、不實際導出的情況下,估計整個導出工作需要占用的磁盤空間
3、只導出元數據(如表結構),不導出實際數據。
4、可以進行並行操作


數據泵導入導出的目錄對象

        數據泵作業在數據庫服務器上創建所有的備份文件,要求數據泵必須使用目錄對象,以防止用戶誤操作數據庫服務器上特定目錄下的操作系統文件。目錄對象對應於操作系統上的一個指定目錄。
        如果當前用戶是DBA用戶,可以使用默認的目錄對象而不必再創建數據泵操作的工作目錄。此時數據泵作業會將備份文件、日志文件以及SQL文件存儲在該目錄下,查看默認目錄:

SQL> col directory_name for a15
SQL> col owner for a23
SQL> col directory_path for a50
SQL> select * from dba_directories where directory_name='DATA_PUMP_DIR';


         不具備目錄對象的數據泵作業錯誤

[oracle@oracle Desktop]$ expdp scott/scott
Export: Release 11.2.0.4.0 - Production on Fri Jan 17 17:04:18 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, 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
---如果需要自已創建目錄對象,需要具有create any directory權限,首先向scott用戶授權create any directory,然后創建屬於scott用戶的數據泵目錄對象。
SQL> grant create any directory to scott;
SQL> conn scott/scott
SQL> create directory scott_dump_dir as '/home/oracle';




sys用戶給 普通用戶 scott 授權 創建文件目錄和訪問sys用戶創建的文件目錄的權限


---給scott用戶 授權創建文件目錄
SYS@orcl> grant create any directory to scott;

Grant succeeded.

SYS@orcl> ho ls /home/oracle
a.dmp  database  extertablefile  h:1dept.sql  h:1.lst           h:emp.txt                 oyt.lst      rlwrap-0.37.tar.gz
b.dmp  Desktop   grid            h:1emp.txt   h:1spooltest.txt  oracle_system_files_back  rlwrap-0.37


SYS@orcl> ho mkdir /home/oracle/dexp

SYS@orcl> ho ls /home/oracle
a.dmp  database  dexp            grid         h:1emp.txt  h:1spooltest.txt  oracle_system_files_back  rlwrap-0.37
b.dmp  Desktop   extertablefile  h:1dept.sql  h:1.lst     h:emp.txt         oyt.lst                   rlwrap-0.37.tar.gz
---sys用戶創建  文件目錄 dexpdirectory 
SYS@orcl> create directory dexpdirectory as '/home/oracle/dexp';

Directory created.
---把sys用戶創建的 文件目錄 dexpdirectory  給普通用戶scott 讀寫的權限
SYS@orcl> grant  read ,write on directory dexpdirectory to scott;

Grant succeeded.

SYS@orcl>



使用如下SQL查詢具有READ和WRITE權限的目錄


--使用如下SQL查詢具有READ和WRITE權限的目錄

SET lines 80
COL grantee FORMAT a20
COL privilege FORMAT a10
SELECT directory_name, grantee, privilege  FROM user_tab_privs t, all_directories d   WHERE t.table_name(+)=d.directory_name   ORDER BY 1,2,3;


expdp參數

 

[oracle@localhost ~]$ expdp help =y

Export: Release 11.2.0.3.0 - Production on Sun Jul 15 21:55:23 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


The Data Pump export utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:

   Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Export runs by entering the 'expdp' command followed
by various parameters. To specify parameters, you use keywords:

   Format:  expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
   Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

------------------------------------------------------------------------------

The available keywords and their descriptions follow. Default values are listed within square brackets.

ATTACH
Attach to an existing job.
For example, ATTACH=job_name.

CLUSTER
Utilize cluster resources and distribute workers across the Oracle RAC.
Valid keyword values are: [Y] and N.

COMPRESSION   
Reduce the size of a dump file.  --對導出的文件dump 進行壓縮  
Valid keyword values are(壓縮方式): ALL(所有壓縮, DATA_ONLY(數據壓縮,可以理解為:表數據的壓縮), [METADATA_ONLY](默認壓縮:元數據壓縮,可以理解為表結構的壓縮) and NONE(不壓縮).

CONTENT
Specifies data to unload.(指定要導出的數據)
Valid keyword values are: [ALL](導出所有數據), DATA_ONLY(數據) and METADATA_ONLY(元數據).

DATA_OPTIONS
Data layer option flags.(指定一個選項)
Valid keyword values are: XML_CLOBS.

DIRECTORY
Directory object to be used for dump and log files.(必須要指定的目錄對象)

DUMPFILE
Specify list of destination dump file names [expdat.dmp].(導出文件) For example, DUMPFILE=scott1.dmp(文件名稱), scott2.dmp(文件名稱), dmpdir(文件目錄名稱):scott3.dmp(文件名稱).



ENCRYPTION
Encrypt part or all of a dump file.(對導出的dump文件進行加密)
Valid keyword values are: ALL(全部加密), DATA_ONLY(對數據加密), ENCRYPTED_COLUMNS_ONLY(對數據列加密), METADATA_ONLY(對元數據加密) and NONE(不加密).

ENCRYPTION_ALGORITHM   (加密算法)
Specify how encryption should be done.
Valid keyword values are: [AES128](默認128位加密), AES192 and AES256.

ENCRYPTION_MODE  (加密模式)
Method of generating encryption key.
Valid keyword values are: DUAL, PASSWORD and [TRANSPARENT].

ENCRYPTION_PASSWORD  (對加密文件創建一個數據口令)
Password key for creating encrypted data within a dump file.

ESTIMATE
Calculate job estimates.(分析)
Valid keyword values are: [BLOCKS](默認為:數據庫分析) and STATISTICS(統計分析).

ESTIMATE_ONLY  (僅僅分析大小不導出數據文件)
Calculate job estimates without performing the export.

EXCLUDE (排除)
Exclude specific object types.
For example, EXCLUDE=SCHEMA:"='HR'".(要導出除了HR對象以外的對象的整個數據庫數據信息)
1)"EXCLUDE=SCHEMA:\"='HR'\"" 

2)將EXCLUDE=SCHEMA:"='HR'"加入到參數文件中
 vi togogo
 加入EXCLUDE=SCHEMA:"='HR'"
parfile=togogo
 
          



FILESIZE Specify the size
of each dump file in units of bytes. (指定最大的dump文件的大小) FLASHBACK_SCN (用於指定導出特定scn時刻的表數據) SCN used to reset session snapshot. FLASHBACK_TIME (指定導出特定時間點的表數據) Time used to find the closest corresponding SCN value. FULL (整庫導出) Export entire database [N]. HELP (顯示出幫助信息) Display Help messages [N]. INCLUDE (包含:指定導出時要包含的對象類型及相關對象) Include specific object types. For example, INCLUDE=TABLE_DATA. JOB_NAME (數據泵是以作業的方式來運行的:指定一個作業的名稱 ,也可不指定則系統默認指定一個名稱) Name of export job to create. LOGFILE Specify log file name [export.log]. (指定一個日志文件的名稱) NETWORK_LINK (當要導出遠程的數據庫的時候可以指定一個databaselike的標識) Name of remote database link to the source system. NOLOGFILE Do not write log file [N]. (不寫日志文件) PARALLEL Change the number of active workers for current job. (指定幾個並行的工作任務) PARFILE Specify parameter file name. (參數文件) QUERY (導出表的部分數據 ,使用 query 參數) Predicate clause used to export a subset of a table. For example, QUERY=employees:"WHERE department_id > 10". REMAP_DATA Specify a data conversion function. (指定一個轉換的函數,重新映射數據。作用:把敏感的數據通過一個轉行方法給轉換掉) For example, REMAP_DATA=EMP.EMPNO:REMAPPKG.EMPNO. REUSE_DUMPFILES (同名文件時 是否需要自動覆蓋) Overwrite destination dump file if it exists [N]. SAMPLE (導出多少) Percentage of data to be exported. SCHEMAS (導出什么模式:即:導出哪個數據庫用戶的數據) List of schemas to export [login schema]. SERVICE_NAME Name of an active Service and associated resource group to constrain Oracle RAC resources. SOURCE_EDITION Edition to be used for extracting metadata. STATUS (顯示狀態信息) Frequency (secs) job status is to be monitored where the default [0] will show new status when available. TABLES (導出表) Identifies a list of tables to export. For example, TABLES=HR.EMPLOYEES,SH.SALES:SALES_1995. TABLESPACES (導出表空間) Identifies a list of tablespaces to export. TRANSPORTABLE (傳輸表) Specify whether transportable method can be used. Valid keyword values are: ALWAYS and [NEVER]. TRANSPORT_FULL_CHECK Verify storage segments of all tables [N]. TRANSPORT_TABLESPACES (傳輸表空間) List of tablespaces from which metadata will be unloaded. VERSION (版本:高版本的數據導入到低版本數據庫的時候:需要制定版本信息) Version of objects to export. Valid keyword values are: [COMPATIBLE], LATEST or any valid database version. ------------------------------------------------------------------------------ The following commands are valid while in interactive mode.(交互式命令,中途是可以暫停的。) Note: abbreviations are allowed. ADD_FILE (增加文件) Add dumpfile to dumpfile set. CONTINUE_CLIENT Return to logging mode. Job will be restarted if idle. EXIT_CLIENT (退出客戶端執行) Quit client session and leave job running. FILESIZE (文件大小) Default filesize (bytes) for subsequent ADD_FILE commands. HELP Summarize interactive commands. KILL_JOB (結束當前作業) Detach and delete job. PARALLEL (平行度) Change the number of active workers for current job. REUSE_DUMPFILES (覆蓋) Overwrite destination dump file if it exists [N]. START_JOB (開始作業) Start or resume current job. Valid keyword values are: SKIP_CURRENT. STATUS (查看作業狀態) Frequency (secs) job status is to be monitored where the default [0] will show new status when available. STOP_JOB (停止作業) Orderly shutdown of job execution and exits the client. Valid keyword values are: IMMEDIATE.




      attach


     用於在客戶會話與已存在導出作業之間建立關聯,

     語法如下:attach=[schema_name.]job_name,schema_name
      用於指定方案名,job_name指定導出作業名,如果使用attach選項,在命令行除了連接字符串和attach選項外,不能指定任何其它選項。
    

  expdp scott/tiger attach=scott.export_job

         content


用於指定要導出的內容,默認是all,

語法如下: CONTENT={ALL | DATA_ONLY | METADATA_ONLY},
當設置content選項為all時,將導出對象定義及其所有數據,當設置該選項為data_only時,只能導出對象數據;當設置該選項為metadata_only時,只導出對象定義。

expdp scott/tiger directory=dump dumpfile=a.dmp content=metadata_only


        directory


用於指定轉儲文件和日志文件所在位置。

語法如下:directory=directory_object

directory_object用於指定目錄對象名稱。目錄對象是使用create directory語句建立的對象,而不是os目錄。

expdp scott/tiger directory=dump dumpfile=a.dmp

         dumpfile


指定轉儲文件的名稱,默認名稱為expda.dmp,

   語法如下:dumpfile=[directory_object:]file_name[,...],

                  directory_object指定目錄對象名

                  file_name指定轉儲文件名。

expdp scott/tiger directory=dump1 dumpfile=dump2:a.dmp

         estimate


用於指定估算被導出表所占用磁盤空間的方法,默認值為blocks,

語法如下: Estimate={blocks|statistics},

設置blocks時,oracle會按照目標對象占用的數據塊個數乘以數據塊尺寸估算對象占用的空間,

設置statistics時,oracle會根據最近的統計值估算對象占用的空間。

expdp scott/tiger tables=emp estimate=statistics directory=dump dumpfile=a.dmp

        estimate_only


用於指定是否估算出作業所占用的磁盤空間,默認n,

語法如下:estimate_only={y|n},

設置為y時,導出作業只估算對象所占用的磁盤空間,而不會執行導出操作,

設置為n時,導出作業不僅估算對象所占用的磁盤空間,且會執行導出操作。

expdp scott/tiger estimate_only=y nologfile=y

         exclude


用於指定執行導出操作時要排除的對象類型或相關對象,

語法如下:exclude=object_type[:name_clause][,...],

object_type指定要排除的對象類型,

name_clause指定要排除的具體對象,

exclude和include不能同時使用。

expdp scott/tiger directory=dump dumpfile=a.dmp exclude=view

        filesize


用於指定導出文件的最大尺寸,默認值是0(表示文件尺寸無限制)

語法如下:filesize=integer[B|K|M|G]

expdp scott/tiger directory=dump dumpfile=hr_3M.dmp filesize=3M

         flashback_time


指定導出特定時間點的表數據。

語法如下:flashback_time=”to_timestamp(time_value)”

time_value用於指定日期時間值,

flashback_time和flashback_scn不能同時用。

expdp scott/tiger directory=dump dumpfile=a.dmp flashback_time=”to_teimstamp(’25-08-2009 14:34:00’,’dd-mm-yyyy hh24:mi:ss’)”

         flashback_scn


用於指定導出特定scn時刻的表數據。

語法如下:flashback_scn=scn_value

expdp scott/tiger directory=dump dumpfile=a.dmp flashback_scn=385823


        full


指定數據庫模式導出,默認主n,

語法如下:full={y|n},

設置為y時,表示執行數據庫導出。

expdp scott/tiger directory=dump dumpfile=full.dmp full=y

         include

指定導出時要包含的對象類型及相關對象。

語法如下:include=object_type[:name_clause][,...],

object_type指定要導出的對象類型,

name_clause指定要導出的對象名。

expdp scott/tiger directory=dump dumpfile=a.dmp include=table

         job_name


指定導出作業的名稱,

語法如下:job_name=jobname_string

jobname_string用於指定導出作業的名稱。

expdp scott/tiger directory=dump dumpfile=a.dmp job_name=wangli

         logfile


指定導出日志文件的名稱,默認名稱為export.log,

語法如下:LOGFILE=[directory_object:]file_name。

directory_object用於指定目錄對象名稱,

file_name用於指定導出日志文件名。

expdp scott/tiger directory=dump dumpfile=a.dmp logfile=a.log


        network_link


指定數據庫鏈名,如果要將遠程數據庫對象導出到本地例程的轉儲文件中,必須設置些選項。

語法如下:NETWORK_LINK=source_database_link

source_database_link 用於指定數據庫鏈名。

expdp scott/tiger directory=dump dumpfile=a.dmp network_like=orcl

         nologfile


用於指定禁止發生導出日志文件,默認值n,

語法如下:nologfile={y|n}

設置為y時,導出操作不會生成日志文件 。

expdp scott/tiger dumpfile=dump:a.dmp nologfile=y


         parallel


用於指定執行導出操作的並行進程個數,默認是1,

語法如下:parallel=integer
Integer用於指定並行進程個數。通過執行並行導出操作,可以加快導出速度。

Expdp scott/tiger directory=dump dumpfile=a.dmp parallel=3


        parfile


指定導出參數文件的名稱,

語法如下:PARFILE=[directory_path]file_name。

directory_path指定參數文件所在目錄,

file_name指定參數文件名。

參數文件a.txt示例如下:

tables=dept,emp
Directory=dump
Dumpfile=tab.dmp

參數文件不能包含parfile選項。參數文件里不指定directory_path

Expdp scott/tiger parfile=a.txt


         Query


指定過濾導出數據的where條件,

語法如下;query=[schema.][table_name:]query_lause
Schema用於指定方案名,

table_name指定表名,

query_lause指定條件限制子句,

query選項不能與connect=metadata_only、estimate_only、transport_tablespaces等選項同時使用。

expdp scott/tiger directory=dump dumpfile=a.dmp tables=emp query=’”where deptno=20”’


         schemas


指定執行方案模式導出,默認為當前用戶方案,

語法如下:SCHEMAS=方案名稱[,…]
方案名稱:用於指定方案名,用戶可以導出自身方案,但如果要導出其它方案,須具有exp_full_daabase角色或DBA角色。

Expdp system/manager directory=dump dumpfile=a.dmp schemas=scott,system


        status


指定顯示導出作業進程的詳細狀態,默認為0,

語法如下:STATUS=[整數],

整數用於指定顯示導出作業狀態的時間間隔(秒),指定了該選項后,每隔特定時間會顯示作業完成的百分比。

expdp system/manager directory=dump dumpfile=a.dmp full=y status=30


         tables


用於指定表模式導出。

語法如下:TABLES=[schema_name.]table_name[:partition_name][,…]
schema_name指定方案名,

table_name指定要導出的表名,

partition_name用於指定要導出的分區名。用戶可以直接導出其自身方案的表,但要導出其它方案的表,須具有exp_full_daabase角色或DBA角色。

expdpd system/manager directory=dump dumpfile=a.dmp tables=scott.dept,scott.emp


        tablespaces


指定要導出的表空間列表,

語法如下:TABLESPACE=tablespace_name[,…]
tablespace_name用於指定要導出的表空間。指定選項時,會導出該表空間上的所有表。

Expdp system/manager directory=dump dumpfile=a.dmp tablespaces=user01


         transport_full_check


用於指定被搬移表空間和末搬移表演關聯關系的檢查方式,默認值是n,

語法如下:TRANSPORT_FULL_CHECK={Y|N}

設置為y時,導出作業會檢查表空間之間的完整關聯關系,如果表所在表空間或其索引所在表空間只有一個表空間被搬移,將顯示錯誤信息,

當設置該選項為n時,導出作業只檢查單端依賴,如果搬移索引所在的表空間但末搬移表所在表空間,將顯示錯誤信息,如果搬移表所在表空間,末搬移索引所在表空間,則不會顯示錯誤信息

expdp system/manager directory=dump dumpfile=b.dmp transport_tablespaces=user01 transport_full_check=y


         transport_tablespaces


指定執行表空間模式導出,

語法如下:TRANSPORT_TABLESPACES=Tablespace_name[,…]
Tablespace_name用於指定要導出的表空間名稱,導出表空間時,要求數據庫用戶必須有exp_full_database角色或DBA角色。

expdp system/manager directory=dump dumpfile=b.dmp transport_tablespaces=user01


數據泵導出實例


使用empd可以導出整個數據庫、單個模式、特定的表或特定的表空間。


      1、導出整個數據庫

         我們使用system用戶登錄數據庫,限制備份的數據文件大小為230M,一旦備份數據文件滿,則自動創建一個新的備份文件,使用%U來實現備份文件的自動創建,nologfile=y即不記錄備份過程。

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:mydb_%U.dat filesize=230M nologfile=y job_name=tom full=y


           2、導出一個模式;

  導出scott模式,在例子中沒有schema參數,但是默認導出登錄數據庫時的模式對象。

[oracle@oracle Desktop]$ expdp scott/scott dumpfile=scott_dump_dir:scottschema.dmp logfile=scott_dump_dir:scottschema.log



[oracle@oracle Desktop]$ expdp scott/scott directory= scott_dump_dir dumpfile=scottschema.dmp logfile=scott_dump_dir:scottschema.log schemas=scott


          3、導出特定的表

 使用tables參數指定導入的表的列表,如果該表不屬於登錄的用戶,但是登錄用戶有訪問這些表的權限,則tables參數的表必須使用schema.tablename的方式。

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:scott_tables_%U.dat tables=scott.emp,scott.dept nologfile=y job_name=only_scott


          4、導出表空間


導出表空間使用tablespaces參數,如果有多個表空間需要導出,表空間名使用逗號隔開,使用parallel參數指定數據導出並行線程數量,與之對應使用替換變量%U來創建相應數量的備份數據文件,這樣每個線程可以獨立寫一個備份數據文件,提高導出速度。

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:users_tbs_%U.dmp tablespaces=users filesize=230M parallel=2 logfile=users_tbs.log job_name=exp_users_tbs


           5、導出數據;


使用content參數,可以指定導出表數據和元數據(應用參數all),導出表行數據(對應參數data_only)或只導出元數據即表以及其他數據庫對象的定義(對應參數metadata_only)

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:mydb_dataony_%U.dat filesize=230M job_name=larry full=y content=data_only logfile=pump_dir:mydb_exp_dataonly.log


           6、使用參數文件


在使用expdp導出數據時,由於參數很多導致每次執行備份都輸入一大串指令,這樣不但繁瑣且不易修改,數據泵技術允許使用參數文件,用戶在參數文件中創建各種參數,保存該文件paraname.par文件,然后再執行導出時使用parfile指定參數文件的位置執行導出備份。

[oracle@oracle ~]$ vi paraname.par
directory=pump_dir
dumpfile=para_data_only_%U.dmp
 content=data_only
exclude=table:"in('salgrade','bonus')"
 logfile=para_data_only.log
 filesize=50M
 parallel=2
 job_name=para_data_only
 [oracle@oracle ~]$ expdp scott/scott parfile=/home/oracle/paraname.par


           7、估計空間導出文件的空間大小


estimate_only計算導出數據所需要的存儲空間,在導出的數據大小不清楚時,事先知道備份文件的大小,可以提前分配磁盤空間,防止由於磁盤空間不足引起的expdp導出作業停止。

[oracle@oracle ~]$ expdp system/oracle full=y estimate_only=y estimate=statistics nologfile=y


使用STATISTICS方法計算system用戶所有數據庫對象的大小。最后給出一個總的估計結果。

           8:交互式導出整個庫

[oracle@localhost ~]$ expdp system/oracle  directory=DEXPDIRECTORY dumpfile=full.dmp full=y

Export: Release 11.2.0.3.0 - Production on Tue Jul 17 22:41:02 2018

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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_FULL_02":  system/******** directory=DEXPDIRECTORY dumpfile=full.dmp full=y
Estimate in progress using BLOCKS method...
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 436.6 MB
Processing object type DATABASE_EXPORT/TABLESPACE
Processing object type DATABASE_EXPORT/PROFILE
Processing object type DATABASE_EXPORT/SYS_USER/USER
Processing object type DATABASE_EXPORT/SCHEMA/USER
Processing object type DATABASE_EXPORT/ROLE
Processing object type DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/ROLE_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/DEFAULT_ROLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLESPACE_QUOTA
Processing object type DATABASE_EXPORT/RESOURCE_COST
Processing object type DATABASE_EXPORT/TRUSTED_DB_LINK
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/SEQUENCE
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/DIRECTORY/DIRECTORY
Processing object type DATABASE_EXPORT/DIRECTORY/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/CONTEXT
Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/INC_TYPE
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/TYPE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PRE_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PROCOBJ
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/POST_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SCHEMA/PROCACT_SCHEMA
Processing object type DATABASE_EXPORT/SCHEMA/XMLSCHEMA/XMLSCHEMA
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/PRE_TABLE_ACTION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/COMMENT
ORA-39171: Job is experiencing a resumable wait.
ORA-01652: unable to extend temp segment by 128 in tablespace TBS_20_GROUP
ORA-39171: Job is experiencing a resumable wait.
ORA-01652: unable to extend temp segment by 128 in tablespace TBS_20_GROUP
ORA-39171: Job is experiencing a resumable wait.
ORA-01652: unable to extend temp segment by 128 in tablespace TBS_20_GROUP
ORA-39171: Job is experiencing a resumable wait.
ORA-01652: unable to extend temp segment by 128 in tablespace TBS_20_GROUP

Export> status

Job: SYS_EXPORT_FULL_02
  Operation: EXPORT
  Mode: FULL
  State: EXECUTING
  Bytes Processed: 0
  Current Parallelism: 1
  Job Error Count: 0
  Dump File: /home/oracle/dexp/full.dmp
    bytes written: 4,096

Worker 1 Status:
  Process Name: DW01
  State: EXECUTING
  Object Type: DATABASE_EXPORT/SCHEMA/TABLE/COMMENT
  Completed Objects: 720
  Worker Parallelism: 1

Export> stop_job
Are you sure you wish to stop this job ([yes]/no): yes

[oracle@localhost ~]$ ls /home/oracle/dexp/
export.log  full.dmp
[oracle@localhost ~]$ 


impdp參數


[oracle@localhost ~]$ impdp help=y

Import: Release 11.2.0.3.0 - Production on Mon Jul 16 00:31:14 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.


The Data Pump Import utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:

     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Import runs by entering the 'impdp' command followed
by various parameters. To specify parameters, you use keywords:

     Format:  impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

USERID must be the first parameter on the command line.

------------------------------------------------------------------------------

The available keywords and their descriptions follow. Default values are listed within square brackets.

ATTACH
Attach to an existing job.  (用於在客戶會話與已存在導出作業之間建立關聯) For example, ATTACH=job_name.

CLUSTER
Utilize cluster resources and distribute workers across the Oracle RAC.
Valid keyword values are: [Y] and N.

CONTENT
Specifies data to load.
Valid keywords are: [ALL], DATA_ONLY and METADATA_ONLY.

DATA_OPTIONS
Data layer option flags.
Valid keywords are: SKIP_CONSTRAINT_ERRORS.

DIRECTORY
Directory object to be used for dump, log and SQL files.

DUMPFILE
List of dump files to import from [expdat.dmp].
For example, DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.

ENCRYPTION_PASSWORD
Password key for accessing encrypted data within a dump file.
Not valid for network import jobs.

ESTIMATE
Calculate job estimates.
Valid keywords are: [BLOCKS] and STATISTICS.

EXCLUDE
Exclude specific object types.
For example, EXCLUDE=SCHEMA:"='HR'".

FLASHBACK_SCN
SCN used to reset session snapshot.

FLASHBACK_TIME
Time used to find the closest corresponding SCN value.

FULL
Import everything from source [Y].

HELP
Display help messages [N].

INCLUDE
Include specific object types.
For example, INCLUDE=TABLE_DATA.

JOB_NAME
Name of import job to create.

LOGFILE
Log file name [import.log].

NETWORK_LINK
Name of remote database link to the source system.

NOLOGFILE
Do not write log file [N].

PARALLEL
Change the number of active workers for current job.

PARFILE
Specify parameter file.

PARTITION_OPTIONS
Specify how partitions should be transformed.
Valid keywords are: DEPARTITION, MERGE and [NONE].

QUERY
Predicate clause used to import a subset of a table.
For example, QUERY=employees:"WHERE department_id > 10".

REMAP_DATA
Specify a data conversion function.
For example, REMAP_DATA=EMP.EMPNO:REMAPPKG.EMPNO.

REMAP_DATAFILE (將源數據文件名轉變為目標數據文件名)
Redefine data file references in all DDL statements.
 REMAP_SCHEMA (用於將源方案的所有對象裝載到目標方案中 fromuser touser )
Objects from one schema are loaded into another schema.

REMAP_TABLE
Table names are remapped to another table.
For example, REMAP_TABLE=HR.EMPLOYEES:EMPS.

REMAP_TABLESPACE
Tablespace objects are remapped to another tablespace.

REUSE_DATAFILES
Tablespace will be initialized if it already exists [N].

SCHEMAS
List of schemas to import.

SERVICE_NAME
Name of an active Service and associated resource group to constrain Oracle RAC resources.

SKIP_UNUSABLE_INDEXES
Skip indexes that were set to the Index Unusable state.

SOURCE_EDITION
Edition to be used for extracting metadata.

SQLFILE
Write all the SQL DDL to a specified file.

STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.

STREAMS_CONFIGURATION
Enable the loading of Streams metadata

TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.

TABLES
Identifies a list of tables to import.
For example, TABLES=HR.EMPLOYEES,SH.SALES:SALES_1995.

TABLESPACES
Identifies a list of tablespaces to import.

TARGET_EDITION
Edition to be used for loading metadata.

TRANSFORM
Metadata transform to apply to applicable objects.
Valid keywords are: OID, PCTSPACE, SEGMENT_ATTRIBUTES and STORAGE.

TRANSPORTABLE
Options for choosing transportable data movement.
Valid keywords are: ALWAYS and [NEVER].
Only valid in NETWORK_LINK mode import operations.

TRANSPORT_DATAFILES
List of data files to be imported by transportable mode.

TRANSPORT_FULL_CHECK
Verify storage segments of all tables [N].

TRANSPORT_TABLESPACES
List of tablespaces from which metadata will be loaded.
Only valid in NETWORK_LINK mode import operations.

VERSION
Version of objects to import.
Valid keywords are: [COMPATIBLE], LATEST or any valid database version.
Only valid for NETWORK_LINK and SQLFILE.

------------------------------------------------------------------------------

The following commands are valid while in interactive mode.
Note: abbreviations are allowed.

CONTINUE_CLIENT
Return to logging mode. Job will be restarted if idle.

EXIT_CLIENT
Quit client session and leave job running.

HELP
Summarize interactive commands.

KILL_JOB
Detach and delete job.

PARALLEL
Change the number of active workers for current job.

START_JOB
Start or resume current job.
Valid keywords are: SKIP_CURRENT.

STATUS
Frequency (secs) job status is to be monitored where
the default [0] will show new status when available.

STOP_JOB
Orderly shutdown of job execution and exits the client.
Valid keywords are: IMMEDIATE.


[oracle@localhost ~]$




         attach


用於在客戶會話與已存在導入作業之間建立關聯,

語法如下:attach=[schema_name.]job_name,schema_name
用於指定方案名,job_name指定導出作業名,如果使用attach選項,在命令行除了連接字符串和attach選項外,不能指定任何其它選項。

impdp scott/tiger attach=import_job


         content


用於指定要導入的內容,默認是all,語法如下:
CONTENT={ALL | DATA_ONLY | METADATA_ONLY},
專業 專注 超越 數據泵
當設置content選項為all時,將導入對象定義及其所有數據,當設置該選項為data_only時,只能導入對象數據;當設置該選項為metadata_only時,只導入對象定義。

impdp scott/tiger directory=dump dumpfile=a.dmp content=data_only tables=dept,emp


         directory


用於指定轉儲文件所在位置。

語法如下:directory=directory_object

directory_object用於指定目錄對象名稱。目錄對象是使用create directory語句建立的對象,而不是os目錄。

impdp scott/tiger directory=dump dumpfile=a.dmp tables=emp


         dumpfile


指定轉儲文件的名稱,默認名稱為expda.dmp,

語法如下:dumpfile=[directory_object:]file_name[,...]directory_object指定目錄對象名,file_name指定轉儲文件名。

impdp scott/tiger directory=dump dumpfile=a.dmp tables=emp


         estimate


用於指定估算執行網絡導入操作時要生成的數據量,默認值為blocks,

語法如下:Estimate={blocks|statistics},設置blocks時,oracle會根據數據塊個數乘以數據塊尺寸估算要生成的數據量,設置statistics時,oracle會根據統計值估算對要生成的數據量。

impdp scott/tiger tables=emp estimate=statistics directory=dump dumpfile=a.dmp


         exclude


用於指定執行導入操作時要過濾的對象類型或特定對象,

語法如下:exclude=object_type[:name_clause][,...],

object_type指定對象類型,

name_clause指定對象名。

impdp scott/tiger directory=dump dumpfile=a.dmp exclude=cluster


         flashback_time


指定導入特定時間點的表數據。

語法如下:flashback_time=”to_timestamp(time_value)”

 time_value用於指定日期時間值,

flashback_time和flashback_scn不能同時用。

impdp scott/tiger directory=dump flashback_time=”to_teimstamp(’25-08-2009 14:34:00’,’dd-mm-yyyy hh24:mi:ss’)”


         flashback_scn


用於指定導入特定scn時刻的表數據。

語法如下:flashback_scn=scn_value


impdp scott/tiger directory=dump flashback_scn=385823


         full


指定是否要導入轉儲文件的全部內容,默認y

,語法如下:full={y|n},

設置為y時,表示所有內容。

impdp scott/tiger directory=dump dumpfile=full.dmp full=y

         include


指定導入時要包含的對象類型及相關對象。

語法如下:include=object_type[:name_clause][,...],

object_type指定要導入的對象類型,

name_clause指定要導入的對象名。

impdp scott/tiger directory=dump dumpfile=a.dmp include=view


         job_name


指定導入操作的作業名稱,

語法如下:job_name=jobname_string,

jobname_string用於指定導出作業的名稱。

impdp scott/tiger directory=dump dumpfile=a.dmp job_name=wangli


         logfile


指定導入日志文件的名稱,默認名稱為export.log,

語法如下:LOGFILE=[directory_object:]file_name。

directory_object用於指定目錄對象名稱,

file_name用於指定導出日志文件名。

impdp scott/tiger directory=dump dumpfile=a.dmp logfile=a.log


         network_link


指定數據庫鏈名,如果要將遠程數據庫對象導入到本地例程的轉儲文件中,必須設置些選項。

語法如下:NETWORK_LINK=source_database_link 。

source_database_link用於指定數據庫鏈名。

impdp scott/tiger directory=dump tables=emp network_like=orcl


         nologfile


用於指定禁止生成入日志文件,默認值n,

語法如下:nologfile={y|n}設置為y時。


impdp scott/tiger dumpfile=a.dmp nologfile=y


         parallel


用於指定執行並行導入操作,默認是1,

語法如下:parallel=integer


Integer用於指定並行進程個數。通過執行並行導出操作,可以加快導出速度。

impdp scott/tiger directory=dump dumpfile=a.dmp parallel=3


         parfile


指定導入參數文件的名稱,

語法如下:PARFILE=[directory_path]file_name。

directory_path指定參數文件所在目錄,

file_name指定參數文件名。

參數文件a.txt示例如下:

tables=dept,emp
 Directory=dump
 Dumpfile=tab.dmp
參數文件不能包含parfile選項。參數文件里不指定directory_path


impdp scott/tiger parfile=a.txt



         query


指定過濾導入數據的where條件,

語法如下;query=[schema.][table_name:]query_lause
Schema用於指定方案名,

table_name指定表名,

query_lause指定條件限制子句,

query選項不能與connect=metadata_only、estimate_only、transport_tablespaces等選項同時使用。


impdp scott/tiger directory=dump dumpfile=tab.dmp tables=emp query=’”where deptno=20”’


         schemas


指定執行方案模式導入,默認為當前用戶方案,

語法如下:SCHEMAS=方案名稱[,…]
方案名稱:用於指定方案名,

用戶可以導入自身方案,但如果要導入其它方案,須具有exp_full_daabase角色或DBA角色。

impdp system/manager directory=dump dumpfile=tab.dmp schemas=scott


         status


指定顯示導入作業的詳細狀態,默認為0,

語法如下:STATUS=[整數],

整數用於指定顯示導出作業狀態的時間間隔(秒),指定了該選項后,每隔特定時間會顯示作業完成的百分比。

impdp system/manager directory=dump dumpfile=full.dmp full=y status=10


         tables


用於指定表模式導入。語法如下:TABLES=[schema_name.]table_name[:partition_name][,…]
schema_name指定方案名,table_name指定要導入的表名,partition_name用於指定要導入的分區名。
impdpd system/manager directory=dump dumpfile=tab.dmp tables=emp

         tablespaces


指定執行表空間模式導入,語法如下:TABLESPACE=tablespace_name[,…]
tablespace_name用於指定要導入的表空間。

impdp system/manager directory=dump dumpfile=a.dmp tablespaces=user01

         transport_full_check


用於指定被搬移表空間和末搬移表演關聯關系的檢查方式,默認值是n,語法如下:TRANSPORT_FULL_CHECK={Y|N}設置為y時,導入作業會檢查表空間之間的完整關聯關系,如果表所在表空間或其索引所在表空間只有一個表空間被搬移,將顯示錯誤信息,當設置該選項為n時,導入作業只檢查單端依賴,如果搬移索引所在的表空間,但末搬移表所在表空間,將顯示錯誤信息,如果搬移表所在表空間,末搬移索引所在表空間,則不會顯示錯誤信息
impdp system/manager directory=dump dumpfile=b.dmp transport_tablespaces=user01 transport_full_check=y transport_datafiles=’/u01/app/oracle/tbs6.dbf’

         transport_tablespaces


指定執行表空間模式導入,語法如下:TRANSPORT_TABLESPACES=Tablespace_name[,…]
Tablespace_name用於指定表空間名稱,導入表空間時,要求數據庫用戶必須有imp_full_database角色或DBA角色。
impdp system/manager directory=dump dumpfile=b.dmp transport_tablespaces=user01

         transport_datafiles


指定搬移表空間時要被導入到目標數據庫的數據文件

         Table_exists_action


指定當表存在時,導入作業要執行的操作。默認是skip,語法如下:
table_exists_action={skip|append|truncate|replace}

         skip_unusable_indexes


指定導入時是否跳過不可使用的索引,默認是n,語法如下:skip_unusable_indexes={y|n}

         reuse_datafiles


指定建立表空間時是否覆蓋已存在的數據文件,默認n,語法如下:Reuse_datafiles={y|n}

         remap_tablespace


用於將源表空間的所有對象導入到目標表空間中,語法如下:remap_tablespace=source_tablespace:target_tablespace。source_tablespace指定源表間名稱,        target_tablespace指定目標表空間名稱。

         remap_schema


用於將源方案的所有對象裝載到目標方案中,語法如下:
remap_schema= source_schema:target_ schema

         remap_datafile


將源數據文件名轉變為目標數據文件名,語法如下:
remap_ datafile = source_ datafile:target_ datafile

數據泵導入實例


使用數據泵導入impdp可以導入基於使用數據泵導出的備份文件,可以導入整個數據庫,指定的表空間,指定的表或指定的數據庫對象類型,如索引、函數、存儲過程和觸發器等。

          1、 導入整個數據庫


導入整個數據庫至少需要二個參數,一個是full,設置full=y說明是導入全庫,一個是dumpfile,說明要導入的備份文件的目錄和名稱,job_name參數,允許切換到交換模式,允許終止或重啟導入會話

[oracle@oracle oracle]$ mkdir /u01/app/oracle/wl/
 [oracle@oracle ~]$ sqlplus / as sysdba
 SQL> startup
 SQL> create directory pump_dir as '/u01/app/oracle/wl';
 SQL> select * from dba_directories where directory_name='PUMP_DIR';

導出:
[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:full_db_%U.dat filesize=230M nologfile=y job_name=tom full=y
SQL> drop user scott cascade;

導入:
[oracle@oracle Desktop]$ impdp system/oracle dumpfile=pump_dir:full_db_%U.dat logfile= pump_dir:myfulldb.log parallel=3 job_name=my_fulldb_impdp full=y

          2、 導入表空間


使用impdp導入特定的表空間時,需要有備份表空間文件,需要使用tablespaces參數說明要導入的表空間名,此時實際上是導入表空間中的所有數據庫對象,由於表空間中有表對象,需要使用table_exits_action來告訴impdp怎么做,可以使用replace重建表,truncate刪除當前表中的數據,然后使用備份文件中的表數據進行加載,但會跳過所有相關元數據。

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:users_tbs_%U.dmp tablespaces=users filesize=230M parallel=2 logfile=users_tbs.log job_name=exp_users_tbs
SQL> drop table scott.emp;
SQL> drop table scott.dept;
[oracle@oracle Desktop]$ impdp system/oracle dumpfile=pump_dir:users_tbs_%U.dmp logfile= pump_dir:users.log tablespaces=users  table_exists_action=replace

          3、 導入指定的表


使用impdp導入特定的表使用tables參數,該參數的后,是要導入表的對象列表,如果有多個表,使用逗號分隔。

[oracle@oracle Desktop]$ expdp system/oracle dumpfile=pump_dir:scott_tables_%U.dat tables=scott.emp,scott.dept nologfile=y job_name=only_scott
 SQL> drop table scott.emp;
 SQL> grant read,write on directory pump_dir to scott;
 [oracle@oracle Desktop]$ impdp scott/scott dumpfile=pump_dir:scott_tables_%U.dat nologfile=y tables=emp table_exists_action=replace

如將表dept,emp 導入到scott 方案中
impdp scott/tiger directory=dump_scott dumpfile=tab.dmp tables=dept,emp

如將表dept 和emp 從scott 方案導入到system 方案中,對於方案的轉移,必須使
用remap_shcema 參數
impdp system/manage directory=dump_scott dumpfile=tab.dmp
 tables=scott.dept,scott.emp remap_schema=scott:system

          4、 導入指定的數據庫對象


導入指定的數據庫對象使用include參數,恢復scott用戶的所有表和觸發器對象,對於已存在的表則重新加載數據

[oracle@oracle wl]$ expdp system/oracle dumpfile=pump_dir:full_db_%U.dat filesize=230M nologfile=y job_name=tom full=y
[oracle@oracle wl]$ impdp scott/scott dumpfile=pump_dir:full_db_%U.dat nologfile=y include=table,trigger table_exists_action=replace


導入方案
如將dump_scott 目錄下的schema.dmp 導入到scott 方案中

impdp scott/tiger directory=dump_scott dumpfile=schema.dmp schemas=scott

如將scott 方案中的所有對象轉移到system 方案中

impdp system/redhat directory=dump_scott dumpfile=schema.dmp schemas=scott remap_schema=scott:system


表空間遷移

參考傳輸表空間的方式來實現數據泵的傳輸表空間



Oracle 11g expdp中COMPRESSION參數

--Oracle 11g expdp中COMPRESSION參數:ALL, DATA_ONLY, [METADATA_ONLY] and NONE
--Oracle 10g expdp中COMPRESSION參數: (METADATA_ONLY) and NONE

--一、創建目錄對象
create directory wl as '/home/oracle';
grant read,write on directory wl to scott;

--二、使用compression參數導出
--1)使用ALL參數,數據泵會對導出的源數據和表數據都進行壓縮,這種方式導出的文件是最小的,不過用時相對也會比較長expdp scott/scott dumpfile=scott_ALL.dmp logfile=scott_ALL.log tables=emp directory=wl compression=ALL

--2)使用DATA_ONLY參數,數據泵對表數據進行壓縮,這種壓縮方式對於大數據量的導出效果明顯

expdp scott/scott dumpfile=scott_DATA_ONLY.dmp logfile=scott_DATA_ONLY.log tables=emp directory=wl compression=DATA_ONLY

--3)使用METADATA_ONLY參數,數據泵只對源數據進行壓縮,這種壓縮執行后效果一般不是很明顯,不過速度比較快
expdp scott/scott dumpfile=scott_METADATA_ONLY.dmp logfile=scott_METADATA_ONLY.log tables=emp directory=wl compression=METADATA_ONLY

--4)使用NONE參數,不進行任何的壓縮,導出后數據文件也是最大的
expdp scott/scott dumpfile=scott_NONE.dmp logfile=scott_NONE.log tables=emp directory=wl compression=NONE

--比較生成的四個dump文件大小
du -sm scott*.dmp
--使用ALL參數和DATA_ONLY參數生成的備份文件基本一樣大;使用METADATA_ONLY參數與NONE參數效果一樣。


--對於默認方式,即不指定COMPRESSION參數,會采用默認的壓縮方式METADATA_ONLY


expdp flashback_scn&flashback_time

conn / as sysdba
drop user wl cascade;
create user wl identified by wl;
grant connect,resource to wl;
GRANT execute ON dbms_flashback TO wl;
grant read,write on directory wl to wl;
conn wl/wl
create table test(id number);
insert into test values(1);
commit;
conn / as sysdba
select dbms_flashback.get_system_change_number from dual;
select current_scn from v$database;
2286919
select * from wl.test;
ID
---
1
insert into wl.test values(2);
commit;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
2013-10-05 17:39:11
select * from wl.test;

ID
----
1
2
insert into wl.test values(3);
commit;
select * from wl.test;

ID
---
1
2
3

expdp wl/wl directory=wl dumpfile=scn.dmp logfile=scn.log flashback_scn=2286919
--導出1條數據
expdp wl/wl directory=wl dumpfile=scn1.dmp logfile=scn1.log
--導出3條數據
expdp wl/wl directory=wl dumpfile=scntime.dmp logfile=scntime.log flashback_time="'2013-10-05 17:39:11'"
--導出2條數據















EXPDP IMPDP 中的並行度PARALLEL

-------PARALLEL工作原理:控制執行任務的最大線程數。當指定參數值為1 時,表示最多只啟動一個線程處理數據,設置為 3 時,表示最多啟動三個線程並行處理數據,由於同一時間一個DUMP文件只允許一個線程處理,所以輸出的文件若只有一個,即使PARALLEL=10,也只有1 個線程進行數據輸出,其他9 個空閑。所以PARALLEL需要與FILESIZE參數一起使用,指定每個DUMP文件的大小。
--如:
expdp system/oracle DIRECTORY=wl DUMPFILE=full_parallel_%U full=y LOGFILE=full_parallel PARALLEL=4 FILESIZE=200M status=1

--EXPDP在數據量較大並且配置合理的情況下,可以極大地提高我們的備份效率,但要經過測試,否則會出錯


expdp reuse_dumpfiles

--使用reuse_dumpfiles選項,用戶可以指定是否覆蓋原文件

expdp scott/scott directory=my_dir dumpfile=wl.dmp tables=emp

expdp scott/scott directory=my_dir dumpfile=wl.dmp tables=emp

--錯誤如下:
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31641: unable to create dump file "/home/oracle/wl.dmp"
ORA-27038: created file already exists

--加reuse_dumpfiles=y選項
expdp scott/scott directory=my_dir dumpfile=wl.dmp tables=emp reuse_dumpfiles=y




expdp transportable

---TRANSPORTABLE用於指定表的遷移,TRANSPORTABLE方式不會導出真正的數據,而是采用將包含指定表的目標表空間遷移到目標數據庫中,唯一不同的是TRANSPORTABLE的對象是個別表,而不是整個表空間。

---一、在源數據庫的tt1表空間上建立3張表
create directory my_dir as '/home/oracle';
grant read,write on directory my_dir to scott;
grant exp_full_database to scott;
create tablespace tt1 datafile '/u01/app/oracle/oradata/orcl/tt1.dbf' size 20M;
conn scott/scott
create table test1 (id number) tablespace tt1;
create table test2 (id number) tablespace tt1;
create table test3 (id number) tablespace tt1;
insert into test2 values(2);
insert into test3 values(3);
commit;

--二、源數據庫設置只讀,並檢查源數據庫的DB_BLOCK_SIZE大小
select table_name,tablespace_name from user_tables where tablespace_name='TT1';
conn  / as sysdba
alter tablespace tt1 read only;
show parameter db_block_size

---三、在源數據庫使用TRANSPORTABLE方式導出test2和test3兩張表,在源數據庫導出的時候,Oracle並沒有導出表的數據,而是采用了遷移表空間的方式,且導出之后提示需要傳輸數據文件信息。

host expdp scott/scott directory=my_dir dumpfile=tt.dmp tables=test2,test3 transportable=always

---四、將dump文件和數據文件發送到目標數據庫站點
scp /u01/app/oracle/oradata/orcl/tt1.dbf oracle@192.168.0.11:/u01/app/oracle/oradata/orcl/
scp /home/oracle/tt.dmp oracle@192.168.0.11:/home/oracle/

---五、將源數據庫的tt1表空間置於READ WRITE狀態:
alter tablespace tt1 read write;

---六、源數據庫的操作結束,下面檢查目標數據庫指定表空間和對象是否存在
select tablespace_name from dba_tablespaces;
select object_name from user_objects where object_name like 'TEST%';

---七、檢查目標數據庫的DB_BLOCK_SIZE和源數據庫是否一致,如果不一致需要設置DB_nK_CACHE_SIZE的值
show parameter db_block_size
如不一致使用alter system進行設置,如下:
alter system set db_32K_cache_size= 64M;

---八、執行導入
create directory my_dd as '/home/oracle';
grant read,write on directory my_dd to scott;
grant imp_full_database to scott;
host impdp scott/scott directory=my_dd dumpfile=tt.dmp transport_datafiles='/u01/app/oracle/oradata/orcl/tt1.dbf'

---九、檢查目標數據庫指定表空間和對象是否存在
conn scott/scott
select object_name from user_objects where object_name like 'TEST%';
select table_name,tablespace_name from user_tables where tablespace_name='TT1';
select * from test2;
select * from test3;

---------需要注意,在拷貝本地的數據文件到遠端站點之前,不要將表空間置於READ WRITE狀態,否則會導致IMPDP過程出錯。只要表空間在拷貝之前至於READ WRITE狀態,即使在拷貝的時候再次置於READ ONLY狀態也不行,這時導入過程也會出現錯誤。
















=================================================================================================


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM