在Unix上使用管道压缩exp导出文件

exp导出文件大到文件系统放不下怎么办?

在Unix上一种行之有效的解决方法是创建一个命名管道,因为exp的导出dumpfile的内容是顺序的,可以将其内容重定向到管道并对该管道实施压缩操作,从而实现其直接的导出文件就是压缩过的。下面我们举出一个使用该中管道压缩的例子:

[oracle@vrh1 exp]$ exp system/oracle  file=maclean.dmp tables=maclean.tv

Export: Release 10.2.0.4.0 - Production on Fri Apr 1 17:03:09 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
Current user changed to MACLEAN
. . exporting table                             TV      19988 rows exported
Export terminated successfully without warnings.

/* 不压缩情况下本例中的dumpfile大小为2MB  */

[oracle@vrh1 exp]$ ls -lh maclean.dmp 
-rw-r--r-- 1 oracle oinstall 2.0M Apr  1 17:03 maclean.dmp

/* 首先使用mknod命令创建命名管道 */

[oracle@vrh1 exp]$ mknod macleanpipe p

/*使用nohup命令在后台执行对macleanpipe管道的内容进行gzip压缩,
   之后重定向到maclean_compress.dmp.gz压缩文件                 */


[oracle@vrh1 exp]$ nohup  gzip maclean_compress.dmp.gz &
[1] 27686


[oracle@vrh1 exp]$ exp system/oracle file=macleanpipe tables=maclean.tv


Export: Release 10.2.0.4.0 - Production on Fri Apr 1 17:13:50 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
Current user changed to MACLEAN
. . exporting table                             TV      19988 rows exported
Export terminated successfully without warnings.


[1]+  Done                    nohup gzip < macleanpipe > maclean_compress.dmp.gz

/* 以上当压缩进程gzip接收到exp输出的EOF文件终结符后,
    该压缩进程会自行结束                 * / 

/* 可以看到这里的压缩比还是很高的 */

[oracle@vrh1 exp]$ ls -lh maclean_compress.dmp.gz 
-rw-r--r-- 1 oracle oinstall 225K Apr  1 17:13 maclean_compress.dmp.gz

/* 使用gzip -d命令解压以上gz文件就可以得到普通的dumpfile用以imp导入 */

[oracle@vrh1 exp]$ gzip -d maclean_compress.dmp.gz 

[oracle@vrh1 exp]$ ls -lh maclean_compress.dmp 
-rw-r--r-- 1 oracle oinstall 2.0M Apr  1 17:13 maclean_compress.dmp

在Oracle 10g中引入了速度更快的DataPump Server-side Expdp/Impdp导入导出工具,与exp不同的是,Expdp导出的dumpfile中信息不遵循某种顺序规则,这导致传统的顺序设备如磁带和管道不支持expdp或impdp;换而言之我们无法使用expdp工具将导出结果直接输出到磁带设备或命名管道中,这也造成上述介绍的管道压缩方法对expdp命令是不适用的。

所幸在Oracle Database 11g中对Expdp的压缩选项添加了all和dataonly选项,虽然目前Datapump压缩的性能仍比gzip压缩要差一些,但2者间的差别几乎可以忽略不计。一般在11g中,Oracle推荐使用DataPump压缩来彻底代替Unix管道压缩。


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *