expdp和impdp数据导出导入

Oracle schema 级别的数据迁移

 

    最近一段时间,跟着两个项目组,做ORACLEDB相关的支持工作,因为项目属于开发阶段,总有一些数据库的复制工作,比较了几种方法,感觉用EXPDP/IMPDP还不错,能顺利实现开发人员的需求。

    需求:实现user/schema级别的数据迁移。
    版本:Oracle Enterprise 11g R2

   总体来说分为以下几步:  

 1.查看原库和目标库的DUMP目录。

[sql] view plain copy

1.  SQL> select * from dba_directories;  

2.  SYS        SUBDIR                /opt/oracle/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry/2002/Sep  

3.  SYS        SS_OE_XMLDIR          /opt/oracle/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry/  

4.  SYS        LOG_FILE_DIR          /opt/oracle/app/oracle/product/11.2.0/dbhome_1/demo/schema/log/  

5.  SYS        DATA_FILE_DIR         /opt/oracle/app/oracle/product/11.2.0/dbhome_1/demo/schema/sales_history/  

6.  SYS        XMLDIR                /ade/b/2125410156/oracle/rdbms/xml  

7.  SYS        MEDIA_DIR             /opt/oracle/app/oracle/product/11.2.0/dbhome_1/demo/schema/product_media/  

8.  SYS        DATA_PUMP_DIR         /opt/oracle/app/oracle/admin/oracle/dpdump/  

9.  SYS        ORACLE_OCM_CONFIG_DIR /opt/oracle/app/oracle/product/11.2.0/dbhome_1/ccr/state  

10. rows selected.  

上面 DATA_PUMP_DIR就是直接可以用的DUMP目录,导出文件和导入文件就放在上面的路径下,如果没有,则需要手动创建并赋给读/写权限。

[sql] view plain copy

1.  SQL>CONN sys /as sysdba  

2.  SQL>CREATE DIRECTORY DATA_PUMP_DIR AS '/opt/oracle/app/oracle/admin/oracle/dpdump/';  

3.  SQL>GRANT READ,WRITE ON DIRECTORY TO TEST;  

2.对比原库和目标库的username和tablespace

如果目标库中没有需要导入的username和tablespace,则需要在目标库中创建username和tablespace。

[sql] view plain copy

1.  SQL> select username,default_tablespace from dba_users; --查看原库中的用户和对应的默认表空间  

2.  SQL> create tablespace test_tbs datafile '/opt/oracle/oradata/test/TEST_TBS01.DBF' size 1024m autoextend on;  

3.  SQL> create user test identified by test default tablespace test_tbs;  

 3.导出脚本 

[sql] view plain copy

1.  --导出指定schema  

2.  expdp system/oracle@orcl DIRECTORY=DATA_PUMP_DIR DUMPFILE=FALABELLA_20111014.DMP SCHEMAS=FALABELLA_CL_CATA,FALABELLA_CL_CATB,FALABELLA_CL_PUB logfile=falabella_expdp_20111014.log status=10 parallel=4 CONTENT=ALL COMPRESSION=ALL  

3.  --导出整个数据库  

4.  expdp system/oracle@orcl DIRECTORY=DATA_PUMP_DIR DUMPFILE=AAXIS_20111125.EXPDP FULL=Y logfile=AAXIS_expdp_20111125.log status=10 parallel=1 CONTENT=ALL flashback_scn=18341888 COMPRESSION=ALL  


 

4. 导入脚本

[sql] view plain copy

1.  --需要从一个schema导入到另一个schema  

2.    

3.  impdp system/oracle@TEST DIRECTORY=dump_dir DUMPFILE=ATG_12OCT11.dmp LOGFILE=impdp_mf_20111013_2.log  SCHEMAS=QA2_ATGPUB_MF,QA2_ATGCATALOGA_MF REMAP_SCHEMA=QA2_ATGPUB_MF:QA2_ATGPUB_MF,QA2_ATGCATALOGA_MF:QA2_ATGCATALOGB_MF CONTENT=ALL PARALLEL=4 STATUS=10 TABLE_EXISTS_ACTION=REPLACE  

4.    

5.  --不需要更名schema  

6.    

7.  impdp system/oracle@TEST DIRECTORY=dump_dir DUMPFILE=ATG_12OCT11.dmp LOGFILE=impdp_mf_20111014_1.log  SCHEMAS=QA2_ATGPUB_MF CONTENT=ALL PARALLEL=4 STATUS=10 TABLE_EXISTS_ACTION=REPLACE  


 

附:查看各个SCHEMA占用空间的大小:

[sql] view plain copy

1.  SQL> select owner,round(sum(bytes/1024/1024),2)||' MB' as schema_size from dba_segments group by owner order by SCHEMA_SIZE desc;  

2.    

3.  OWNER                          SCHEMA_SIZE  

4.  ------------------------------ ------------------------------------------  

5.  APEX_030200                    85.06MB  

6.  CTXSYS                         61.75MB  

7.  DBSNMP                         1.63MB  

8.  EXFSYS                         3.63MB  

9.  FALABELLA_AR_CATA              96.5MB  

10. FALABELLA_AR_CATB              90.13MB  

11. FALABELLA_AR_CORE              10889.63MB  

12. FALABELLA_AR_PUB               357.38MB  

13. FALABELLA_CL_CATA              116.06MB  

14. FALABELLA_CL_CATB              109.63MB  

15.   

16. 37 rows selected.  

17.   

18. --查询己经导入的对象个数  

19. SQL> select owner,count(*) from dba_objects where owner like 'FALABELLA_AR%' group by owner order by owner;  

20.   

21. OWNER                            COUNT(*)  

22. ------------------------------ ----------  

23. FALABELLA_AR2_CATA                    463  

24. FALABELLA_AR2_CATB                    462  

25. FALABELLA_AR2_CORE                   1300  

26. FALABELLA_AR2_PUB                    2308  

27. FALABELLA_AR3_CATA                    175  

28. FALABELLA_AR3_CATB                    174  

29. FALABELLA_AR3_CORE                    884  

30. FALABELLA_AR3_PUB                     907  

31. FALABELLA_AR_CATA                     463  

32. FALABELLA_AR_CATB                     462  

33. FALABELLA_AR_CORE                    1300  

34. FALABELLA_AR_PUB                     2308  

35.   

36. 12 rows selected.  


 


 ORA-39095: Dump file space has been exhausted: Unable to allocate 8192bytes
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" stopped due to fatalerror at 13:34:40

expdp
时parallel不当也会引起ORA-39095
2008-09-24 15:01

在expdp做导出的时候会有碰到ora-39095的错误,引起这个错误的原因有两种。一一说来
先看官方的解释:
ORA-39095: Dump file space has been exhausted: Unable to allocate string bytes
Cause: The Export job ran out of dump file space before the job was completed.
Action: Reattach to the job and add additional dump files to the job restartingthe job.
从字面意思就解释了第一种原因,那就是:空间不够了。解决方法也简单,多来点空间。
还有第二中原因:当使用了PARALLEL但是dumpfile却只有一个或小于parallel数,下面是官方的说明:

Oracle? Database Utilities
10g Release 2 (10.2)
2 Data Pump Export
PARALLEL=integer
The value you specify for integer should be less than, or equal to, the numberof files in the dump file set (or you should specify substitution variables inthe dump file specifications).
Because each active worker process or I/O server process writes exclusively toone file at a time, an insufficient number of files can have adverse effects.Some of the worker processes will be idle while waiting for files, therebydegrading the overall performance of the job.(第一个原因是影响性能)
More importantly, if any member of a cooperating group of parallel I/O serverprocesses cannot obtain a file for output, then the export operation will bestopped with an ORA-39095 error. (ora-39095的成因)Bothsituations can be corrected by attaching to the job using the Data Pump Exportutility, adding more files using the ADD_FILE command while in interactivemode, and in the case of a stopped job, restarting the job.
说白话点就是:parallel io server processes写文件不能同时写一个,如果只有一个dumpfile(或少于parallel)就会影响性能。不但如此,当一个io server process在等待从而不能写dumpfile的时候就会报ora-39095
要解决:expdp ATTACH 连上作业然后减少parallel或者增加dumpfile
从起源解决的话就是:指定parallel的时候就要指定至少同样多的dumpfile或者使用类似下面的命令(注意红字):
expdp hr/hr DIRECTORY=dpump_dir1 LOGFILE=parallel_export.log JOB_NAME=par4_jobDUMPFILE=par_exp%u.dmp PARALLEL=4

 

实际操作:

 

--创建用户并将另外一个用户的数据(对象和数据)复制到新建里(同一个数据库里)

 

--1.创建新用户并赋予对应的权限

createuser cash_gateway_dev identifiedby123456

  defaulttablespace omms_data

  temporarytablespace TEMP

  profiledefault;

-- grant/revoke role privileges

grantconnectto cash_gateway_dev;

grantresourceto cash_gateway_dev;

-- grant/revoke system privileges

grantcreateviewto cash_gateway_dev;

grantselectanydictionaryto cash_gateway_dev;

grantunlimitedtablespaceto cash_gateway_dev;

grantcreate job to cash_gateway_dev;

grantmanage scheduler to cash_gateway_dev;

 

--2.查看数据库中可利用的目录

select * from dba_directories;

 

--3.我们选取目录DUMP_BAK

 

--4. 第三方软件 WinSCP ,使用服务器操作系统账户密码登录,使用WinSCP 软件里面集成的PuTTY SSH终端登录命令行

 

--5.执行从iboxpay_worthtech_dev 用户下导出整个schema的对象和数据,文件格式是DMP

expdp jiangzl/jiangzl DIRECTORY=DUMP_BAK DUMPFILE=iboxpay_worthtech_dev_20180112.DMPSCHEMAS=iboxpay_worthtech_dev logfile=falabella_expdp_20180112.log status=10parallel=4CONTENT=ALL COMPRESSION=ALL

 

--6.执行导入命令,将iboxpay_worthtech_dev导入到新用户cash_gateway_dev

impdp jiangzl/jiangzl DIRECTORY=DUMP_BAK DUMPFILE=iboxpay_worthtech_dev_20180112.DMP LOGFILE=impdp_mf_20180112_1.log  SCHEMAS=iboxpay_worthtech_devREMAP_SCHEMA=iboxpay_worthtech_dev:cash_gateway_dev CONTENT=ALLPARALLEL=4 STATUS=10 TABLE_EXISTS_ACTION=REPLACE

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值