码迷,mamicode.com
首页 > 其他好文 > 详细

专题实验 EXP & IMP

时间:2014-07-03 06:24:20      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:des   使用   strong   文件   数据   os   

基本语法和实例:

1、EXP:


有三种主要的方式(完全、用户、表)
1、完全:
exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y file=exp_.dmp log=exp.log

如果要执行完全导出,必须具有特殊的权限
2、用户模式:
exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp.dmp log=exp.log
3、表模式:
exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 volsize=0 file=exp.dmp log=exp.log tables=tab1,tab2,tab3

parameter

Keyword Description (Default) Keyword Description (Default)

--------------------------------------------------------------------------

USERID username/password FULL export entire file (N)

BUFFER size of data buffer OWNER list of owner usernames

FILE output files (EXPDAT.DMP) TABLES list of table names

COMPRESS import into one extent (Y) RECORDLENGTH length of IO record

GRANTS export grants (Y) INCTYPE incremental export type

INDEXES export indexes (Y) RECORD track incr. export (Y)

DIRECT direct path (N) TRIGGERS export triggers (Y)

LOG log file of screen output STATISTICS analyze objects (ESTIMATE)

ROWS export data rows (Y) PARFILE parameter filename

CONSISTENT cross-table consistency(N) CONSTRAINTS export constraints (Y)

OBJECT_CONSISTENT transaction set to read only during object export (N)

FEEDBACK display progress every x rows (0)

FILESIZE maximum size of each dump file

FLASHBACK_SCN SCN used to set session snapshot back to

FLASHBACK_TIME time used to get the SCN closest to the specified time

QUERY select clause used to export a subset of a table

RESUMABLE suspend when a space related error is encountered(N)

RESUMABLE_NAME text string used to identify resumable statement

RESUMABLE_TIMEOUT wait time for RESUMABLE

TTS_FULL_CHECK perform full or partial dependency check for TTS

VOLSIZE number of bytes to write to each tape volume

TABLESPACES list of tablespaces to export

TRANSPORT_TABLESPACE export transportable tablespace metadata (N)

TEMPLATE template name which invokes iAS mode export

 

2、IMP:


具有三种模式(完全、用户、表)与 EXP 对应 
1、完全:
IMP SYSTEM/MANAGER BUFFER=64000 FILE=C:\FULL.DMP FULL=Y
2、用户模式:
IMP SONIC/SONIC BUFFER=64000 FILE=C:\SONIC.DMP FROMUSER=SONIC TOUSER=SONIC
这样用户SONIC的所有对象被导入到文件中。必须指定FROMUSER、TOUSER参数,这样才能导入数据。
3、表模式: 
IMP SONIC/SONIC BUFFER=64000 FILE=C:\SONIC.DMP OWNER=SONIC TABLES=(SONIC)
这样用户SONIC的表SONIC就被导入。

parameter

Keyword Description (Default) Keyword Description (Default)

--------------------------------------------------------------------------

USERID username/password FULL import entire file (N)

BUFFER size of data buffer FROMUSER list of owner usernames

FILE input files (EXPDAT.DMP) TOUSER list of usernames

SHOW just list file contents (N) TABLES list of table names

IGNORE ignore create errors (N) RECORDLENGTH length of IO record

GRANTS import grants (Y) INCTYPE incremental import type

INDEXES import indexes (Y) COMMIT commit array insert (N)

ROWS import data rows (Y) PARFILE parameter filename

LOG log file of screen output CONSTRAINTS import constraints (Y)

DESTROY overwrite tablespace data file (N)

INDEXFILE write table/index info to specified file

SKIP_UNUSABLE_INDEXES skip maintenance of unusable indexes (N)

FEEDBACK display progress every x rows(0)

TOID_NOVALIDATE skip validation of specified type ids

FILESIZE maximum size of each dump file

STATISTICS import precomputed statistics (always)

RESUMABLE suspend when a space related error is encountered(N)

RESUMABLE_NAME text string used to identify resumable statement

RESUMABLE_TIMEOUT wait time for RESUMABLE

COMPILE compile procedures, packages, and functions (Y)

STREAMS_CONFIGURATION import streams general metadata (Y)

STREAMS_INSTANTIATION import streams instantiation metadata (N)

VOLSIZE number of bytes in file on each volume of a file on tape

The following keywords only apply to transportable tablespaces

TRANSPORT_TABLESPACE import transportable tablespace metadata (N)

TABLESPACES tablespaces to be transported into database

DATAFILES datafiles to be transported into database

TTS_OWNERS users that own data in the transportable tablespace set

示例

4.1 oracle创建表空间,创建用户

//创建临时表空间

create temporary tablespace test_temp

tempfile ‘/u01/app/oracle/oradata/orcl/test_temp01.Dbf‘

size 32m autoextend on next 32m maxsize 2048m

extent management local;

//创建数据表空间

create tablespace test_data logging

datafile ‘/u01/app/oracle/oradata/orcl/test_data01.dbf‘ ­

size 32m autoextend on

next 32m maxsize 2048m

extent management local;

//创建用户并指定表空间

create user username identified by password

default tablespace test_data

temporary tablespace test_temp;

//给用户授予权限 ­

grant connect,resource to username;

先创建一个用户和表空间,用户名david,密码david.在这个表空间下创建一个表:tianle。随便插入些数据。代码如下:

SQL> create tablespace test_data

3 datafile ‘/u01/app/oracle/oradata/orcl/test_data01.dbf‘

4 size 5m;

Tablespace created.

SQL> create user david identified by david default tablespace test_data;

SQL> grant connect,resource to david;

SQL> conn david/david

SQL> create table tianle(id number, content varchar2(100));

SQL> set wrap off

SQL> column id format a20;

SQL> column content format a50;

4.2 表模式备份 与 恢复

备份:

[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log tables=(tianle);

恢复:

[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=y buffer=65536 file=exp_tianle_090101.dmp log=imp_tianle_090101.log tables=(tianle); ­

4.3 用户模式备份与恢复

备份:

[oracle@roy orcl]$ exp david/david owner=david rows=y indexes=n compress=n buffer=65536 file=exp_david__090101.dmp log=exp_david_090101.log; ­

恢复:

[oracle@roy orcl]$ imp david/david fromuser=david touser=david rows=y indexes=n commit=y buffer=65536 file=exp_tianle_090101.dmp log=exp_tianle_090101.log; ­

4.4 完全模式备份与恢复

备份:

[oracle@roy orcl]$ exp david/david rows=y indexes=n compress=n buffer=65536 full=y file=exp_fulldatabase_090101.dmp log=exp_fulldatabase_090101.log; ­

恢复

[oracle@roy orcl]$ imp david/david rows=y indexes=n commit=y full=y ignore=y buffer=65536 file=/tmp/exp_fulldatabase_090101.dmp log=/tmp/imp.log;


EXP常用选项
1.FULL,这个用于导出整个数据库,在ROWS=N一起使用时,可以导出整个数据库的结构。例如:
exp userid=test/test file=./db_str.dmp log=./db_str.log full=y rows=n compress=y direct=y

2. OWNER和TABLE,这两个选项用于定义EXP的对象。OWNER定义导出指定用户的对象;TABLE指定EXP的table名称,例如:
exp userid=test/test file=./db_str.dmp log=./db_str.log owner=duanl
exp userid=test/test file=./db_str.dmp log=./db_str.log table=nc_data,fi_arap

3.BUFFER和FEEDBACK,在导出比较多的数据时,我会考虑设置这两个参数。例如:
exp userid=test/test file=yw97_2003.dmp log=yw97_2003_3.log feedback=10000 buffer=100000000 tables=WO4,OK_YT

4.FILE和LOG,这两个参数分别指定备份的DMP名称和LOG名称,包括文件名和目录,例子见上面。

5.COMPRESS参数不压缩导出数据的内容。用来控制导出对象的storage语句如何产生。默认值为Y,使用默认值,对象的存储语句的init extent等于当前导出对象的extent的总和。推荐使用COMPRESS=N。

IMP常用选项
1、FROMUSER和TOUSER,使用它们实现将数据从一个SCHEMA中导入到另外一个SCHEMA中。例如:假设我们做exp时导出的为test的对象,现在我们想把对象导入用户:
imp userid=test1/test1 file=expdat.dmp fromuser=test1 touser=test1

2、IGNORE、GRANTS和INDEXES,其中IGNORE参数将忽略表的存在,继续导入,这个对于需要调整表的存储参数时很有用,我们可以先根据实际情况用合理的存储参数建好表,然后直接导入数据。而GRANTS和INDEXES则表示是否导入授权和索引,如果想使用新的存储参数重建索引,或者为了加快到入速度,我们可以考虑将INDEXES设为N,而GRANTS一般都是Y。例如:imp userid=test1/test1 file=expdat.dmp fromuser=test1 touser=test1 indexes=N

优化EXP/IMP的方法:
当需要exp/imp的数据量比较大时,这个过程需要的时间是比较长的,我们可以用一些方法来优化exp/imp的操作。
exp:使用直接路径 direct=y
oracle会避开sql语句处理引擎,直接从数据库文件中读取数据,然后写入导出文件.
可以在导出日志中观察到: exp-00067: table xxx will be exported in conventional path
如果没有使用直接路径,必须保证buffer参数的值足够大.
有一些参数于direct=y不兼容,无法用直接路径导出可移动的tablespace,或者用query参数导出数据库子集.
当导入导出的数据库运行在不同的os下时,必须保证recordlength参数的值一致

imp:通过以下几个途径优化
1.避免磁盘排序
将sort_area_size设置为一个较大的值,比如100M
2.避免日志切换等待
增加重做日志组的数量,增大日志文件大小.
3.优化日志缓冲区
比如将log_buffer容量扩大10倍(最大不要超过5M)
4.使用阵列插入与提交
commit = y
注意:阵列方式不能处理包含LOB和LONG类型的表,对于这样的table,如果使用commit = y,每插入一行,就会执行一次提交.
5.使用NOLOGGING方式减小重做日志大小
在导入时指定参数indexes=n,只导入数据而忽略index,在导完数据后在通过脚本创建index,指定 NOLOGGING选项

导出/导入与字符集
进行数据的导入导出时,我们要注意关于字符集的问题。在EXP/IMP过程中我们需要注意四个字符集的参数:导出端的客户端字符集,导出端数据库字符集,导入端的客户端字符集,导入端数据库字符集。
我们首先需要查看这四个字符集参数。
查看数据库的字符集的信息:
SQL> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET ZHS16GBK
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZH:TZM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZH:TZM
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_NCHAR_CHARACTERSET ZHS16GBK
NLS_RDBMS_VERSION 8.1.7.4.1
NLS_CHARACTERSET:ZHS16GBK是当前数据库的字符集。

我们再来查看客户端的字符集信息:
客户端字符集的参数NLS_LANG=_< territory >.
language:指定oracle消息使用的语言,日期中日和月的显示。
Territory:指定货币和数字的格式,地区和计算星期及日期的习惯。
Characterset:控制客户端应用程序使用的字符集。通常设置或等于客户端的代码页。或者对于unicode应用设为UTF8。
在windows中,查询和修改NLS_LANG可在注册表中进行:
HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\HOMExx\
xx指存在多个Oracle_HOME时的系统编号。

在unix中:
$ env|grep NLS_LANG
NLS_LANG=simplified chinese_china.ZHS16GBK
修改可用:
$ export NLS_LANG=AMERICAN_AMERICA.UTF8

通常在导出时最好把客户端字符集设置得和数据库端相同。当进行数据导入时,主要有以下两种情况:
(1) 源数据库和目标数据库具有相同的字符集设置。
这时,只需设置导出和导入端的客户端NLS_LANG等于数据库字符集即可。
(2) 源数据库和目标数据库字符集不同。
先将导出端客户端的NLS_LANG设置成和导出端的数据库字符集一致,导出数据,然后将导入端客户端的NLS_LANG设置成和导出端一致,导入数据,这样转换只发生在数据库端,而且只发生一次。
这种情况下,只有当导入端数据库字符集为导出端数据库字符集的严格超集时,数据才能完全导成功,否则,可能会有数据不一致或乱码出现。

不同版本的EXP/IMP问题
一般来说,从低版本导入到高版本问题不大,麻烦的是将高版本的数据导入到低版本中,在Oracle9i之前,不同版本Oracle之间的EXP/IMP可以通过下面的方法来解决:
1、在高版本数据库上运行底版本的catexp.sql;
2、使用低版本的EXP来导出高版本的数据;
3、使用低版本的IMP将数据库导入到低版本数据库中;
4、在高版本数据库上重新运行高版本的catexp.sql脚本。
但在9i中,上面的方法并不能解决问题。如果直接使用低版本EXP/IMP会出现如下错误:
EXP-00008: orACLE error %lu encountered
orA-00904: invalid column name
这已经是一个公布的BUG,需要等到Oracle10.0才能解决,BUG号为2261722,你可以到METALINK上去查看有关此BUG的详细信息。
BUG归BUG,我们的工作还是要做,在没有Oracle的支持之前,我们就自己解决。在Oracle9i中执行下面的SQL重建exu81rls视图即可。
Create or REPLACE view exu81rls
(objown,objnam,policy,polown,polsch,polfun,stmts,chkopt,enabled,spolicy)
AS select u.name, o.name, r.pname, r.pfschma, r.ppname, r.pfname,
decode(bitand(r.stmt_type,1), 0,‘‘, ‘Select,‘)
|| decode(bitand(r.stmt_type,2), 0,‘‘, ‘Insert,‘)
|| decode(bitand(r.stmt_type,4), 0,‘‘, ‘Update,‘)
|| decode(bitand(r.stmt_type,8), 0,‘‘, ‘Delete,‘),
r.check_opt, r.enable_flag,
DECODE(BITAND(r.stmt_type, 16), 0, 0, 1)
from user$ u, obj$ o, rls$ r
where u.user# = o.owner#
and r.obj# = o.obj#
and (uid = 0 or
uid = o.owner# or
exists ( select * from session_roles where role=‘Select_CATALOG_ROLE‘)
)
/
grant select on sys.exu81rls to public;
/
可以跨版本的使用EXP/IMP,但必须正确地使用EXP和IMP的版本:
1、总是使用IMP的版本匹配数据库的版本,如:要导入到817中,使用817的IMP工具。
2、总是使用EXP的版本匹配两个数据库中最低的版本,如:从9201往817中导入,则使用817版本的EXP工具

专题实验 EXP & IMP,布布扣,bubuko.com

专题实验 EXP & IMP

标签:des   使用   strong   文件   数据   os   

原文地址:http://www.cnblogs.com/moveofgod/p/3818524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!