Oracle Data Pump 导出和导入数据
Data pump export/import(hereinafter referred to as Export/Import for ease of reading)是一种将元数据和数据导出到系统文件集/从系统文件集导入数据的服务端工具;导出的文件可以移动到其它服务器上,但只能使用impdp导入;使用前要先建立目录(directory)和授权:
conn / as sysdba
CREATE DIRECTORY PUMP_DIR AS '/u01/backup';
创建后即可查询出目录信息,包括目录名称、所有者、目录位置:
SQL> column directory_path format a50
SQL>select * from dba_directories where directory_name='PUMP_DIR';
OWNER DIRECTORY_NAME DIRECTORY_PATH
------------------------------ ------------------------------ --------------------------------------------------
SYS PUMP_DIR /u01/backup
删除已有的目录
drop directory pump_dir;
向某些用户授权使用目录,可以授权read或write权限,或者两个权限同时授予:
grant read,write on directory pump_dir to frdc;
撤销权限
revoke read,write on directory pump_dir from frdc;
1导出数据
1.1基本说明
EXPDP USERID='sywu/sywu' job_name=export_tb parallel=3 tables=(tb01,tb02,tb03) dumpfile=pump_dir:dw_20150602.dmp logfile=pump_dir:exptb.log version='11.2.0.1.0' exclude=''
userid 表示数据库连接信息,可以是as sysdba权限,非sysdba权限用户可以省略;
job_name 表示导出任务名,未指定默认格式为: SYS_EXPORT_TABLE _*;
parallel 表示并行数,默认为1;
tables 表示导出的表名,可以指定所有者owner.tab,导出分区表的某个分区owner.tab:part01;
dumpfile 表示导出的dump文件名,格式目录名:dump文件名,注:某些版本可能不兼容报错(ORA-39145),可以把目录独立出来用directory参数指定(directory=pump_dir);
version 表示导入目的地数据库版本,在非同一版本数据库之间导出导入数据这个比较重要;
exclude 表示导入排除的对象,DATABASE_EXPORT_OBJECTS表中记录所有的(数据库级别)排除模式,SCHEMA_EXPORT_OBJECTS表中记录schema级别排除对象模式,TABLE_EXPORT_OBJECTS表中记录table级别排除对象模式;
1.2带条件导出数据
有时候只想导出特定的数据,比如id=10或id in(10,20,30),这种情况下可以用条件限定导出数据(注意字符转义)
expdp userid='ops$sywu/sywu' tables=tb01 query=tb01:\"where object_id in\(10,20,30\)\" dumpfile=query_tab.dump directory=pump_dir
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 17:09:24 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."SYS_EXPORT_TABLE_01": userid=ops$sywu/******** tables=tb01 query=tb01:"where object_id in(10,20,30)" dumpfile=query_tab.dump directory=pump_dir
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 88 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "OPS$SYWU"."TB01" 25.70 KB 192 rows
Master table "OPS$SYWU"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for OPS$SYWU.SYS_EXPORT_TABLE_01 is:
/u01/backup/query_tab.dump
Job "OPS$SYWU"."SYS_EXPORT_TABLE_01" successfully completed at 17:09:32
或者通过rownum限定行的方式导出数据(注意字符转义)
expdp userid='ops$sywu/sywu' tables=tb01 query=tb01:\"where rownum\<10\" dumpfile=query_tab.dump directory=pump_dir
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 17:14:28 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."SYS_EXPORT_TABLE_01": userid=ops$sywu/******** tables=tb01 query=tb01:"where rownum<10" dumpfile=query_tab.dump directory=pump_dir
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 88 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "OPS$SYWU"."TB01" 11.41 KB 9 rows
Master table "OPS$SYWU"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for OPS$SYWU.SYS_EXPORT_TABLE_01 is:
/u01/backup/query_tab.dump
Job "OPS$SYWU"."SYS_EXPORT_TABLE_01" successfully completed at 17:14:36
有些情况下,为了满足测试要求,我们可能需要整库导出或整个schema下的数据导出,但又不需要所有数据,so 同样可以使用限定行数的方式限定所有表数据行导出数据
expdp userid='ops$sywu/sywu' SCHEMAS='ops$sywu' query=\"where rownum\<10\" dumpfile=schema_sywu.dump directory=pump_dir
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 17:18:34 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."SYS_EXPORT_SCHEMA_01": userid=ops$sywu/******** SCHEMAS=ops$sywu query="where rownum<10" dumpfile=schema_sywu.dump directory=pump_dir
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 104 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "OPS$SYWU"."TB01" 11.41 KB 9 rows
. . exported "OPS$SYWU"."TB02" 6.015 KB 9 rows
. . exported "OPS$SYWU"."T_EXCE" 5.820 KB 2 rows
Master table "OPS$SYWU"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for OPS$SYWU.SYS_EXPORT_SCHEMA_01 is:
/u01/backup/schema_sywu.dump
Job "OPS$SYWU"."SYS_EXPORT_SCHEMA_01" successfully completed at 17:18:55
有些情况下,导出的数据需要通过网络或通过媒介传输到其它目的地,考虑媒介的大小和网络情况,每次只能限定传输,为了达到这个目的可以将数据导出到多个文件,然后再分批或独立发送;比如评估的数据大小是80M,我想把文件导出为4个文件,每个文件的大小为20M,so 我像这样导出数据:
expdp userid='ops$sywu/sywu' job_name=exporttb_bysize SCHEMAS='ops$sywu' filesize=20971520 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 18:03:03 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."EXPORTTB_BYSIZE": userid=ops$sywu/******** job_name=exporttb_bysize SCHEMAS=ops$sywu filesize=20971520 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 104 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "OPS$SYWU"."TB01" 74.64 MB 844416 rows
. . exported "OPS$SYWU"."TB02" 452.3 KB 13448 rows
. . exported "OPS$SYWU"."T_EXCE" 5.820 KB 2 rows
Master table "OPS$SYWU"."EXPORTTB_BYSIZE" successfully loaded/unloaded
******************************************************************************
Dump file set for OPS$SYWU.EXPORTTB_BYSIZE is:
/u01/backup/size_each_sywu.dump
/u01/backup/file02.dmp
/u01/backup/file03.dmp
/u01/backup/file04.dmp
Job "OPS$SYWU"."EXPORTTB_BYSIZE" successfully completed at 18:03:24
filesize 表示每个文件的大小,单位为:bytes
dumpfile 表示导出的4个dump文件名,如果实际导出数据大小大于指定的文件数据(dumpfile)乘以每个文件大小(filesize)之合,则导出停止并报错
ORA-39095: Dump file space has been exhausted: Unable to allocate 4096 bytes
Job "OPS$SYWU"."SYS_EXPORT_SCHEMA_07" stopped due to fatal error at 17:57:31
有个地方要注意:在导出数据时,数据库会在导数用户下根据job_name名称创建一张表,比如job_name=exporttb_bysize,在导数过程中数据库创建一张名EXPORTTB_BYSIZE的表,该表记录了导数的信息,导数成功完成后自动删除,如果导数未成功,比如空间不足或实际大小大于指定大小,则job停止,该表不会自动删除。
为了说明问题,我将filesize改为每个文件10m模拟错误发生,最后观察状态,然后解决错误;
expdp userid='ops$sywu/sywu' job_name=exporttb_bysize SCHEMAS='ops$sywu' filesize=10485760 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 18:21:07 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."EXPORTTB_BYSIZE": userid=ops$sywu/******** job_name=exporttb_bysize SCHEMAS=ops$sywu filesize=10485760 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 104 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
ORA-39095: Dump file space has been exhausted: Unable to allocate 4096 bytes
Job "OPS$SYWU"."EXPORTTB_BYSIZE" stopped due to fatal error at 18:21:26
指定文件大小乘以文件个数小于实际数据量大小,导出报错停止,仅仅是停止;
ls -lh /u01/backup
-rw-r--r--. 1 oracle asmadmin 1.8K Jun 2 17:18 export.log
-rw-r--r--. 1 oracle asmadmin 1.5K Jun 2 18:21 exportt01.log
-rw-r-----. 1 oracle asmadmin 10M Jun 2 18:21 file02.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 18:21 file03.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 18:21 file04.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 18:21 size_each_sywu.dump
此时查看数据库,发现一张于job_name名称相同的表EXPORTTB_BYSIZE,表中记录了导数时的信息;查询job的状态为:NOT RUNING;
select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
EXPORTTB_BYSIZE TABLE
TB01 TABLE
TB02 TABLE
T_EXCE TABLE
select job_name,state from dba_datapump_jobs;
JOB_NAME STATE
------------------------------ ------------------------------
EXPORTTB_BYSIZE NOT RUNNING
继续完成导数可以通过添加dump文件或使用系统默认的文件
expdp userid='ops$sywu/sywu' attach=EXPORTTB_BYSIZE
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 22:28:37 2015
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, OLAP, Data Mining and Real Application Testing options
Job: EXPORTTB_BYSIZE
Owner: OPS$SYWU
Operation: EXPORT
Creator Privs: FALSE
GUID: 178798A215814641E053FE1813ACD41C
Start Time: Tuesday, 02 June, 2015 22:28:38
Mode: SCHEMA
Instance: sydb
Max Parallelism: 1
EXPORT Job Parameters:
Parameter Name Parameter Value:
CLIENT_COMMAND userid=ops$sywu/******** job_name=exporttb_bysize SCHEMAS=ops$sywu filesize=10485760 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
State: IDLING
Bytes Processed: 0
Current Parallelism: 1
Job Error Count: 0
Dump File: /u01/backup/size_each_sywu.dump
size: 10,485,760
bytes written: 10,485,760
Dump File: /u01/backup/file02.dmp
size: 10,485,760
bytes written: 10,485,760
Dump File: /u01/backup/file03.dmp
size: 10,485,760
bytes written: 10,485,760
Dump File: /u01/backup/file04.dmp
size: 10,485,760
bytes written: 10,485,760
Worker 1 Status:
Process Name: DW00
State: UNDEFINED
Object Schema: OPS$SYWU
Object Name: TB01
Object Type: SCHEMA_EXPORT/TABLE/TABLE_DATA
Completed Objects: 1
Total Objects: 3
Completed Bytes: 41,844,736
Percent Done: 45
Worker Parallelism: 1
Export> add_file=file05.dmp
Export> start_job
开始任务后,导数继续执行
select job_name,state from dba_datapump_jobs;
JOB_NAME STATE
------------------------------ ------------------------------
EXPORTTB_BYSIZE EXECUTING
select job_name,state from dba_datapump_jobs;
JOB_NAME STATE
------------------------------ ------------------------------
EXPORTTB_BYSIZE COMPLETING
在添加dump file(add_file)时,添加的文件最终大小取决于添加了多少dump file,在上例中仅添加了一个file05.dmp,so 剩余的数据量将全部归纳到该文件中;如果未添加文件oracle会自己分配和创建一个dump文件;
[oracle@sywu backup]$ ls -ltrh
-rw-r-----. 1 oracle asmadmin 10M Jun 2 22:30 file02.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 22:30 file03.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 22:30 file04.dmp
-rw-r-----. 1 oracle asmadmin 10M Jun 2 22:30 size_each_sywu.dump
-rw-r-----. 1 oracle asmadmin 36M Jun 2 22:30 file05.dmp
-rw-r--r--. 1 oracle asmadmin 2.4K Jun 2 22:30 exportt01.log
[oracle@sywu backup]$ cat exportt01.log
Export: Release 11.2.0.3.0 - Production on Tue Jun 2 18:42:17 2015
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, OLAP, Data Mining and Real Application Testing options
Starting "OPS$SYWU"."EXPORTTB_BYSIZE": userid=ops$sywu/******** job_name=exporttb_bysize SCHEMAS=ops$sywu filesize=10485760 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 104 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
ORA-39095: Dump file space has been exhausted: Unable to allocate 4096 bytes
Job "OPS$SYWU"."EXPORTTB_BYSIZE" stopped due to fatal error at 18:42:36
Job EXPORTTB_BYSIZE has been reopened at Tuesday, 02 June, 2015 22:28
Restarting "OPS$SYWU"."EXPORTTB_BYSIZE": userid=ops$sywu/******** job_name=exporttb_bysize SCHEMAS=ops$sywu filesize=10485760 dumpfile=size_each_sywu.dump,file02.dmp,file03.dmp,file04.dmp directory=pump_dir logfile=exportt01.log
. . exported "OPS$SYWU"."TB01" 74.64 MB 844416 rows
. . exported "OPS$SYWU"."TB02" 452.3 KB 13448 rows
. . exported "OPS$SYWU"."T_EXCE" 5.820 KB 2 rows
Master table "OPS$SYWU"."EXPORTTB_BYSIZE" successfully loaded/unloaded
******************************************************************************
Dump file set for OPS$SYWU.EXPORTTB_BYSIZE is:
/u01/backup/size_each_sywu.dump
/u01/backup/file02.dmp
/u01/backup/file03.dmp
/u01/backup/file04.dmp
/u01/backup/file05.dmp
Job "OPS$SYWU"."EXPORTTB_BYSIZE" completed with 1 error(s) at 22:30:38
1.3导出某个schema下的数据
对于导出schema下的数据,建议使用sysdba用户导出,因为随着系统的复杂和环境不一,某些时候依赖的包、对象、存储过程可能是属于另一个用户的,导出时被导出schema未必具有完全的权限,同时还要考虑导入的目的地环境;当然万事没有绝对,完全取决于应用;
expdp userid='sys/oracle as sysdba' job_name=export_schema SCHEMAS='ops$sywu' directory=pump_dir dumpfile=schema_sywu.dmp logfile=schema_sywu.log
1.4整库导出
整库导出必须使用sysdba权限;
expdp userid='sys/oracle as sysdba' job_name=export_schema FULL=Y directory=pump_dir dumpfile=full_dbexport.dmp logfile=full_dbexport.log
1.5查询导数job状态
column username format a10
column opname format a20
column units format a10
select
round(sofar/totalwork*100,2) percent_completed,
t.sid,t.SERIAL#,t.USERNAME,t.OPNAME,t.TOTALWORK,t.UNITS,t.START_TIME,t.MESSAGE
from
v$session_longops t
where
sofar <> totalwork
order by target,sid;
PERCENT_COMPLETED SID SERIAL# USERNAME OPNAME TOTALWORK UNITS START_TIME MESSAGE
----------------- ---------- ---------- ---------- -------------------- ---------- ---------- -------------- ---------------------------------------------------------------------------
70.88 128 17213 FRDC Table Scan 2533381 Blocks 02-6月 -15 Table Scan: FRDC.H_BASE_MAIN05_T: 1795601 out of 2533381 Blocks done
12.58 128 17213 FRDC Table Scan 2533381 Blocks 02-6月 -15 Table Scan: FRDC.H_BASE_MAIN05_T: 318705 out of 2533381 Blocks done
70.74 128 17213 FRDC Table Scan 2533381 Blocks 02-6月 -15 Table Scan: FRDC.H_BASE_MAIN05_T: 1792046 out of 2533381 Blocks done
29.06 4 57701 FRDC Index Fast Full Scan 2127 Blocks 13-5月 -15 Index Fast Full Scan: FRDC.O_BASE_DW: 618 out of 2127 Blocks done
0 5 280 SYS Rowid Range Scan 4294967296 Blocks 02-6月 -15 Rowid Range Scan: FRDC.O_BASE_DW_T: 22055 out of 0 Blocks done
0 427 54951 FRDC EXPORT_TB 7900 MB 02-6月 -15 EXPORT_TB: EXPORT : 0 out of 7900 MB done
2数据导入
2.1基本语法
$ impdp userid='uname/pwd' directory=pump_dir dumpfile=file01.dmp job_name='' log_file='' remap_schema='scott:sywu' remap_table='tb01:tb02' remap_tablespace='tbs01:ts01' tables='' schemas='' table_exists_action='' tablespaces='' exclude='' sqlfile=''
上面有的参数这里就不重复了,因为dump方式导出数据使用了xml格式,所以导入时很容易实现对象重新定义操作,这里主要说几个经常使用的参数:
remap_schema 表示重新定义schema,将旧的schema定义为新的schema,格式old:new,old:new....;
remap_table 表示重新定义表名,格式oldtbname:newtbname,....;
remap_tablespace 表示重新定义表空间名,格式old:new....;
tables 表示要导入的表名,如果未指定则导入dumpfile里的所有表;
schemas 表示要导入的schema对象,如果未指定并且操作用户有权限则导入dumpfile里的所有schema;
table_exists_action 表示当导入表时如果表已经存在时的操作,参数值可以为:append(追加)、replace(替换数据库中存在的)、truncate(删除已经存在的数据,导入dumpfile里面的数据)、skip(不做任何操作);
tablespaces 表示导入的表空间名;
exclude 表示导入排除的对象,DATABASE_EXPORT_OBJECTS表中记录所有的(数据库级别)排除模式,SCHEMA_EXPORT_OBJECTS表中记录schema级别排除对象模式,TABLE_EXPORT_OBJECTS表中记录table级别排除对象模式;
sqlfile 表示不导入数据仅生成导数ddl语句记录在该文件中;
2.2导入数据
导入数据时要确认导入的用户是否存在,是否有权限访问表空间、是否具有读写directory的权限;
$ impdp userid='ops$sywu/sywu' schemas='ops$sywu' directory=pump_dir job_name=import_opssywu dumpfile=export_opssywu.dmp
Import: Release 11.2.0.3.0 - Production on Sat Jun 6 13:39:43 2015
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, OLAP, Data Mining and Real Application Testing options
Master table "OPS$SYWU"."IMPORT_OPSSYWU" successfully loaded/unloaded
Starting "OPS$SYWU"."IMPORT_OPSSYWU": userid=ops$sywu/******** schemas=ops$sywu directory=pump_dir job_name=import_opssywu dumpfile=export_opssywu.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "OPS$SYWU"."TB01" 74.64 MB 844416 rows
. . imported "OPS$SYWU"."TB02" 452.3 KB 13448 rows
. . imported "OPS$SYWU"."T_EXCE" 5.820 KB 2 rows
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "OPS$SYWU"."IMPORT_OPSSYWU" successfully completed at 13:39:55
导入数据时重定义schema和tablespaces,重定义schema建议使用sysdba权限导入数据:
create tablespace tbs02 datafile '/u01/oradata/sydb/tbs02.dbf' size 10m autoextend on uniform size 4m;
create user sywu identified by sywu default tablespace tbs02 quota unlimited on tbs02;
grant create session,resource to sywu;
grant read,write on directory pump_dir to sywu;
exit;
$ impdp userid="'sys/oracle as sysdba'" remap_schema='ops$sywu:sywu' remap_tablespace=tbs01:tbs02 directory=pump_dir job_name=import_opssywu dumpfile=export_opssywu.dmp
Import: Release 11.2.0.3.0 - Production on Sat Jun 6 13:51:48 2015
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, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."IMPORT_OPSSYWU" successfully loaded/unloaded
Starting "SYS"."IMPORT_OPSSYWU": userid="sys/******** AS SYSDBA" remap_schema=ops$sywu:sywu remap_tablespace=tbs01:tbs02 directory=pump_dir job_name=import_opssywu dumpfile=export_opssywu.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SYWU"."TB01" 74.64 MB 844416 rows
. . imported "SYWU"."TB02" 452.3 KB 13448 rows
. . imported "SYWU"."T_EXCE" 5.820 KB 2 rows
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYS"."IMPORT_OPSSYWU" successfully completed at 13:52:08
其它还有限定行数的操作,操作类似上面导出操作;
The end(2015-06-06)
Oracle Data Pump 导出和导入数据的更多相关文章
- OGG初始化之使用Oracle Data Pump加载数据
此方法使用Oracle Data Pump实用程序来建立目标数据.将副本应用于目标后,您将记录副本停止的SCN.包含在副本中的交易将被跳过以避免完整性违规冲突.从流程起点,Oracle GoldenG ...
- 利用PL/SQL从Oracle数据库导出和导入数据
转自:https://www.jb51.net/article/109768.htm 本文实例为大家分享了使用PL/SQL从Oracle数据库导出和导入数据的方法,供大家参考,具体内容如下 1.导出数 ...
- 转 使用隐含Trace参数诊断Oracle Data Pump故障
http://blog.itpub.net/17203031/viewspace-772718/ Data Pump数据泵是Oracle从10g开始推出的,用于取代传统exp/imp工具的数据备份还原 ...
- [Oracle] Data Pump 详细使用教程(4)- network_link
[Oracle] Data Pump 详细使用教程(1)- 总览 [Oracle] Data Pump 详细使用教程(2)- 总览 [Oracle] Data Pump 详细使用教程(3)- 总览 [ ...
- [Oracle] Data Pump 详细使用教程(5)- 命令交互模式
[Oracle] Data Pump 详细使用教程(1)- 总览 [Oracle] Data Pump 详细使用教程(2)- 总览 [Oracle] Data Pump 详细使用教程(3)- 总览 [ ...
- oracle数据库管理员简介、导入数据与导出数据
数据库管理员: sys和system的权限区别:sys:所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle的运行时至关重要的,由数据库 自己维护,任何用户都不能 ...
- [Oracle] Data Pump 详细使用教程(1)- 总览
从10g开始,Oracle提供更高效的Data Pump(即expdp/impdp)来进行数据的导入和导出,老的exp/imp还可以用,但已经不建议使用.注意:expdp/impdp和exp/imp之 ...
- Oracle数据库的导出和导入
本次数据库的导入导出操作是导出公司环境的Oracle数据库,再导入本地数据库,采用impdp和expdp命令进行导入导出操作. 一.导出52数据库 1.用system用户登录到数据库,查看是否有创建d ...
- Oracle数据库备份---导出与导入
利用windows的cmd命令备份导出数据(也可以连接上sqlplus进行操作)--导出--将数据库orcl完全导出 exp system/oracle@orcl file=c:\oracle_bak ...
随机推荐
- EasyUI treegrid 删除一条或多条记录
function del_dg() { $.messager.defaults = { ok: "是", cancel: "否" }; var node = $ ...
- 安装git之后,桌面图标出现很多的蓝色问号
今天在搞git之后,开机发现多了好多的问号: 这是因为我们在桌面创建了版本库了. 这个时候我们在系统中吧隐藏的文件夹显示出来.这个时候会看到桌面上有一个隐藏的git文件夹.把这个文件夹删除掉之后,刷新 ...
- 阶段性总结(PHP-Array函数)
PHP 5 Array 函数 PHP Array 简介 PHP Array 函数允许您访问并操作数组. 支持简单的数组和多维数组. 详情见下表: 函数 描述 array() 创建数组. array_c ...
- MVC、MVP、MVVM架构模式
MVC模式 如何设计一个程序的结构,这是一门专门的学问,叫做"架构模式"(architectural pattern),属于编程的方法论. MVC模式就是架构模式的一种,不仅适用于 ...
- window.location和window.open的区别
window.location = "http://www.baidu.com" 跳转后有后退功能 window.location.replace("http://www ...
- 回归问题中代价函数选择的概率解释(Probabilistic interpretation)
在我们遇到回归问题时,例如前面提到的线性回归,我们总是选择最小而成作为代价函数,形式如下: 这个时候,我们可能就会有疑问了,我们为什么要这样来选择代价函数呢?一种解释是使我们的预测值和我们训练样本的真 ...
- C#Question:“XXX”的重载均与“System.Threading.WaitCallback”不匹配。
public static class ThreadPool // 提供一个线程池,该线程池可用于执行任务.发送工作项.处理异步 I/O.代表其他线程等待以及处理计时器. { [SecuritySaf ...
- 前端使用CryptoJs类库进行sha-256、MD5加密
Google的加密库 CryptoJs(点此下载) 包含了很多常用的加解密方式,包括AES.DES.SHA-1.SHA-2.SHA256.MD5等. DES对称加密在之前的文章中也有介绍过,大传送门. ...
- HTTP 状态信息
一.1xx 消息 该类型的状态码代表请求已被接受,需要继续处理. 100 Continue 客户端应当继续发送请求,这个临时响应是用来通知客户端的部分请求已经被服务器接收,且仍未被拒绝.客户端应当继续 ...
- 开发团队(Team)的主要职责和特征
角色介绍 开发团队是Scrum团队的三个角色之一. 开发团队包括架构师.开发工程师.测试人员.数据库管理员和UI设计师等,这几类人的跨职能组合.具备的技能足以实现产品开发. Team的主要职责 1.S ...