ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

oracle数据泵导出导入

2021-04-30 19:35:59  阅读:287  来源: 互联网

标签:1024 expdp testUser 导出 导入 exp oracle TABLE segment


 
    数据备份要先看看需要导出的对象大小,如果有些日志表跟业务无关占用空间很大,就可以不导出这类表从而增加数据导出的效率。

    数据泵确实很好用,但是网上看到的例子总是不是那么全,自己抽空把这些年用到的例子总结了一下,希望能帮到一些道友。


    注:如下例子中testUser是用户名testUserPwd是用户密码

一、查看数据库的大小
 
全库大小
select segment_name,segment_type, sum(bytes)/1024/1024/1024 GB from  dba_segments where segment_type in('TABLE','INDEX','TABLE PARTITION')
group by segment_name ,segment_type
order by GB desc

某个用户的大小
select segment_name,segment_type, sum(bytes)/1024/1024/1024 GB from  dba_segments where segment_type in('TABLE','INDEX','TABLE PARTITION')
and OWNER ='TESTUSER'
group by segment_name ,segment_type
order by GB desc


1、表占用空间:
select segment_name, sum(bytes)/1024/1024/1024 GB from user_segments where segment_type='TABLE' group by segment_name
order by GB desc
 
2、索引占用空间:
select segment_name ,sum(bytes)/1024/1024/1024 GB from user_segments where segment_type ='INDEX' group by segment_name
order by GB desc

3、分区表TABLE PARTITION占用空间:
select segment_name,sum(bytes)/1024/1024/1024 GB   from user_segments where segment_type='TABLE PARTITION' group by segment_name
order by GB desc

二、导出、导入脚本


1、创建路径
(sqlplus里运行)
select * from dba_directories;  --查看现有的路径

create directory exp as '/mnt/share/';        --数据库里创建路径
grant read on directory  exp    to testUser;  --给testUser这个用户赋予读路径的权限
grant write on directory  exp    to testUser; --给testUser这个用户赋予写路径的权限

(linux系统下oracle用户下运行)
2、导出脚本
    普通用法
    --导出testUser用户下的所有数据
    expdp testUser/testUserPwd directory=exp dumpfile=FILE.bak schemas=testUser;  

    特殊用法
    (1)导出时排除某表EXCLUDE用法
    
        --不导出EMP和DEPT表
        expdp testUser/testUserPwd directory=exp_dir dumpfile=datafile.bak EXCLUDE=TABLE:\"IN\(\'EMP\',\'DEPT\'\)\"

        --不导出REPORT开头的表    
        expdp testUser/testUserPwd directory=exp dumpfile=no_report.bak EXCLUDE=TABLE:\"LIKE \'REPORT%\'\"   
 
        --导出排除MV开头和TMP开头的表
        expdp testUser/testUserPwd dumpfile=exp logfile=/opt/out.log directory=expdir EXCLUDE=TABLE:\"LIKE \'MV%\'\", EXCLUDE=TABLE:\"LIKE \'TMP%\'\"

        --除了排除指定字母开头的表,还可以再排除特定的表
        expdp testUser/testUserPwd dumpfile=exp logfile=/opt/out.log directory=expdir EXCLUDE=TABLE:\"LIKE \'MV%\'\", EXCLUDE=TABLE:\"LIKE \'TMP%\'\" ,EXCLUDE=TABLE:\"IN \(\'T1\'\,\'T2\'\)\"
 
 
    (2)只导出特定的表tables用法
        expdp testUser/testUserPwd  dumpfile=exp:scott.bak tables = emp,dept
 
    (3)INCLUDE用法
        expdp testUser/testUserPwd  DIRECTORY=exp SCHEMAS=testUser DUMPFILE=yes_report.bak  INCLUDE=TABLE:"LIKE'REPORT%'";  
 
3、导入脚本
   普通用法
    --导入testUser用户下的所有数据
   impdp testUser/testUserPwd  dumpfile=exp:FILE.bak   
 
   特殊用法
   (1)只导入特殊的表
        impdp scott/tiger dumpfile=exp:scott.bak tables = emp,dept

   (2)导入时数据存在就truncate(删除)    
    impdp scott/tiger dumpfile=exp:scott.bak tables = emp table_exists_action=truncate;
    注:table_exists_action后面的参数还可以跟 append\replace\truncate\skip
    
三、 并行导出导入
 
(1)并行导出
    举 例:某用户对象占用了4G左右的空间,实际导出后的DUMP文件约为1G,我们尝试在导出该用户时指定并行度为4,设置单个文件不超过500M,则语法如下:
    expdp user/pwd directory=exp dumpfile=expdp_20210430_%U.dmp logfile=expdp_20210430.log filesize=500M parallel=4
 
 
(2)并行导入
    举例:某dmp文件中包含了40张表,我们尝试在导入该DMP文件时指定并行度为4,则语法如下:
    impdp user/pwd directory=exp dumpfile=expdp_20210430_%U.dmp logfile=expdp_20210430.log parallel=4
 
 

标签:1024,expdp,testUser,导出,导入,exp,oracle,TABLE,segment
来源: https://www.cnblogs.com/yclh/p/14723082.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有