Utilities之EXP&IMP小结-续2-实例测试

来源:互联网 发布:head first java epdu 编辑:程序博客网 时间:2024/06/03 17:36
    通过之前的几篇文章大致了解了EXP\IMP使用的一些参数,下面开始结合一些例子来加上了解。
    show下EXP\IMP使用帮助吧。
[oracle@localhost test]$ exp help=y

Export: Release 10.2.0.4.0 - Production on Thu Jan 19 17:25:53 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.



You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:

     Example: EXP SCOTT/TIGER

Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

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

Export terminated successfully without warnings.
[oracle@localhost test]$ imp help=y

Import: Release 10.2.0.4.0 - Production on Thu Jan 19 17:25:58 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.



You can let Import prompt you for parameters by entering the IMP
command followed by your username/password:

     Example: IMP SCOTT/TIGER

Or, you can control how Import runs by entering the IMP command followed
by various arguments. To specify parameters, you use keywords:

     Format:  IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

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

Import terminated successfully without warnings.
    有心的话数数有多少个参数吧,还真别说,有的面试官就问这问题,所以,赶快数数吧。
    example.0. 显示导入对象的创建语句
    首先创建测试表。
[oracle@localhost test]$ sqlplus gtlions/gtlions

SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jan 19 17:34:30 2012

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, OLAP, Data Mining and Real Application Testing options

SQL> create table expimptest as select object_id,object_name from dba_objects where rownum<=100;

Table created.
SQL> alter table expimptest add constraint PK_OBJID primary key (object_id);

Table altered.

SQL> create index IDX_OBJNAME on expimptest (object_name);

Index created.
    下面先做一个导出操作。
[oracle@localhost test]$ exp gtlions/gtlions file=exp log=exp

Export: Release 10.2.0.4.0 - Production on Thu Jan 19 17:39:28 2012

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, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user GTLIONS
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user GTLIONS
About to export GTLIONS's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export GTLIONS's tables via Conventional Path ...
. . exporting table                     EXPIMPTEST        100 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
    执行导入,但是并不导入数据,只是需要获得对象创建语句。
[oracle@localhost test]$ imp gtlions/gtlions file=exp log=imp fromuser=gtlions show=y

Import: Release 10.2.0.4.0 - Production on Thu Jan 19 17:40:00 2012

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, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing GTLIONS's objects into GTLIONS
 "BEGIN  "
 "sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','"
 "CURRENT_SCHEMA'), export_db_name=>'TEST', inst_scn=>'80271930');"
 "COMMIT; END;"
 "CREATE TABLE "EXPIMPTEST" ("OBJECT_ID" NUMBER, "OBJECT_NAME" VARCHAR2(128))"
 "  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREEL"
 "ISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING "
 "NOCOMPRESS"
. . skipping table "EXPIMPTEST"                       

 "CREATE UNIQUE INDEX "PK_OBJID" ON "EXPIMPTEST" ("OBJECT_ID" )  PCTFREE 10 I"
 "NITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 "
 "BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING"
 "CREATE INDEX "IDX_OBJNAME" ON "EXPIMPTEST" ("OBJECT_NAME" )  PCTFREE 10 INI"
 "TRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BU"
 "FFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING"
 "ALTER TABLE "EXPIMPTEST" ADD  CONSTRAINT "PK_OBJID" PRIMARY KEY ("OBJECT_ID"
 "") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FRE"
 "ELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGIN"
 "G ENABLE "
Import terminated successfully without warnings.
[oracle@localhost test]$ cat imp.log

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing GTLIONS's objects into GTLIONS
 "BEGIN  "
 "sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','"
 "CURRENT_SCHEMA'), export_db_name=>'TEST', inst_scn=>'80271930');"
 "COMMIT; END;"
 "CREATE TABLE "EXPIMPTEST" ("OBJECT_ID" NUMBER, "OBJECT_NAME" VARCHAR2(128))"
 "  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREEL"
 "ISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING "
 "NOCOMPRESS"
. . skipping table "EXPIMPTEST"                       

 "CREATE UNIQUE INDEX "PK_OBJID" ON "EXPIMPTEST" ("OBJECT_ID" )  PCTFREE 10 I"
 "NITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 "
 "BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING"
 "CREATE INDEX "IDX_OBJNAME" ON "EXPIMPTEST" ("OBJECT_NAME" )  PCTFREE 10 INI"
 "TRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BU"
 "FFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING"
 "ALTER TABLE "EXPIMPTEST" ADD  CONSTRAINT "PK_OBJID" PRIMARY KEY ("OBJECT_ID"
 "") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FRE"
 "ELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGIN"
 "G ENABLE "
Import terminated successfully without warnings.
    从上面导入过程的输出或者日志中均可以获得我们想要的DML语句。
    再来一个现实创建索引的语句的例子。
[oracle@localhost test]$ imp gtlions/gtlions file=exp log=imp fromuser=gtlions indexfile=index

Import: Release 10.2.0.4.0 - Production on Fri Jan 20 15:07:47 2012

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, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. . skipping table "EXPIMPTEST"                       

Import terminated successfully without warnings.
[oracle@localhost test]$ cat index.sql

REM  CREATE TABLE "GTLIONS"."EXPIMPTEST" ("OBJECT_ID" NUMBER,
REM  "OBJECT_NAME" VARCHAR2(128)) PCTFREE 10 PCTUSED 40 INITRANS 1
REM  MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1
REM  BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING NOCOMPRESS ;
REM  ... 100 rows
CONNECT GTLIONS;
CREATE UNIQUE INDEX "GTLIONS"."PK_OBJID" ON "EXPIMPTEST" ("OBJECT_ID" )
PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1
FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING ;
CREATE INDEX "GTLIONS"."IDX_OBJNAME" ON "EXPIMPTEST" ("OBJECT_NAME" )
PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1
FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "GTLIONS" LOGGING ;
REM  ALTER TABLE "GTLIONS"."EXPIMPTEST" ADD CONSTRAINT "PK_OBJID" PRIMARY
REM  KEY ("OBJECT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
REM  STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
REM  DEFAULT) TABLESPACE "GTLIONS" LOGGING ENABLE ;
    example.1. 挂起测试
下面测试一个空间不够的例子,在测试之前将用户的空间使用权限收回。
SQL> select * from dba_sys_privs where grantee='GTLIONS';

GRANTEE                PRIVILEGE                ADM
------------------------------ ---------------------------------------- ---
GTLIONS                UNLIMITED TABLESPACE            NO

SQL> revoke unlimited tablespace from gtlions;

Revoke succeeded.

SQL> select * from dba_sys_privs where grantee='GTLIONS';

no rows selected

接着进行导入,正常情况下就会导入失败提示没有使用空间。
[oracle@localhost test]$ imp gtlions/gtlions file=exp.dmp log=imp.log  fromuser=gtlions

Import: Release 10.2.0.4.0 - Production on Fri Jan 20 15:26:02 2012

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, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing GTLIONS's objects into GTLIONS
IMP-00017: following statement failed with ORACLE error 1536:
 "CREATE TABLE "EXPIMPTEST" ("OBJECT_ID" NUMBER, "OBJECT_NAME" VARCHAR2(128))"
 "  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREEL"
 "ISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)                      LOGGING "
 "NOCOMPRESS"
IMP-00003: ORACLE error 1536 encountered
ORA-01536: space quota exceeded for tablespace 'USERS'
Import terminated successfully with warnings.
如果增加了挂起参数,可以看到导入并不会失败,只是挂起:
[oracle@localhost test]$ imp gtlions/gtlions file=exp.dmp log=imp.log  fromuser=gtlions resumable=y resumable_name=not_enough_space resumable_timeout=3600

Import: Release 10.2.0.4.0 - Production on Fri Jan 20 15:33:12 2012

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, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing GTLIONS's objects into GTLIONS
这个时候可以去数据库查看相关视图并解决,问题解决后导入就会自动继续。
SQL> select user_id,name,sql_text from dba_resumable;

   USER_ID
----------
NAME
----------------------------------------------------------------------------------------------------------------------------------
SQL_TEXT
----------------------------------------------------------------------------------------------------------------------------------
    57
not_enough_space
CREATE TABLE "EXPIMPTEST" ("OBJECT_ID" NUMBER, "OBJECT_NAME" VARCHAR2(128))  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE
(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)               LOGGING NOCOMPRESS


SQL> grant unlimited tablespace to gtlions;

Grant succeeded.
    example.2. 传输表空间
注意:
传输表空间要求表空间置于只读状态;
且必须dba操作;
目标库必须存在对应用户。
操作步骤:导出表空间置于只读->执行导出->传输表空间的数据文件->导出表空间置于读写->执行导入。
[oracle@localhost test]$ exp gtlions/gtlions file=exp.dmp log=exp.log tablespaces=gtlions transport_tablespace=y

Export: Release 10.2.0.4.0 - Production on Fri Jan 20 15:38:47 2012

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, OLAP, Data Mining and Real Application Testing options
EXP-00044: must be connected 'AS SYSDBA' to do Point-in-time Recovery or Transportable Tablespace import
EXP-00000: Export terminated unsuccessfully
[oracle@localhost test]$ exp \"gtlions/gtlions as sysdba \" file=exp.dmp log=exp.log tablespaces=gtlions transport_tablespace=y

Export: Release 10.2.0.4.0 - Production on Fri Jan 20 15:39:11 2012

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, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
EXP-00008: ORACLE error 29335 encountered
ORA-29335: tablespace 'GTLIONS' is not read only
ORA-06512: at "SYS.DBMS_PLUGTS", line 507
ORA-06512: at line 1
EXP-00000: Export terminated unsuccessfully
[oracle@localhost test]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jan 20 15:39:21 2012

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, OLAP, Data Mining and Real Application Testing options

SQL> alter tablespace gtliosn read only;
alter tablespace gtliosn read only
*
ERROR at line 1:
ORA-00959: tablespace 'GTLIOSN' does not exist


SQL> alter tablespace gtlions read only;

Tablespace altered.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost test]$ exp \"gtlions/gtlions as sysdba \" file=exp.dmp log=exp.log tablespaces=gtlions transport_tablespace=y

Export: Release 10.2.0.4.0 - Production on Fri Jan 20 15:39:53 2012

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, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace GTLIONS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                     EXPIMPTEST
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
[oracle@localhost test]$ imp \"sys/test as sysdba \" file=exp.dmp log=imp.log  fromuser=gtlions touser=gtlions datafiles='/usr/oracle/oradata/TEST1/gtlions01.dbf' tablespaces=gtlions transport_tablespace=y

Import: Release 10.2.0.4.0 - Production on Fri Jan 20 15:49:47 2012

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, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
About to import transportable tablespace(s) metadata...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing GTLIONS's objects into GTLIONS
. . importing table                   "EXPIMPTEST"
Import terminated successfully without warnings.
大概的测试了下比较使用而且可能会用到的几个参数,其实大部分的参数只要有个了解,以后遇到问题的时候能够想起即可,到时临时报下佛脚即可。
-The End-




原创粉丝点击