且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

EXP/IMP 学习(三)

更新时间:2022-03-08 05:43:42

1.3  优化
1.  加快exp速度
加大 large_pool_size,可以提高 exp的速度 采用直接路径的方式(direct=y),数据不需要经过内存进行整合和检查. 设置较大的 buffer,如果导出大对象,小 buffer会失败。
export文件不在 ORACLE使用的驱动器上 不要 export到 NFS文件系统
UNIX环境:用管道模式直接导入导出来提高 imp/exp的性能

2.  加快imp速度
建立一个 indexfile,在数据 import完成后在建立索引
将 import 文件放在不同的驱动器上 增加 DB_BLOCK_BUFFERS
增加 LOG_BUFFER
用非归档方式运行 ORACLE:ALTER DATABASE NOARCHIVELOG; 建立大的表空间和回滚段,OFFLINE其他回滚段,回滚段的大小为最大表的 1/2 使用  COMMIT=N
使用 ANALYZE=N
单用户模式导入
UNIX环境:用管道模式直接导入导出来提高 imp/exp的性能

3.  通过unix/Linux PIPE管道加快exp/imp速度
通过管道导出数据:
1.通过 mknod -p 建立管道
$ mknod /home/exppipe p    //  在目录/home下建立一个管道 exppipe注意参数 p
2.通过 exp和 gzip导出数据到建立的管道并压缩
$ exp test/test file=/home/exppipe & gzip exp.dmp.gz
$ exp test/test tables=bitmap file=/home/newsys/test.pipe &
gzip bitmap.dmp.gz
3.导出成功完成之后删除建立的管道
$ rm    -rf    /home/exppipe
 
导出脚本:
###UNIX下 ORACLE数据库通过 PIPE管道进行备份
###### using "export" and "tar" command to bakup oracle datebase #######
trap "" 1 #nohup
LOGFILE=/opt/bakup/log/bakup_ora.log
export LOGFILE
DUMPDIR=/archlog_node1
export DUMPDIR
exec >$LOGFILE 2>&1
 
echo
echo ' Begin at ' `date`
echo
 
#               clear old result file
cd $DUMPDIR
if [ -f exp.dmp.Z ]
then
echo "clear old result file"
rm exp.dmp.Z
fi
 
#make pipe
mkfifo exp.pipe
chmod a+rw exp.pipe
 
#gain the dmp.Z file
compress exp.dmp.Z &
su -u oracle -c "exp userid=ll/ll file=$DUMPDIR/exp.pipe full=y buffer=20000000"
echo
echo ' exp end at '`date`
echo
# rm pipe
rm exp.pipe
#tar the dmp.Z file to tape
mt -f /dev/rmt/0 rew
tar cvf /dev/rmt/0 exp.dmp.Z
echo
echo 'tar end at '`date`
echo
通过管道导入生成的文件:
1.通过 mknod -p 建立管道
$ mknod /home/exppipe p
2.导入生成的压缩文件
$ imp test/test file=/home/exppipe fromuser=test touser=macro &
gunzip /home/exppipe
3.删除管道
$ rm –fr /home/exppipe
 
4.  全库导入的一般步骤
注意:在导出时,需要通过toad或其他工具提取源数据库创建主键和索引的脚本
1.  先全库加 rows=n 把结构导进去
$ imp system/manager file=exp.dmp log=imp.log full=y rows=n indexes=n
2.  使业务用户的触发器失效/删除主键和唯一索引
spool drop_pk_u.sql
select 'alter table '||table_name||' drop constraint '||constraint_name||';'
from user_constraints
where constraint_type in ('P','U');
/
spool off
spool disable_trigger.sql
select 'alter trigger '||trigger_name||' disable;'
from user_triggers;
/
spool off
@drop_pk_u.sql
@disable_trigger.sql
3.  以 ignore=y全库导入
$ imp system/manager file=exp.dmp log=imp.log full=y ignore=y
4.  通过 toad或其他工具提取源数据库创建主键和索引的脚本,在目标数据库中创建主键和索引。使触发器生效。