延迟段依然会对expdp造成影响
deferred_segment_creation
和exp不同,expdp需要建立目录并授权,因为expdp导出文件只能存储在服务器
可以通关dba_directories视图来查看目录
[oracle@orcl ~]$ mkdir /u01/pump
SQL> create directory mypump as ‘/u01/pump’;
SQL> grant read, write on directory mypump to hr;
exp的帮助文档
[oracle@orcl ~]$ impdp -help
expdp hr/hr@127.0.0.1:1521/orcl.example.com directory=mypump dumpfile=hr.dmp
expdp system/oracle_4U directory=mypump dumpfile=hr.dmp logfile=hr.log schemas=hr
如果不加logfile参数,则会自动生成export.log文件,会被再次生成的覆盖而不是追加
dumpfile不可生成已存在的文件名
dba_datapump_jobs视图可以查看数据泵作业运行情况
用sys用户导出全库:
expdp \”/ as sysdba\” directory=mypump dumpfile=full.dmp full=y
用普通用户导出全库:
grant datapump_exp_full_database to hr;
expdp hr/hr directory=mypump dumpfile=full.dmp full=y
相关权限:
datapump_exp_full_database
datapump_imp_full_database
导出表:
expdp hr/hr directory=mypump dumpfile=hr.dmp tables=employees,jobs
expdp system/oracle_4U directory=mypump dumpfile=hr.dmp tables=hr.e%
导出结构:
expdp hr/hr directory=mypump dumpfile=hr.dmp content=metadata_only tables=employees,jobs
指定版本导出
expdp hr/hr directory=mypump dumpfile=hr.dmp version=10.2
按表空间导出
expdp hr/hr directory=mypump dumpfile=hr.dmp tablespaces=users
1 2 3 4 5 |
expdp hr/hr directory=mypump dumpfile=hr.dmp exclude=table:"in('EMPLOYEES')" expdp hr/hr directory=mypump dumpfile=hr.dmp exclude=table:\"in \(\'EMPLOYEES\'\)\" expdp hr/hr directory=mypump dumpfile=hr.dmp exclude=table:\"in \(\'EMPLOYEES\',\'JOBS\'\)\" expdp hr/hr directory=mypump dumpfile=hr.dmp exclude=table:\"in \(select table_name from all_tables where owner=upper\(\'hr\'\) and table_name like \'E%\'\)\" expdp hr/hr directory=mypump dumpfile=hr.dmp exclude=table:\"like \'E%\'\",exclude=table:\"like \'J%\'\" |
关于expdp导出的一致性
exp 用 consistent=Y 参数
expdp 用 flashback_scn 或者 flashback_time=sysdate 参数
expdp hr/hr directory=mypump dumpfile=hr.dmp logfile=hr.log flashback_time=sysdate
1 2 3 4 5 6 7 8 9 10 11 12 |
// 使用触发器插入表A时同步更新表B create table tab1(id int,name varchar2(20)); create table tab2(id int,name varchar2(20)); CREATE OR REPLACE TRIGGER hr.TG_TEST BEFORE INSERT ON hr.TAB1 REFERENCING NEW AS New OLD AS Old FOR EACH ROW BEGIN insert into tab2 (id, name) values (:New.id, :New.name); END tg_test; / |
定时expdp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// expdpbackup.sh // 0 3 * * * /u01/exp.sh > /dev/null 2>&1 #!/bin/sh export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1 export ORACLE_SID=orcl export PATH=$ORACLE_HOME/bin:$PATH export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS' EXP_FILE="ortest_begin_`date +%Y%m%d%H%M%S`.dmp" LOG_FILE="${EXP_FILE}.log" cd /u01/pump find . -ctime +7 -exec rm -rf {} \; if [ -f $EXP_FILE ]; then rm -f $EXP_FILE* fi expdp hr/hr directory=mypump dumpfile=$EXP_FILE logfile=$LOG_FILE flashback_time=sysdate gzip -9 /u01/pump/$EXP_FILE |
impdp 命令
既导入结构也导入数据
impdp hr/hr directory=mypump dumpfile=hr.dmp tables=test
只导入结构
impdp hr/hr directory=mypump dumpfile=hr.dmp tables=test content=metadata_only
只导入数据
impdp hr/hr directory=mypump dumpfile=hr.dmp tables=test content=data_only
导入用户:
impdp hr/hr directory=mypump dumpfile=hr.dmp
将hr用户下的数据导入到hr1用户下
grant read,write on directory mypump to hr1
grant dba to hr1
impdp hr1/hr1 directory=mypump dumpfile=hr.dmp remap_schema=hr:hr1
impdp hr1/hr1 directory=mypump dumpfile=hr.dmp tables=hr:hr1 content=data_only
处理数据泵 job 后台进程
Ctrl+C 组合键:在执行过程中,可以按 Ctrl+C 组合键退出当前模式,退出之后,导出操作不会停止
Export> status –查看当前 JOB 的状态及相关信息
Export> stop_job –暂停 JOB(暂停 job 后会退出 expor 模式)
重新进入 export 模式下: expdp begin/begin attach=begin.SYS_EXPORT_SCHEMA_01
Export> start_job –打开暂停的 JOB
Export> kill_job –取消当前的 JOB 并释放相关客户会话(将 job 删除同时删除 dmp 文件)
Export> exit –通过此命令退出 export 模式(通过 4)可再进入export 模式下)