DataPump使用说明

     DataPump使用说明

一、Export与Import


[oracle@rac1 ~]$ exp help=y

1.1  Export

1.1.1 表模式


exp icdmain/icd rows=y indexes=n compress=n buffer=655360 feedback=100000 file=exp.dmp log=exp.log tables=tab1,tab2,tab3

1.1.2 用户模式

exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=655360 feedback=100000 file=exp.dmp log=exp.log

1.1.3 完全模式

exp icdmain/icd rows=y indexes=n compress=n buffer=655360 feedback=100000 full=y  file=exp.dmp log=exp.log

1.2 Import

1.2.1 表模式


导入所有表
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=655360 feedback=100000 ignore=n file=exp.dmp log=imp.log

导入指定表
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=655360 feedback=100000  ignore=n file=exp.dmp  log=imp.log  tables=t1,t2,t3

1.2.2 用户模式


导入所有内容
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=655360 feedback=100000 ignore=n file=exp.dmp log=imp.log

导入指定的表
imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=655360 feedback=100000 ignore=n file=exp.dmp log=imp.log tables=t1,t2,t3;

1.2.3 完全模式

imp system/manager rows=y indexes=n commit=y buffer=655360 feedback=100000 ignore=y full=y  file=exp.dmp  log=imp.log

1.3 参数选择及原理

1.3.1 ignore


     Oracle在恢复数据的过程中,当恢复某个表时,该表已经存在,就要根据ignore参数的设置来决定如何操作。

     若ignore=y,Oracle不执行CREATE TABLE语句,直接将数据插入到表中,如果插入的记录违背了约束条件,比如主键约束,则出错的记录不会插入,但合法的记录会添加到表中。

     若ignore=n,Oracle不执行CREATE TABLE语句,同时也不会将数据插入到表中,而是忽略该表的错误,继续恢复下一个表。

1.3.2 indexes

     在恢复数据的过程中,若indexes=n,则表上的索引不会被恢复,但是主键对应的唯一索引将无条件恢复,这是为了保证数据的完整性。

1.3.3 字符集转换

     对于单字节字符集(例如US7ASCII),恢复时,数据库自动转换为该会话的字符集(NLS_LANG参数);

     对于多字节字符集(例如ZHS16CGB231280),恢复时,应尽量使字符集相同(避免转换),如果要转换,目标数据库的字符集应是输出数据库字符集的超集。

1.4  Import常见问题及解决

1.4.1 数据库对象已经存在

     一般情况, 导入数据前应该彻底删除目标数据下的表, 序列, 函数/过程,触发器等;  数据库对象已经存在, 按缺省的imp参数, 则会导入失败如果用了参数ignore=y, 会把exp文件内的数据内容导入如果表有唯一关键字的约束条件, 不合条件将不被导入如果表没有唯一关键字的约束条件, 将引起记录重复。

1.4.2 数据库对象有主外键约束
     在执行全库导入和schema导入时,外键约束没有影响。
     但是按表导入时,不符合主外键约束时, 数据会导入失败。
     解决办法:
     先导入主表, 再导入依存表
     disable目标导入对象的主外键约束, 导入数据后, 再enable它们

1.4.3 权限不够
     如果要把A用户的数据导入B用户下, A用户需要有imp_full_database权限

1.4.4 导入大表( 大于80M ) 时, 存储分配失败
     默认的EXP时, compress = Y, 也就是把所有的数据压缩在一个数据块上.
     导入时, 如果不存在连续一个大数据块, 则会导入失败. 导出80M以上的大表时, 记得compress= N, 则不会引起这种错误.

1.4.5 字符集转换
     imp和exp使用的字符集不同
     如果字符集不同, 导入会失败, 可以改变unix环境变量或者NT注册表里NLS_LANG相关信息.  导入完成后再改回来.

1.4.6 imp和exp版本不能往上兼容
     可以从低版本导入高版本,但不能从高版本导入到低版本。    
     如果遇到迁移因版本不同的问题,可以用低版本的export 导出,到导入到低版本。

1.5 exp优化

     在使用exp时,可以采用直接路径模式。 这种模式有2个相关的参数:DIRECT 和RECORDLENGTH参数。

  DIRECT参数定义了导出是使用直接路径方式(DIRECT=Y),还是常规路径方式(DIRECT=N)。常规路径导出使用SQL SELECT语句从表中抽取数据,直接路径导出则是将数据直接从磁盘读到PGA再原样写入导出文件,从而避免了SQL命令处理层的数据转换过程,大大提高了导出效率。在数据量大的情况下,直接路径导出的效率优势更为明显,可比常规方法速度提高三倍之多。

  和DIRECT=Y配合使用的是RECORDLENGTH参数,它定义了Export I/O缓冲的大小,作用类似于常规路径导出使用的BUFFER参数。建议设置RECORDLENGTH参数为最大I/O缓冲,即65535(64kb)。其用法如下:

     如:exp userid=system/manager full=y direct=y recordlength=65535 file=exp_full.dmp log=exp_full.log

直接路径方式的一些限制如下:

     You cannot use the DIRECT=Y parameter when exporting in tablespace-mode  (i.e. when specifying the parameter TRANSPORT_TABLESPACES=Y).  You can use the DIRECT=Y parameter when exporting in full, user or table mode (i.e.: when specifying FULL=Y or OWNER=scott or TABLES=scott.emp).
--直接路径不能使用在tablespace-mode

The parameter QUERY applies ONLY to conventional path Export. It cannot be specified in a direct path export (DIRECT=Y).
--直接路径不支持query 参数。 query 只能在conventional path模式下使用。

In versions of Export prior to 8.1.5, you could not use direct path Export for tables containing objects and LOBs.
--如果exp 版本小于8.1.5,不能使用exp 导入有lob字段的biao。 不过现在很少有有8版本的数据库了。 这点可以忽略掉了。

The BUFFER parameter applies ONLY to conventional path Export. It has no effect on a direct path Export. This BUFFER parameter specifies the size (in bytes) of the buffer used to fetch rows. It determines the maximum number of rows in an array, fetched by Export.  For direct path Export, use the RECORDLENGTH parameter to specify the size of the buffer that Export uses for writing to the export file.
-- buffer 选项只对conventional path exp有效。 对于直接路径没有影响。 对于直接路径, 应该设置RECORDLENGTH 参数。

The RECORDLENGTH parameter specifies the length (in bytes) of the file record. You can use this parameter to specify the size of the Export I/O buffer (highest value is 64 kb). Changing the RECORDLENGTH parameter affects only the size of data that accumulates before writing to disk.  It does not affect the operating system file block size.  If you do not define this parameter, it defaults to your platform-dependent value for BUFSIZ (1024 bytes in most cases).

invoking a Direct path Export with a maximum I/O buffer of 64kb can improve the performance of the Export with almost 50%. This can be achieved by specifying the additional Export parameters DIRECT and RECORDLENGTH
-- 对于直接路径下, RECORDLENGTH参数建议设成64k(65535)。这个值对性能提高比较大。  如:
> exp system/manager FILE=exp_full.dmp LOG=exp_full.log
FULL=y DIRECT=y RECORDLENGTH=65535
> imp system/manager FILE=exp_full.dmp LOG=imp_full.log
FULL=y RECORDLENGTH=65535

1.6 imp优化

Oracle Import进程需要花比Export进程数倍的时间将数据导入数据库。某些关键时刻,导入是为了应对数据库的紧急故障恢复。为了减少宕机时间,加快导入速度显得至关重要。没有特效办法加速一个大数据量的导入,但我们可以做一些适当的设定以减少整个导入时间。

(1)避免I/O竞争
     Import是一个I/O密集的操作,避免I/O竞争可以加快导入速度。如果可能,不要在系统高峰的时间导入数据,不要在导入数据时运行job等可能竞争系统资源的操作。

(2)增加排序区
  Oracle Import进程先导入数据再创建索引,不论INDEXES值设为YES或者NO,主键的索引是一定会创建的。创建索引的时候需要用到排序区,在内存大小不足的时候,使用临时表空间进行磁盘排序,由于磁盘排序效率和内存排序效率相差好几个数量级。增加排序区可以大大提高创建索引的效率,从而加快导入速度。

(3)调整BUFFER选项
  Imp参数BUFFER定义了每一次读取导出文件的数据量,设的越大,就越减少Import进程读取数据的次数,从而提高导入效率。BUFFER的大小取决于系统应用、数据库规模,通常来说,设为百兆就足够了。其用法如下:
     imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_db_pipe1 commit=y feedback=10000 buffer=10240000

(4)使用COMMIT=Y选项
  COMMIT=Y表示每个数据缓冲满了之后提交一次,而不是导完一张表提交一次。这样会大大减少对系统回滚段等资源的消耗,对顺利完成导入是有益的。

(5)使用INDEXES=N选项
  前面谈到增加排序区时,说明Imp进程会先导入数据再创建索引。导入过程中建立用户定义的索引,特别是表上有多个索引或者数据表特别庞大时,需要耗费大量时间。某些情况下,需要以最快的时间导入数据,而索引允许后建,我们就可以使用INDEXES=N 只导入数据不创建索引,从而加快导入速度。
  我们可以用INDEXFILE选项生成创建索引的DLL脚本,再手工创建索引。我们也可以用如下的方法导入两次,第一次导入数据,第二次导入索引。其用法如下:
imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_db_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=y indexes=n

imp user/pwd fromuser=user1 touser=user2 file=/tmp/imp_index_pipe1 commit=y feedback=10000 buffer=10240000 ignore=y rows=n indexes=y

(6)增加LARGE_POOL_SIZE
  如果在init.ora中配置了MTS_SERVICE,MTS_DISPATCHERS等参数,tnsnames.ora中又没有(SERVER=DEDICATED)的配置,那么数据库就使用了共享服务器模式。在MTS模式下,Exp/Imp操作会用到LARGE_POOL,建议调整LARGE_POOL_SIZE到150M。
检查数据库是否在MTS模式下:
  SQL>select distinct server from v$session;
如果返回值出现none或shared,说明启用了MTS。


二、expdp与impdp

该命令使用时需要创建oracle目录

CREATE DIRECTORY dirname AS 'dirpath';
GRANT read, write ON DIRECTORY dirname TO username;  

2.1 expdp

2.1.1 导出表


Expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=tab.dmp TABLES=dept,emp logfile=exp.log;

2.1.2 导出方案

Expdp scott/tiger DIRECTORY=dump_dir DUMPFILE=schema.dmp SCHEMAS=system,scott logfile=/exp.log;

2.1.3 导出表空间

     Expdp system/manager DIRECTORY=dump_dir DUMPFILE=tablespace.dmp TABLESPACES=user01,user02 logfile=/exp.log;

2.1.4 导出数据库

     Expdp system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=Y logfile=/exp.log;

2.2 Impdp

2.2.1 导入表


导入至同一方案(scott)
impdp scott/tiger DIRECTORY=dump_dir DUMPFILE=tab.dmp TABLES=dept,emp logfile=/exp.log;

导入至其他方案(scott至system)
Impdp system/manage DIRECTORY=dump_dir DUMPFILE=tab.dmp
TABLES=scott.dept,scott.emp REMAP_SCHEMA=SCOTT:SYSTEM logfile=/exp.log;

2.2.2 导入方案

Impdp scott/tiger DIRECTORY=dump_dir DUMPFILE=schema.dmp SCHEMAS=scott logfile=/exp.log;

Impdp system/manager DIRECTORY=dump_dir DUMPFILE=schema.dmp
SCHEMAS=scott REMAP_SCHEMA=scott:system logfile=/exp.log;

2.2.3 导入表空间

Impdp system/manager DIRECTORY=dump_dir DUMPFILE=tablespace.dmp TABLESPACES=user01 logfile=/exp.log;

2.2.4 导入数据库

Impdp system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y logfile=/exp.log;

2.3 expdp参数说明


(1). ATTACH
     该选项用于在客户会话与已存在导出作用之间建立关联.语法如下
     ATTACH=[schema_name.]job_name
     Schema_name用于指定方案名,job_name用于指定导出作业名.注意,如果使用ATTACH选项,在命令行除了连接字符串和ATTACH选项外,不能指定任何其他选项,示例如下:
     Expdp scott/tiger ATTACH=scott.export_job

(2). CONTENT
     该选项用于指定要导出的内容.默认值为ALL
     CONTENT={ALL | DATA_ONLY | METADATA_ONLY}
     当设置CONTENT为ALL 时,将导出对象定义及其所有数据.为DATA_ONLY时,只导出对象数据,为METADATA_ONLY时,只导出对象定义。
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dump CONTENT=METADATA_ONLY

(3) DIRECTORY
指定转储文件和日志文件所在的目录,DIRECTORY=directory_object
     Directory_object用于指定目录对象名称.需要注意,目录对象是使用CREATE DIRECTORY语句建立的对象,而不是OS 目录。
     Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dump
先在对应的位置创建物理文件夹,如D:/backup
建立目录:
     create or replace directory backup as '/opt/oracle/utl_file'
     SQL>CREATE DIRECTORY backup as ‘d:/backup’;
     SQL>grant read,write on directory backup to SYSTEM;
查询创建了那些子目录:
     SELECT * FROM dba_directories;

(4). DUMPFILE
     用于指定转储文件的名称,默认名称为expdat.dmp
     DUMPFILE=[directory_object:]file_name [,….]
     Directory_object用于指定目录对象名,file_name用于指定转储文件名.需要注意,如果不指定directory_object,导出工具会自动使用DIRECTORY选项指定的目录对象:Expdp scott/tiger DIRECTORY=dump1 DUMPFILE=dump2:a.dmp

(5). ESTIMATE
指定估算被导出表所占用磁盘空间的方法.默认值是BLOCKS。
          EXTIMATE={BLOCKS | STATISTICS}
设置为BLOCKS时,oracle会按照目标对象所占用的数据块个数乘以数据块尺寸估算对象占用的空间,设置为STATISTICS时,根据最近统计值估算对象占用空间:  Expdp scott/tiger TABLES=emp ESTIMATE=STATISTICS DIRECTORY=dump DUMPFILE=a.dump

(6). EXTIMATE_ONLY
     指定是否只估算导出作业所占用的磁盘空间,默认值为N
          EXTIMATE_ONLY={Y | N}
     设置为Y时,导出作用只估算对象所占用的磁盘空间,而不会执行导出作业,为N时,不仅估算对象所占用的磁盘空间,还会执行导出操作.
     Expdp scott/tiger ESTIMATE_ONLY=y NOLOGFILE=y

(7). EXCLUDE
     该选项用于指定执行操作时释放要排除对象类型或相关对象
          EXCLUDE=object_type[:name_clause] [,….]
     Object_type用于指定要排除的对象类型,name_clause用于指定要排除的具体对象.EXCLUDE和INCLUDE不能同时使用。
     Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dup EXCLUDE=VIEW

(8). FILESIZE
     指定导出文件的最大尺寸,默认为0,(表示文件尺寸没有限制)

(9). FLASHBACK_SCN
     指定导出特定SCN时刻的表数据。FLASHBACK_SCN=scn_value
     Scn_value用于标识SCN值.FLASHBACK_SCN和FLASHBACK_TIME不能同时使用: Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp FLASHBACK_SCN=358523

(10). FLASHBACK_TIME
     指定导出特定时间点的表数据
     FLASHBACK_TIME=”TO_TIMESTAMP(time_value)”
     Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp FLASHBACK_TIME= “TO_TIMESTAMP(’25-08-2004 14:35:00’,’DD-MM-YYYY HH24:MI:SS’)”

(11). FULL
     指定数据库模式导出,默认为N。 FULL={Y | N} 。为Y时,标识执行数据库导出.

(12). HELP
     指定是否显示EXPDP命令行选项的帮助信息,默认为N。当设置为Y时,会显示导出选项的帮助信息. Expdp help=y

(13). INCLUDE
     指定导出时要包含的对象类型及相关对象。INCLUDE = object_type[:name_clause] [,… ]

(14). JOB_NAME
     指定要导出作用的名称,默认为SYS_XXX 。JOB_NAME=jobname_string

(15). LOGFILE
     指定导出日志文件文件的名称,默认名称为export.log
          LOGFILE=[directory_object:]file_name
     Directory_object用于指定目录对象名称,file_name用于指定导出日志文件名.如果不指定directory_object.导出作用会自动使用DIRECTORY的相应选项值.
     Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp logfile=a.log

(16). NETWORK_LINK
     指定数据库链接名,如果要将远程数据库对象导出到本地例程的转储文件中,必须设置该选项.

(17). NOLOGFILE
     该选项用于指定禁止生成导出日志文件,默认值为N.

(18). PARALLEL
指定执行导出操作的并行进程个数,默认值为1

(19). PARFILE
     指定导出参数文件的名称。PARFILE=[directory_path] file_name

(20). QUERY
     用于指定过滤导出数据的where条件
          QUERY=[schema.] [table_name:] query_clause
     Schema用于指定方案名,table_name用于指定表名,query_clause用于指定条件限制子句.QUERY选项不能与CONNECT=METADATA_ONLY,EXTIMATE_ONLY,TRANSPORT_TABLESPACES等选项同时使用.
     Expdp scott/tiger directory=dump dumpfiel=a.dmp Tables=emp query=’WHERE deptno=20’

(21). SCHEMAS
     该方案用于指定执行方案模式导出,默认为当前用户方案.

(22). STATUS
     指定显示导出作用进程的详细状态,默认值为0

(23). TABLES
     指定表模式导出
          TABLES=[schema_name.]table_name[:partition_name][,…]
     Schema_name用于指定方案名,table_name用于指定导出的表名,partition_name用于指定要导出的分区名.

(24). TABLESPACES
     指定要导出表空间列表

(25). TRANSPORT_FULL_CHECK
     该选项用于指定被搬移表空间和未搬移表空间关联关系的检查方式,默认为N. 当设置为Y时,导出作用会检查表空间直接的完整关联关系,如果表空间所在表空间或其索引所在的表空间只有一个表空间被搬移,将显示错误信息.当设置为N时,导出作用只检查单端依赖,如果搬移索引所在表空间,但未搬移表所在表空间,将显示出错信息,如果搬移表所在表空间,未搬移索引所在表空间,则不会显示错误信息.
(26). TRANSPORT_TABLESPACES
     指定执行表空间模式导出

(27). VERSION
     指定被导出对象的数据库版本,默认值为COMPATIBLE.
     VERSION={COMPATIBLE | LATEST | version_string}
     为COMPATIBLE时,会根据初始化参数COMPATIBLE生成对象元数据;为LATEST时,会根据数据库的实际版本生成对象元数据.version_string用于指定数据库版本字符串.

2.4 impdp参数说明


     IMPDP命令行选项与EXPDP有很多相同的,不同的有:
(1)REMAP_DATAFILE
     该选项用于将源数据文件名转变为目标数据文件名,在不同平台之间搬移表空间时可能需要该选项.
     REMAP_DATAFIEL=source_datafie:target_datafile

(2)REMAP_SCHEMA
     该选项用于将源方案的所有对象装载到目标方案中.
     REMAP_SCHEMA=source_schema:target_schema

(3)REMAP_TABLESPACE
     将源表空间的所有对象导入到目标表空间中
     REMAP_TABLESPACE=source_tablespace:target_tablespace

(4)REUSE_DATAFILES
     该选项指定建立表空间时是否覆盖已存在的数据文件.默认为N。
     REUSE_DATAFIELS={Y | N}

(5)SKIP_UNUSABLE_INDEXES
     指定导入是否跳过不可使用的索引,默认为N

(6)SQLFILE
     指定将导入要指定的索引DDL操作写入到SQL脚本中。
     SQLFILE=[directory_object:]file_name
     Impdp scott/tiger DIRECTORY=dump DUMPFILE=tab.dmp SQLFILE=a.sql

(7)STREAMS_CONFIGURATION
     指定是否导入流元数据(Stream Matadata),默认值为Y.

(8)TABLE_EXISTS_ACTION
     该选项用于指定当表已经存在时导入作业要执行的操作,默认为SKIP
     TABBLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | FRPLACE }
     当设置该选项为SKIP时,导入作业会跳过已存在表处理下一个对象;当设置为APPEND时,会追加数据,为TRUNCATE时,导入作业会截断表,然后为其追加新数据;当设置为REPLACE时,导入作业会删除已存在表,重建表病追加数据,注意,TRUNCATE选项不适用与簇表和NETWORK_LINK选项

(9)TRANSFORM
     该选项用于指定是否修改建立对象的DDL语句
          TRANSFORM=transform_name:value[:object_type]
     Transform_name用于指定转换名,其中SEGMENT_ATTRIBUTES用于标识段属性(物理属性,存储属性,表空间,日志等信息),STORAGE用于标识段存储属性,VALUE用于指定是否包含段属性或段存储属性,object_type用于指定对象类型.
     Impdp scott/tiger directory=dump dumpfile=tab.dmp Transform=segment_attributes:n:table

(10)TRANSPORT_DATAFILES
     该选项用于指定搬移空间时要被导入到目标数据库的数据文件。
          TRANSPORT_DATAFILE=datafile_name
     Datafile_name用于指定被复制到目标数据库的数据文件
Impdp system/manager DIRECTORY=dump DUMPFILE=tts.dmp TRANSPORT_DATAFILES=’/user01/data/tbs1.f’

2.5 expdp/impdp优化

     数据泵与exp/imp 来说性能有很大的提高, 其中影响最大的就是paralle。 可以这么来看:  expdp/impdp=exp/imp+direct moe + paralle. 所以, 使用数据泵,要想提高速度,就要设置并行参数。

先看2个参数:
Setting Parallelism
For export and import operations, the parallelism setting (specified with the PARALLEL parameter) should be less than or equal to the number of dump files in the dump file set. If there are not enough dump files, the performance will not be optimal because multiple threads of execution will be trying to access the same dump file.
The PARALLEL parameter is valid only in the Enterprise Edition of Oracle Database 10g.
Using Substitution Variables
Instead of, or in addition to, listing specific filenames, you can use the DUMPFILE parameter during export operations to specify multiple dump files, by using a substitution variable (%U) in the filename. This is called a dump file template. The new dump files are created as they are needed, beginning with 01 for %U, then using 02, 03, and so on. Enough dump files are created to allow all processes specified by the current setting of the PARALLEL parameter to be active. If one of the dump files becomes full because its size has reached the maximum size specified by the FILESIZE parameter, it is closed, and a new dump file (with a new generated name) is created to take its place.

From:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_overview.htm#sthref44


如果我们使用如下语句:
expdp full=y directory=dump dumpfile=orcl_%U.dmp parallel=4

     那么expdp将为parallel 创建4个文件: ORCL_01.DMP,RCL_02.DMP
,ORCL_03.DMP,RCL_04.DMP。 每个进程一个文件。 这样的话,每个文件的大小会因进程而不同。 可以某个文件很大,某个文件却很小。 要解决这个问题,就是设置filesize 参数。 来指定每个文件的最大值。 这样当一个文件达到最大值的之后,就会创建一个新的文件。

如:
expdp full=y directory=dump dumpfile=orcl_%U.dmp parallel=4 filesize=50M


     导出的dump文件和paralle有关系,那么导入也有关系。 paralle要小于dump文件数。 如果paralle 大于dump文件的个数,就会因为超过的那个进程获取不到文件,就不能对性能提高。

     一般parall 参数值等于CPU 的个数。而且要小于dump文件的个数。

查看CPU 个数:
SQL> show parameter cpu


注意事项:
(1)导入的时候可能会停在某个地方,比如在创建索引的时候,可能在一个地方停了十几分钟。  这个时候切记不要中断过程。  这个时候可能是需要导入的数据比较多。

     可以在不同时段观察下表空间大小的变化。 如果表空间一直在变化,说明还在导入,这个时候耐心等待就好。

查看表空间可以用如下SQL:
/* Formatted on 2010/12/23 13:14:13 (QP5 v5.115.810.9015) */
SELECT   a.tablespace_name,
         ROUND (a.total_size) "total_size(MB)",
         ROUND (a.total_size) - ROUND (b.free_size, 3) "used_size(MB)",
         ROUND (b.free_size, 3) "free_size(MB)",
         ROUND (b.free_size / total_size * 100, 2) || '%' free_rate
  FROM   (  SELECT   tablespace_name, SUM (bytes) / 1024 / 1024 total_size
              FROM   dba_data_files
          GROUP BY   tablespace_name) a,
         (  SELECT   tablespace_name, SUM (bytes) / 1024 / 1024 free_size
              FROM   dba_free_space
          GROUP BY   tablespace_name) b
WHERE   a.tablespace_name = b.tablespace_name(+);


(2)导出导入的过程,尽量避免用ssh连上服务器,在客户端的ssh里执行备份恢复命令。 因为这样,如果连接中断,备份也就中断了。 可以将备份脚本添加到crontab 里。 让备份在服务器上执行。 这样即使ssh中断,备份和恢复也不受影响。


三、exp/imp 与 expdp/impdp的比较
     exp/imp 默认会是传统路径, 这种模式下,是用SELECT 加数据查询出来, 然后写入buffer cache, 在将这些记录写入evaluate buffer. 最后传到Export客户端,在写入dump文件。
    Exp/imp的模式
    Conventional path Export
    Conventional path Export uses the SQL SELECT statement to extract data from tables. Data is read from disk into the buffer cache, and rows are transferred to the evaluating buffer. The data, after passing expression evaluation, is transferred to the Export client, which then writes the data into the export file.
    Direct path Export
         When using a Direct path Export, the data is read from disk directly into the export session's program global area (PGA): the rows are transferred directly to the Export session's private buffer. This also means that the SQL command-processing layer (evaluation buffer) can be bypassed, because the data is already in the format that Export expects. As a result, unnecessary data conversion is avoided. The data is transferred to the Export client, which then writes the data into the export file.

The default is DIRECT=N, which extracts the table data using the conventional path.

This parameter is only applicable to the original export client. Export DataPump (expdp) uses a Direct Path unload by default and switches to External Table mode if required

    直接路径模式下,数据直接从硬盘读取,然后写入PGA, 格式就是export 的格式,不需要转换, 数据再直接传到export 客户端,写入dump 文件。 这种模式没有经过evaluation buffer。 少了一个过程,导出速度提高也是很明显。
   expdp/impdp 默认就是使用直接路径的,所以expdp要比exp块。

   
    expdp/impdp调用Server端的API在执行操作,是数据库内部的job任务。可以远程使用,但是生成的dump 文件存在于服务器上的directory里。
   Expdp/impdp 的模式
   Direct Path mode
  After data file copying, direct path is the fastest method of moving data. In this method, the SQL layer of the database is bypassed and rows are moved to and from the dump file with only minimal interpretation. Data Pump automatically uses the direct path method for loading and unloading data when the structure of a table allows it.

expdp/impdp 默认就是使用直接路径的,所以expdp要比exp块。

  External Tables mode
   If data cannot be moved in direct path mode, or if there is a situation where parallel SQL can be used to speed up the data move even more, then the external tables mode is used. The external table mechanism creates an external table that maps the dump file data for the database table. The SQL engine is then used to move the data. If possible, the APPEND hint is used on import to speed the copying of the data into the database.
Note: When the Export NETWORK_LINK parameter is used to specify a network link for an export operation, a variant of the external tables method is used. In this case, data is selected from across the specified network link and inserted into the dump file using an external table.

Data File Copying mode    
     This mode is used when a transport tablespace job is started, i.e.: the TRANSPORT_TABLESPACES parameter is specified for an Export Data Pump job. This is the fastest method of moving data because the data is not interpreted nor altered during the job, and Export Data Pump is used to unload only structural information (metadata) into the dump file.
Network Link Import mode
     This mode is used when the NETWORK_LINK parameter is specified during an Import Data Pump job. This is the slowest of the four access methods because this method makes use of an INSERT SELECT statement to move the data over a database link, and reading over a network is generally slower than reading from a disk.

功能区别
1)把用户usera的对象导到用户userb,用法区别在于fromuser=usera touser=userb ,remap_schema='usera':'userb' 。例如
     imp system/passwd fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;
     impdp system/passwd directory=expdp dumpfile=expdp.dmp remap_schema='usera':'userb' logfile=/oracle/exp.log;


(2)更换表空间,用exp/imp的时候,要想更改表所在的表空间,需要手工去处理一下,如alter table xxx move tablespace_new之类的操作。用impdp只要用remap_tablespace='tabspace_old':'tablespace_new'


(3)当指定一些表的时候,使用exp/imp 时,tables的用法是 tables=('table1','table2','table3')。expdp/impdp用法是tables='table1','table2','table3'。

(4)是否要导出数据行
     exp (ROWS=Y 导出数据行,ROWS=N 不导出数据行)

     expdp content(ALL:对象+导出数据行,DATA_ONLY:只导出对象,METADATA_ONLY:只导出数据的记录)


以上内容整理自网络。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值