---
title: "逻辑备份与恢复"
author: "1enny"
date: "2015-02-25T09:54:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2015-03-14T16:50:53Z"
id: 2192337
url: "https://1enny.iteye.com/blog/2192337"
---

oracle227

* * *

[]()

* * *

逻辑备份与恢复

**备份与恢复简介：**

* * *

备份是数据库中数据的副本，它可以保护数据在出现意外

损失时最大限度的恢复。

Oracle数据库的备份包括以下两种类型：

物理备份是对数据库的操作系统物理文件（如数据文件、控制文件和日志文件等）的备份:RMAN备份

逻辑备份是对数据库逻辑组件（如表、视图和存储过程等数据库对象）的备份：imp\[dp]/exp\[dp]

**故障类型：**

* * *

导致数据库操作中止的故障包括四种类型：

语句故障：在执行 SQL 语句无效可导致语句故障。

用户进程故障：当用户程序出错而无法访问数据库时发生用户进程故障。导致用户进程故障的原因是异常断开连接或异常终止进程

实例故障：当 Oracle 的数据库实例由于硬件或软件问题而无法继续运行时，就会发生实例故障

介质故障：在数据库无法正确读取或写入某个数据库文件时，会发生介质故障

语句故障 select * from aa;//假如aa表并不存在的情况 不需要处理 用户进程故障 用户（死机、用户进程消失了）&lt;——&gt;连接&lt;——&gt;服务器（pmon进程处理，监测到客户端进程消失后马上就把serverPro杀死掉） 不需要处理 实例故障 oracle服务器死机、坏掉了，通过重启oracle就可以解决实例故障 不需要处理 介质故障 硬盘坏了导致数据文件丢失或者损坏了 需要dba来进行处理

**传统的导入导出：**

* * *

简介：

> 传统的导出导入程序用于实施数据库的逻辑备份和恢复
> 
> 导出程序将数据库中的对象定义和数据备份到一个操作系统二进制文件中
> 
> 导入程序读取二进制导出文件并将对象和数据载入数据库中
> 
> 传统的导出导入程序是客户端工具。

导出和导入实用程序的特点有：

可以按时间保存表结构和数据

允许导出指定的表，并重新导入到新的数据库中

可以把数据库迁移到另外一台异构服务器上

在两个不同版本的Oracle数据库之间传输数据

在联机状态下进行备份和恢复

可以重新组织表的存储结构，减少链接及磁盘碎片

使用以下三种方法调用导出和导入实用程序：

> 1，交互提示符：以交互的方式提示用户逐个输入参数的值。
> 
> 2，命令行参数：在命令行指定执行程序的参数和参数值。
> 
> 3，参数文件：允许用户将运行参数和参数值存储在参数文件中，以便重复使用参数

导出和导入数据库对象的四种模式是：四种模式独立互斥的，不能同时存在

> 1，数据库模式：导出和导入整个数据库中的所有对象
> 
> 2，表空间模式：导出和导入一个或多个指定的表空间中的所有对象
> 
> 3，用户模式：导出和导入一个用户模式中的所有对象
> 
> 4，表模式：导出和导入一个或多个指定的表或表分区

**表的高水位线可以使用导入导出来下降**  
**导出操作的基本命令参数：**

**参数**

**说明**

USERID

确定执行导出实用程序的用户名和口令

BUFFER

确定导出数据时所使用的缓冲区大小，其大小用字节表示

FILE

指定导出的二进制文件名称，默认的扩展名是.dmp

FULL

指定是否以全部数据库方式导出，只有授权用户才可使用此参数

OWNER

要导出的数据库用户列表

HELP

指定是否显示帮助消息和参数说明

ROWS

确定是否要导出表中的数据

TABLES

按表方式导出时，指定需导出的表和分区的名称

PARFILE

指定传递给导出实用程序的参数文件名

TABLESPACES

按表空间方式导出时，指定要导出的表空间名

\[root@localhost ~]# su-oracle

\[oracle@localhost ~]$clear

\[oracle@localhost ~]$ cd $ORACLE\_BASE

\[oracle@localhost oracle]$ ls

adminarchive cfgtoollogs checkpoints diag flash\_recovery\_area oradata pl\_sql\_pacakge

\[oracle@localhost oracle]$ mkdir-p test\_imp\_exp

\[oracle@localhost oracle]$ cd test\_imp\_exp/

\[oracle@localhost test\_imp\_exp]$ ls

\[oracle@localhost test\_imp\_exp]$ pwd

/u01/app/oracle/test\_imp\_exp

\[oracle@localhost test\_imp\_exp]$sqlplushr/hr@jiagulun

SQL\*Plus:Release11.2.0.1.0 ProductiononTue Jan2023:50:522015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;select\*fromstudent;

IDNAME AGE

*---------- -------------------- ----------*

SQL&gt;select\*fromaddress;

XH ZZ

*---------- ----------*

SQL&gt;exit;

DisconnectedfromOracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

\[oracle@localhost test\_imp\_exp]$exphelp=y*--通过这个来查看关于exp命令的解释*

Export:Release11.2.0.1.0-ProductiononTue Jan2023:51:562015

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

You can letExportpromptyouforparametersbyenteringtheEXP

command followedbyyour username/password:

Example:EXPSCOTT/TIGER

Or,you can control howExportrunsbyenteringtheEXPcommand followed

byvarious arguments.Tospecifyparameters,youusekeywords:

Format:EXPKEYWORD=valueorKEYWORD=(value1,value2,...,valueN)

Example:EXPSCOTT/TIGER GRANTS=YTABLES=(EMP,DEPT,MGR)

orTABLES=(T1:P1,T1:P2),ifT1ispartitionedtable

USERID must bethefirstparameteronthecommand line.

KeywordDescription(Default) KeywordDescription(Default)

*--------------------------------------------------------------------------*

USERID username/passwordFULLexportentirefile(N)

BUFFERsizeofdatabuffer OWNERlistofowner usernames

FILE output files(EXPDAT.DMP)TABLESlistoftablenames

COMPRESS importintooneextent(Y)RECORDLENGTHlengthofIOrecord

GRANTSexportgrants(Y) INCTYPE incrementalexporttype

INDEXESexportindexes(Y)RECORD track incr.export(Y)

DIRECTdirectpath(N)TRIGGERSexporttriggers(Y)

LOGlogfileofscreenoutputSTATISTICSanalyzeobjects(ESTIMATE)

ROWSexportdatarows(Y) PARFILE parameter filename

CONSISTENTcross-tableconsistency(N)CONSTRAINTSexportconstraints(Y)

OBJECT\_CONSISTENTtransactionsettoreadonlyduringobjectexport(N)

FEEDBACK display progress every xrows(0)

FILESIZEmaximumsizeofeachdumpfile

FLASHBACK\_SCNSCNusedtosetsessionsnapshotbackto

FLASHBACK\_TIMEtimeusedtogettheSCNclosesttothespecifiedtime

QUERYselectclause usedtoexporta subsetofatable

RESUMABLEsuspendwhenaspacerelatederrorisencountered(N)

RESUMABLE\_NAME textstringusedtoidentifyresumablestatement

RESUMABLE\_TIMEOUTwaittimeforRESUMABLE

TTS\_FULL\_CHECK performfullorpartial dependencycheckforTTS

VOLSIZEnumberofbytestowritetoeachtape volume

TABLESPACESlistoftablespacestoexport

TRANSPORT\_TABLESPACEexporttransportabletablespacemetadata(N)

TEMPLATEtemplatenamewhich invokes iASmodeexport

\[oracle@localhost test\_imp\_exp]$exphr/hr@jiaguluntables=studentfile=/u01/app/oracle/test\_imp\_exp/hr\_student\_file.dbflog=/u01/app/oracle/test\_imp\_exp/hr\_student\_log.log

Export:Release11.2.0.1.0-ProductiononWed Jan2100:05:422015*--上面的命令为通过导出表的模式导出student表*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportdoneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

Abouttoexportspecifiedtablesvia ConventionalPath...

. . exportingtable STUDENT4rowsexported

Exportterminated successfullywithoutwarnings.

\[oracle@localhost test\_imp\_exp]$!ls-a

ls-a

. .. expdat.dmp hr\_student\_file.dbf hr\_student\_log.log

\[oracle@localhost test\_imp\_exp]$exphr/hr@jiagulun tablespaces=usersfile=/u01/app/oracle/test\_imp\_exp/hr\_tbs\_users\_file.dbflog=/u01/app/oracle/test\_imp\_exp/hr\_tbs\_users\_log.log

Export:Release11.2.0.1.0-ProductiononWed Jan2100:08:232015*--导出表空间*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

EXP-00023:must be aDBAtodoFullDatabaseorTablespaceexport*--假如是导出数据库或者恶表空间需要dba来做*

(2)U(sers),or(3)T(ables):(2)U&gt;u--自动跳到了交互提示符模式：exp

Exportgrants(yes/no):yes&gt;yes

Exporttabledata(yes/no):yes&gt;yes

Compressextents(yes/no):yes&gt;yes

ExportdoneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

Abouttoexportselected tablespaces ...

. exporting referential integrityconstraints

. exportingtriggers

Exportterminated successfullywithwarnings.

\[oracle@localhost test\_imp\_exp]$ ls

expdat.dmp hr\_student\_file.dbf hr\_student\_log.log hr\_tbs\_users\_file.dbf hr\_tbs\_users\_log.log

\[oracle@localhost test\_imp\_exp]$ ll

total40

-rw-r*--r-- 1 oracle oinstall 0 Jan 21 00:02 expdat.dmp*

-rw-r*--r-- 1 oracle oinstall 16384 Jan 21 00:05 hr\_student\_file.dbf*

-rw-r*--r-- 1 oracle oinstall 427 Jan 21 00:05 hr\_student\_log.log*

-rw-r*--r-- 1 oracle oinstall 16384 Jan 21 00:10 hr\_tbs\_users\_file.dbf*

-rw-r*--r-- 1 oracle oinstall 463 Jan 21 00:10 hr\_tbs\_users\_log.log*

\[oracle@localhost test\_imp\_exp]$sqlplus/assysdba

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2100:11:222015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;createusertest1identifiedbytest1;

Usercreated.

SQL&gt;grantconnect,resourcetotest1;

Grantsucceeded.

SQL&gt;createtabletest\_export\_tab(idnumber(20),namevarchar2(20));

Tablecreated.

SQL&gt;insertintotest\_export\_tabvalues(1,'zhangsan');

1rowcreated.

SQL&gt;exit;

DisconnectedfromOracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

\[oracle@localhost test\_imp\_exp]$exphr/hr@jiaguluntables=test1.test\_export\_tabfile=/u01/app/oracle/test\_imp\_exp/hr\_test1\_tab\_file.dbflog=/u01/app/oracle/test\_imp\_exp/hr\_test1\_tab\_log.log

Export:Release11.2.0.1.0-ProductiononWed Jan2100:20:072015*--导出不同用户的表*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportdoneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

Abouttoexportspecifiedtablesvia ConventionalPath...

EXP-00009:noprivilegetoexportTEST1's table TEST\_EXPORT\_TAB

Export terminated successfully with warnings.--导出不同用户的数据信息必须有权限

\[oracle@localhost test\_imp\_exp]$ exp system/oracle@jiagulun tables=test1.test\_export\_tab file=/u01/app/oracle/test\_imp\_exp/hr\_test1\_tab\_file.dbf log=/u01/app/oracle/test\_imp\_exp/hr\_test1\_tab\_log.log

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 00:23:48 2015--system用户可以导出不同用户数据

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit 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 tables via Conventional Path ...

Current user changed to TEST1

. . exporting table TEST\_EXPORT\_TAB 1 rows exported

Export terminated successfully without warnings.

**导入操作的基本命令参数：**

**参数**

**说明**

USERID

指定执行导入的用户名和密码

BUFFER

指定用来读取数据的缓冲区大小，以字节为单位

COMMIT

指定是否在每个数组（其大小由BUFFER参数设置）插入后进行提交

FILE

指定要导入的二进制文件名

FROMUSER

指定要从导出转储文件中导入的用户模式

TOUSER

指定要将对象导入的用户名。FROMUSER与TOUSER可以不同

FULL

指定是否要导入整个导出转储文件

TABLES

指定要导入的表的列表

ROWS

指定是否要导入表中的行

PARFILE

指定传递给导入实用程序的参数文件名，此文件可以包含这里列出的所有参数

IGNORE

导入时是否忽略遇到的错误，默认为N

TABLESPACES

按表空间方式导入，列出要导入的表空间名

\[oracle@localhost test\_imp\_exp]$exphr/hr@jiaguluntables=student,addressfile=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_addlog=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add

Export:Release11.2.0.1.0-ProductiononWed Jan2100:56:302015*--导出文件的表不是table=(tab1,tab2)而是如上面所示*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportdoneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

Abouttoexportspecifiedtablesvia ConventionalPath...

. . exportingtable STUDENT4rowsexported

. . exportingtable ADDRESS4rowsexported

Exportterminated successfullywithoutwarnings.

\[oracle@localhost test\_imp\_exp]$ ls

hr\_stu\_add.dmp hr\_stu\_add.log

\[oracle@localhost test\_imp\_exp]$sqlplushr/hr

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2100:57:042015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;droptableaddress;

Tabledropped.

SQL&gt;droptablestudent;

Tabledropped.

SQL&gt;commit;

Commitcomplete.

SQL&gt;purgerecyclebin;*--清除回收站*

Recyclebinpurged.

SQL&gt;exit

DisconnectedfromOracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

\[oracle@localhost test\_imp\_exp]$ imp hr/hr@jiagulunfile=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add.dmp

Import:Release11.2.0.1.0-ProductiononWed Jan2100:59:272015*--导入表到自己当中去*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportfilecreatedbyEXPORT:V11.02.00 via conventionalpath

import doneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

. importing HR's objects into HR

. importing HR's objectsintoHR

. . importingtable "STUDENT"4rowsimported

. . importingtable "ADDRESS"4rowsimported

Abouttoenableconstraints...

Import terminated successfullywithoutwarnings.

\[oracle@localhost test\_imp\_exp]$ imp hr/hr@jiagulunfile=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add.dmp fromuser=hr touser=test1

Import:Release11.2.0.1.0-ProductiononWed Jan2101:00:312015*--通过其他用户把表导入到另外用户中去*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportfilecreatedbyEXPORT:V11.02.00 via conventionalpath

import doneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

IMP-00007:must be aDBAtoimport objectstoanotheruser's account

IMP-00000: Import terminated unsuccessfully--通过其他用户把表导入到另外用户中去，这是不行的

\[oracle@localhost test\_imp\_exp]$ imp test1/test1@jiagulun file=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add.dmp fromuser=hr touser=test1 tables=student

Import: Release 11.2.0.1.0 - Production on Wed Jan 21 01:01:26 2015--自己导入其他用户的表到自己当中去

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by HR, not by you--可以导入，但是会有警告

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set

. importing HR's objectsintoTEST1

. . importingtable "STUDENT"4rowsimported

Import terminated successfullywithoutwarnings.

\[oracle@localhost test\_imp\_exp]$ impsystem/oracle@jiagulunfile=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add.dmp fromuser=hr touser=test1tables=address

Import:Release11.2.0.1.0-ProductiononWed Jan2101:02:002015*--通过system导入其他表到另外用户中可以*

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportfilecreatedbyEXPORT:V11.02.00 via conventionalpath

Warning:theobjects were exportedbyHR,notbyyou*--通过system导入其他表到另外用户中可以但也会有警告出现*

import doneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

. importing HR's objects into TEST1

. . importing table "ADDRESS" 4 rows imported

About to enable constraints...

Import terminated successfully without warnings.

\[oracle@localhost test\_imp\_exp]$ sqlpus test1/test1

-bash: sqlpus: command not found

\[oracle@localhost test\_imp\_exp]$ sqlplus test1/test1

SQL\*Plus: Release 11.2.0.1.0 Production on Wed Jan 21 01:02:22 2015

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL&gt; select * from tab;

TNAME TABTYPE CLUSTERID

\------------------------------ ------- ----------

ADDRESS TABLE

STUDENT TABLE

TEST\_EXPORT\_TAB TABLE

SQL&gt;

假如我想导入用户已经存在的表：需要添加ignore参数

下面是通过交互提示符的方式导入的：没有添加ignore

\[oracle@localhost test\_imp\_exp]$ imp

Import: Release 11.2.0.1.0 - Production on Wed Jan 21 01:33:00 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Username: test1  
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Import data only (yes/no): no &gt;

Import file: expdat.dmp &gt; hr\_stu\_add.dmp

Enter insert buffer size (minimum is 8192) 30720&gt;

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by HR, not by you

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set  
List contents of import file only (yes/no): no &gt;

Ignore create error due to object existence (yes/no): no &gt;

Import grants (yes/no): yes &gt;

Import table data (yes/no): yes &gt;

Import entire export file (yes/no): no &gt;  
Username: hr

Enter table(T) or partition(T:P) names. Null list means all tables for user  
Enter table(T) or partition(T:P) name or . if done: .

. importing HR's objects into TEST1  
. importing HR's objects into TEST1  
IMP-00015: following statement failed because the object already exists:  
"CREATE TABLE "STUDENT" ("ID" NUMBER(10, 0), "NAME" VARCHAR2(20), "AGE" NUMB"  
"ER(10, 0)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 6"  
"5536 NEXT 1048576 MINEXTENTS 1 FREELISTS 1 FREELIST GROUPS 1 BUFFER\_POOL DE"  
"FAULT) LOGGING NOCOMPRESS"  
IMP-00015: following statement failed because the object already exists:  
"CREATE TABLE "ADDRESS" ("XH" NUMBER, "ZZ" VARCHAR2(10)) PCTFREE 10 PCTUSED"  
" 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1"  
" FREELISTS 1 FREELIST GROUPS 1 BUFFER\_POOL DEFAULT) LOGG"  
"ING NOCOMPRESS"  
Import terminated successfully with warnings.

下面是通过参数文件的方式导入的：添加ignore

file=$ORACLE\_BASE/test\_imp\_exp/hr\_stu\_add.dmp  
ignore=y  
fromuser=hr  
touser=test1  
\[oracle@localhost test\_imp\_exp]$ imp test1/test1@jiagulun parfile=imp\_by\_spfile

Import: Release 11.2.0.1.0 - Production on Wed Jan 21 01:46:58 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by HR, not by you

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set  
. importing HR's objects into TEST1  
. . importing table "STUDENT"  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_STUDENT) violated  
Column 1 1  
Column 2 ▒▒▒▒  
Column 3 20  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_STUDENT) violated  
Column 1 2  
Column 2 ▒▒▒▒  
Column 3 25  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_STUDENT) violated  
Column 1 3  
Column 2 ▒▒▒▒  
Column 3 30  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_STUDENT) violated  
Column 1 4  
Column 2 ▒▒▒▒  
Column 3 30 0 rows imported  
. . importing table "ADDRESS"  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_ADDRESS) violated  
Column 1 3  
Column 2 ▒▒▒▒  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_ADDRESS) violated  
Column 1 2  
Column 2 ֣▒▒  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_ADDRESS) violated  
Column 1 1  
Column 2 ▒▒▒▒  
IMP-00019: row rejected due to ORACLE error 1  
IMP-00003: ORACLE error 1 encountered  
ORA-00001: unique constraint (TEST1.PK\_ADDRESS) violated  
Column 1 4  
Column 2 ▒▒▒▒ 0 rows imported  
About to enable constraints...  
Import terminated successfully with warnings.  
\[oracle@localhost test\_imp\_exp]$

之所以会出现建表语句是因为exp操作就是把数据库中的表的建表信息，数据信息，对象信息全部转换成sql语句

当使用Imp的其实也就是执行里面的sql语句。

当ignore设置为Y时，oracle会忽略其中的错误重新执行一遍建表操作，数据插入操作等

**可传输表空间：**

下面模拟两个不同主机下的不同数据库进行表空间的传输操作：  
明确什么事自包含？  
就是要传输的表空间的对象中被建立的对象存放在其他表空间中：例如表，可以把表的索引建立在其他的表空间中，这样就不是自包含了。  
在Linux下进行的传输表空间：

\[oracle@localhost imp\_tran\_file]$sqlplus/assysdba*--sys登录oracle数据库*

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2118:06:452015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;createtablespacetest\_tran\_tsdatafile'/u01/app/oracle/oradata/jiagulun/test\_tran\_ts\_file.dbf'size10m;

Tablespacecreated.*--创建表空间*

SQL&gt;createtable test\_tran\_tab1(idnumber,namevarchar2(20))tablespacetest\_tran\_ts;

Tablecreated.*--在该表空间中创建表*

SQL&gt;altertablespacetest\_tran\_tsreadonly;

Tablespacealtered.*--修改表空间为只读的状态*

\[oracle@localhost imp\_tran\_file]$sqlplus/assysdba

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2118:18:582015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;execdbms\_tts.transport\_set\_check(test\_tran\_ts,true);

BEGINdbms\_tts.transport\_set\_check(test\_tran\_ts,true);END;

\*

ERRORatline1:

ORA-06550:line1,column36:

PLS-00201:identifier'TEST\_TRAN\_TS'must be declared

ORA-06550:line1,column7:

PL/SQL:Statementignored

SQL&gt;execdbms\_tts.transport\_set\_check('test\_tran\_ts',true);*--检查表空间的是否是自包含*

PL/SQLproceduresuccessfully completed.

SQL&gt;SELECT\*FROMTRANSPORT\_SET\_VIOLATIONS;*--检查表空间的是否是自包含*

norowsselected

SQL&gt;exit;

DisconnectedfromOracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

\[oracle@localhost test\_imp\_exp]$exp\\'system/oracle@jiagulun as sysdba\\'tablespaces=test\_tran\_ts transport\_tablespace=yfile=/u01/app/oracle/test\_imp\_exp/exp\_tran\_file.dmp

Export:Release11.2.0.1.0-ProductiononWed Jan2118:25:372015

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

EXP-00056:ORACLEerror1031encountered

ORA-01031:insufficientprivileges

Username:

Password:

EXP-00056:ORACLEerror1017encountered

ORA-01017:invalid username/password;logon denied

Username:

Password:

EXP-00056:ORACLEerror1017encountered

ORA-01017:invalid username/password;logon denied

EXP-00005:allallowable logonattemptsfailed

EXP-00000:Exportterminated unsuccessfully

\[oracle@localhost test\_imp\_exp]$exp\\'sys/oracle@jiagulun as sysdba\\'tablespaces=test\_tran\_ts transport\_tablespace=yfile=/u01/app/oracle/test\_imp\_exp/exp\_tran\_file.dmp

*--必须使用sys用户而且是as sysdba才可以*

*--在Linux中需要对'进行转义才可以*

Export:Release11.2.0.1.0-ProductiononWed Jan2118:25:492015

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportdoneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

Note:tabledata(rows)willnotbe exported

Abouttoexporttransportabletablespacemetadata...

FortablespaceTEST\_TRAN\_TS ...

. exportingclusterdefinitions

. exportingtabledefinitions

. exporting referential integrityconstraints

. exportingtriggers

.endtransportabletablespacemetadataexport

Exportterminated successfullywithoutwarnings.

\[oracle@localhost test\_imp\_exp]$ ls

exp\_tran\_file.dmp hr\_stu\_add.dmp hr\_stu\_add.log imp\_by\_spfile

\[oracle@localhost test\_imp\_exp]$ mkdir-p imp\_tran\_file

*--之所以建立一个文件夹是因为模拟是从另外一台主机拷贝过来的，统一放在该目录下*

\[oracle@localhost test\_imp\_exp]$ ls

exp\_tran\_file.dmp hr\_stu\_add.dmp hr\_stu\_add.log imp\_by\_spfile imp\_tran\_file

\[oracle@localhost test\_imp\_exp]$ cp-avf/u01/app/oracle/oradata/jiagulun/test\_tran\_ts

test\_tran\_ts01.dbf test\_tran\_ts\_file.dbf

\[oracle@localhost test\_imp\_exp]$ cp-avf/u01/app/oracle/oradata/jiagulun/test\_tran\_ts\_file.dbf ./imp\_tran\_file/

\`/u01/app/oracle/oradata/jiagulun/test\_tran\_ts\_file.dbf' -&gt; \`./imp\_tran\_file/test\_tran\_ts\_file.dbf'

\[oracle@localhost test\_imp\_exp]$ cd imp\_tran\_file/

\[oracle@localhost imp\_tran\_file]$ ls

exp\_tran\_file.dmp test\_tran\_ts\_file.dbf

\[oracle@localhost imp\_tran\_file]$sqlplus/assysdba

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2118:29:382015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;droptablespacetest\_tran\_tsincludingcontents;*--删除刚刚创建的表空间，因为实际上是在同一个oracle中进行传输表空间的*

Tablespacedropped.

SQL&gt;exit

DisconnectedfromOracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

\[oracle@localhost imp\_tran\_file]$ imp \\'sys/oracle@jiagulun as sysdba\\'tablespaces=test\_tran\_ts transport\_tablespace=yfile=/u01/app/oracle/test\_imp\_exp/imp\_tran\_file/exp\_tran\_file.dmpdatafiles=/u01/app/oracle/test\_imp\_exp/imp\_tran\_file/test\_tran\_ts\_file.dbf

*--导入表空间*

Import:Release11.2.0.1.0-ProductiononWed Jan2118:32:152015

Copyright(c)1982,2009,Oracleand/orits affiliates.Allrights reserved.

Connectedto:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

ExportfilecreatedbyEXPORT:V11.02.00 via conventionalpath

Abouttoimport transportabletablespace(s)metadata...

import doneinZHS16GBKcharactersetandAL16UTF16NCHARcharacterset

. importingSYS's objects into SYS

. importing SYS's objectsintoSYS

Import terminated successfullywithoutwarnings.

\[oracle@localhost imp\_tran\_file]$sqlplus/assysdba

SQL\*Plus:Release11.2.0.1.0 ProductiononWed Jan2118:32:252015

Copyright(c)1982,2009,Oracle.Allrights reserved.

Connectedto:

OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bit Production

WiththePartitioning,OLAP,DataMiningandRealApplication Testing options

SQL&gt;setlinesize10000pagesize10000;

SQL&gt;selectdt.tablespace\_name,dt.block\_size,dt.status,dt.contentsfromdba\_tablespaces dt;

TABLESPACE\_NAME BLOCK\_SIZE STATUSCONTENTS

*------------------------------ ---------- --------- ---------*

SYSTEM8192ONLINEPERMANENT

SYSAUX8192ONLINEPERMANENT

UNDOTBS18192ONLINEUNDO

TEMP8192ONLINETEMPORARY

USERS8192ONLINEPERMANENT

UNDOTBS28192ONLINEUNDO

EXAMPLE8192ONLINEPERMANENT

TESTTS8192ONLINEPERMANENT

TEMP28192ONLINETEMPORARY

TEMP38192ONLINETEMPORARY

TEST\_TRAN\_TS8192READONLYPERMANENT

11rowsselected.

SQL&gt;altertablespaceTEST\_TRAN\_TSread,write;

altertablespaceTEST\_TRAN\_TSread,write

\*

ERRORatline1:

ORA-02142:missingorinvalidALTERTABLESPACEoption

SQL&gt;altertablespaceTEST\_TRAN\_TSreadwrite;*--修改表空间的状态*

Tablespacealtered.

SQL&gt;insertintotest\_tran\_tabvalues(1,'张三');

insertintotest\_tran—n\_tabvalues(1,'张三')

\*

ERRORatline1:

ORA-00942:tableorviewdoesnotexist

SQL&gt;insertintotest\_tran\_tabvalues(1,'zs');

1rowcreated.

SQL&gt;select\*fromtest\_tran\_tab;

IDNAME

*---------- --------------------*

1zs

SQL&gt;

**使用数据泵的方式导入导出：**

* * *

exp/imp的缺点是速度太慢，在大型生产库中尤其明显。从10g开始，oracle设计了数据泵，这是一个服务器端的工

具，它为Oracle数据提供高速并行及大数据的迁移。imp/exp可以在客户端调用，但是expdp/impdp只能在服

务端，因为在使用expdp/impdp以前需要在数据库中创建一个 Directory 。

在expdp进行导出时，先创建了MT表，并把对象的信息插入到MT表，之后进行导出动作；导出完成后，MT表也导

出到转储文件中；导出任务完成后、或者删除了导出任务后，MT表自动删除；如果导出任务异常终止，MT表仍然保留。

expdp也具有四种模式：表、用户、可传输表空间、全库。

**数据泵的导出：**

1，部分的exp中的参数仍然可用，有的不能使用，如index。

2，directory：供转储文件和日志文件使用的目录对象。

3，job\_name：指定的任务的名称。

4，content：指定要导出的数据,其中有效关键字值为: (ALL), DATA\_ONLY和METADATA\_ONLY，当设置content为ALL时,将导出对象定义及其所有数据；

DATA\_ONLY时,只导出对象数据；为METADATA\_ONLY时,只导出对象定义 。

5，reuse\_dumpfiles：如果导出文件已经存在，是否覆盖。

6，compression：压缩导出文件。

7，estimate：指定估算被导出表所占用磁盘空间分方法.默认值是BLOCKS

8， estimate\_only：是否只估算导出占用的磁盘空间，而不进行真正的导出，默认是N。

9，exclude：用于指定执行操作时要排除对象类型或相关对象，用法：EXCLUDE=object\_type\[:name\_clause] \[,….]

10，include：用于指定执行操作时要包含的对象类型或相关对象，用法：INCLUDE=object\_type\[:name\_clause] \[,….]

11，query：导出符合条件的行。

12，attch：连接到现有的作业，可以用在中断导出任务后重新启动导出任务。

**----------------------------------------------------------------**

\[oracle@localhost oracle]$ sqlplus / as sysdba

SQL\*Plus: Release 11.2.0.1.0 Production on Wed Jan 21 20:50:29 2015

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

Connected to:  
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL&gt; create directory test\_impdp\_expdp as '/u01/app/oracle/test\_impdp\_expdp';

Directory created.**--创建目录**

SQL&gt; grant write,read on directory test\_impdp\_expdp to hr;

Grant succeeded.**--给用户赋予权限**

SQL&gt; grant write,read on directory test\_impdp\_expdp to test1;

Grant succeeded.**--给用户赋予权限**

SQL&gt; exit  
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Productio  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
\[oracle@localhost oracle]$ cd test\_impdp\_expdp/  
\[oracle@localhost test\_impdp\_expdp]$expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile  
\--默认是多出用户的所有的对象

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:14:04 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_SCHEMA\_01": hr/\*\*\*\*\*\*\*\*@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfi  
Estimate in progress using BLOCKS method...  
Processing object type SCHEMA\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 768 KB  
Processing object type SCHEMA\_EXPORT/PRE\_SCHEMA/PROCACT\_SCHEMA  
Processing object type SCHEMA\_EXPORT/SEQUENCE/SEQUENCE  
Processing object type SCHEMA\_EXPORT/CLUSTER/CLUSTER  
Processing object type SCHEMA\_EXPORT/CLUSTER/INDEX  
Processing object type SCHEMA\_EXPORT/TABLE/TABLE  
Processing object type SCHEMA\_EXPORT/TABLE/GRANT/OWNER\_GRANT/OBJECT\_GRANT  
Processing object type SCHEMA\_EXPORT/TABLE/INDEX/INDEX  
Processing object type SCHEMA\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type SCHEMA\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type SCHEMA\_EXPORT/TABLE/COMMENT  
Processing object type SCHEMA\_EXPORT/PACKAGE/PACKAGE\_SPEC  
Processing object type SCHEMA\_EXPORT/PROCEDURE/PROCEDURE  
Processing object type SCHEMA\_EXPORT/PACKAGE/COMPILE\_PACKAGE/PACKAGE\_SPEC/ALTER\_PACKAGE\_SPEC  
Processing object type SCHEMA\_EXPORT/PROCEDURE/ALTER\_PROCEDURE  
Processing object type SCHEMA\_EXPORT/VIEW/VIEW  
Processing object type SCHEMA\_EXPORT/PACKAGE/PACKAGE\_BODY  
Processing object type SCHEMA\_EXPORT/TABLE/CONSTRAINT/REF\_CONSTRAINT  
Processing object type SCHEMA\_EXPORT/TABLE/TRIGGER  
Processing object type SCHEMA\_EXPORT/EVENT/TRIGGER  
Processing object type SCHEMA\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
Processing object type SCHEMA\_EXPORT/JOB  
. . exported "HR"."ADDRESS" 5.476 KB 2 rows  
. . exported "HR"."COUNTRIES" 6.367 KB 25 rows  
. . exported "HR"."DEPARTMENTS" 7.007 KB 27 rows  
. . exported "HR"."DEPT" 5.492 KB 3 rows  
. . exported "HR"."DROPPED\_OBJ" 6.367 KB 21 rows  
. . exported "HR"."EMPLOYEES" 16.81 KB 107 rows  
. . exported "HR"."JOBS" 6.992 KB 19 rows  
. . exported "HR"."JOB\_HISTORY" 7.054 KB 10 rows  
. . exported "HR"."LOCATIONS" 8.273 KB 23 rows  
. . exported "HR"."REGIONS" 5.476 KB 4 rows  
. . exported "HR"."STUDENT" 5.937 KB 3 rows  
. . exported "HR"."TEST\_JOB" 24.74 KB 1684 rows  
Master table "HR"."SYS\_EXPORT\_SCHEMA\_01" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.SYS\_EXPORT\_SCHEMA\_01 is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_01.dmp  
Job "HR"."SYS\_EXPORT\_SCHEMA\_01" successfully completed at 22:16:07

\[oracle@localhost test\_impdp\_expdp]$ ls  
export.log test\_exp\_01.dmp

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP TABLES=Sexp\_02.dmp EXCLUDE=INDEX:"=\\'INDEX\_ADDRESS\_NAME\\'"  
LRM-00116: syntax error at 'INDEX:' following '='

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP TABLES=Sexp\_02.dmp EXCLUDE=INDEX:"IN\\'INDEX\_ADDRESS\_NAME\\'"

.**--通过上面的导出你会发现需要对'进行转义,而且是IN关键字**

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:25:09 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_TABLE\_01": hr/\*\*\*\*\*\*\*\*@jiagulun directory=TEST\_IMPDP\_EXPDP TABLES=\_exp\_02.dmp EXCLUDE=INDEX:IN\\'INDEX\_ADDRESS\_NAME\\'  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 128 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."ADDRESS" 5.476 KB 2 rows  
. . exported "HR"."STUDENT" 5.937 KB 3 rows  
Master table "HR"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.SYS\_EXPORT\_TABLE\_01 is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_02.dmp  
Job "HR"."SYS\_EXPORT\_TABLE\_01" successfully completed at 22:25:20

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student,address encryption=dmpfiles=test\_exp\_encrytion\_reuse\_01.dmp  
LRM-00101: unknown parameter name 'dumpfiles'

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student,address encryption=dmpfile=test\_exp\_encrytion\_reuse\_01.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:32:31 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39002: invalid operation  
ORA-39070: Unable to open the log file.  
ORA-39145: directory object parameter must be specified and non-null

**--对于上面的错误是因为没有打开或者不存在encryption wallet所以需要进行下面操作：**

* * *

oracle Wallet的使用（即内部加密技术TDE（Transparent Data Encryption ））

1\. TDE是Oracle10gR2中推出的一个新功能，使用时要保证Oracle版本是在10gR2或者以上

--查看oracle版本：

select * from v$version;

2、创建一个新目录，并指定为Wallet目录

D:\\oracle\\product\\10.2.0\\admin\\ora10\\ora\_wallet

3\. 设置wallet目录，在参数文件sqlnet.ora中（window+f,在你安装盘区查找sqlnet.ora），按照下面的格式加入信息：

ENCRYPTION\_WALLET\_LOCATION=(SOURCE=(METHOD=FILE)

(METHOD\_DATA=(DIRECTORY=D:\\oracle\\product\\10.2.0\\admin\\ora10\\ora\_wallet)))

4\. 创建master key文件，指定wallet密码，使用SYS用户登入系统，建立加密文件

SQL&gt; alter system set encryption key identified by "wallet";

System altered

-- 密码"wallet"不加引号时，后面使用时也不需要用引号

此时在设置的目录下，多出一个Personal Information Exchange类型的文件，相当于我们生成的master key文件。D:\\oracle\\product\\10.2.0\\admin\\ora10\\ora\_wallet\\ewallet.p12

5、启动、关闭Wallet

SQL&gt; ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "wallet";

ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "wallet"

ORA-28354: wallet 已经打开

SQL&gt; ALTER SYSTEM SET ENCRYPTION WALLET CLOSE; --关闭

System altered

SQL&gt; ALTER SYSTEM SET ENCRYPTION WALLET OPEN IDENTIFIED BY "wallet"; --打开

System altered

到此，已经成功配置了Wallet，创建了master key。

**--通过上面的创建并且开启encryption wallet后才可以进行如下**

\[oracle@localhost wallet]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPDP\_EXPDP dumpfile=test\_exp\_encryption\_1.dmp encryption=data\_only

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:57:01 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_TABLE\_01": hr/\*\*\*\*\*\*\*\*@jiagulun tables=student directory=TEST\_IMPDP\_EXPDP dumpfile=test\_exp\_encryption\_1.dmp encryption=data\_only  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 64 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."STUDENT" 5.945 KB 3 rows  
Master table "HR"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.SYS\_EXPORT\_TABLE\_01 is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_encryption\_1.dmp  
Job "HR"."SYS\_EXPORT\_TABLE\_01" successfully completed at 23:57:08

* * *

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student compression=data\_onlreuse\_dumpfiles=y dumpfile=test\_exp\_01.dmp**--reuse\_dumpfiles表示可以覆盖原文件**

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:41:57 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_TABLE\_01": hr/\*\*\*\*\*\*\*\*@jiagulun tables=student compression=data\_on reuse\_dumpfiles=y dumpfile=test\_exp\_01.dmp  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 64 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."STUDENT" 4.914 KB 3 rows  
Master table "HR"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.SYS\_EXPORT\_TABLE\_01 is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_01.dmp  
Job "HR"."SYS\_EXPORT\_TABLE\_01" successfully completed at 22:42:02

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPDP\_EXPDP  
EXCLUDE=CONSTRAINT:IN\\'PK\_PRIMARY\\'" dumpfile=test\_exp\_jobname.dmp job\_name=test\_exp\_jobname

**--需要转义和大写**

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:56:23 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."TEST\_EXP\_JOBNAME": hr/\*\*\*\*\*\*\*\*@jiagulun tables=student directory=TEST\_IMPDP\_EK\_PRIMARY\\' dumpfile=test\_exp\_jobname.dmp job\_name=test\_exp\_jobname  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 64 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."STUDENT" 5.937 KB 3 rows  
Master table "HR"."TEST\_EXP\_JOBNAME" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.TEST\_EXP\_JOBNAME is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_jobname.dmp  
Job "HR"."TEST\_EXP\_JOBNAME" successfully completed at 22:56:28

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPIN\\'PK\_PRIMARY\\'" dumpfile=test\_exp\_jobname.dmp job\_name=test\_exp\_jobname

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 22:57:02 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39000: bad dump file specification  
ORA-31641: unable to create dump file "/u01/app/oracle/test\_impdp\_expdp/test\_exp\_jobname.dmp"  
ORA-27038: created file already exists  
Additional information: 1

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPIN\\'PK\_PRIMARY\\'" dumpfile=test\_exp\_jobname.dmp job\_name=test\_exp\_jobname REUSE\_DUMPFILES=Y

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:16:05 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."TEST\_EXP\_JOBNAME": hr/\*\*\*\*\*\*\*\*@jiagulun tables=student directory=TEST\_IMPDP\_EK\_PRIMARY\\' dumpfile=test\_exp\_jobname.dmp job\_name=test\_exp\_jobname REUSE\_DUMPFILES=Y  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 64 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."STUDENT" 5.937 KB 3 rows  
Master table "HR"."TEST\_EXP\_JOBNAME" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.TEST\_EXP\_JOBNAME is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_jobname.dmp  
Job "HR"."TEST\_EXP\_JOBNAME" successfully completed at 23:16:19

\[oracle@localhost test\_impdp\_expdp]$ exp hr/hr@jiagulun TABLES=STUDENT DIRECTORY=test\_impdp\_etion.dmp  
LRM-00101: unknown parameter name 'DIRECTORY'

EXP-00019: failed to process parameters, type 'EXP HELP=Y' for help  
EXP-00000: Export terminated unsuccessfully  
\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP id &lt;2" dumpfile=test\_exp\_query.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:17:57 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP id &lt;2" dumpfile=test\_exp\_query.dmp reuse\_dumpfile=y  
LRM-00101: unknown parameter name 'reuse\_dumpfile'

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP id &lt;2" dumpfile=test\_exp\_query.dmp reuse\_dumpfiles=y

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:18:28 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP id &lt;2" dumpfile=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:18:56 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP query=s=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:19:11 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP query=s=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:19:37 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$  
\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP query=se=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:21:12 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP id \\&lt;2" dumpfile=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:21:41 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMP dumpfile=test\_exp\_query\_1.dmp

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:26:04 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPery\_1.dmp query=STUDENT:"WHERE ID &lt; 2"

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:28:16 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPery\_1.dmp query=STUDENT:"WHERE ID \\&lt; 2"

Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:28:23 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
ORA-39001: invalid argument value  
ORA-39035: Data filter SUBQUERY has already been specified.

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun tables=student directory=TEST\_IMPery\_1.dmp query=STUDENT:\\"WHERE ID \\&lt; 2\\"  
**--通过上面的错误可以知道符号需要被转义和query的使用方式**  
Export: Release 11.2.0.1.0 - Production on Wed Jan 21 23:28:30 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_TABLE\_01": hr/\*\*\*\*\*\*\*\*@jiagulun tables=student directory=TEST\_IMPDry\_1.dmp query=STUDENT:"WHERE ID &lt; 2"  
Estimate in progress using BLOCKS method...  
Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
Total estimation using BLOCKS method: 64 KB  
Processing object type TABLE\_EXPORT/TABLE/TABLE  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX  
Processing object type TABLE\_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  
Processing object type TABLE\_EXPORT/TABLE/INDEX/STATISTICS/INDEX\_STATISTICS  
Processing object type TABLE\_EXPORT/TABLE/STATISTICS/TABLE\_STATISTICS  
. . exported "HR"."STUDENT" 5.906 KB 1 rows  
Master table "HR"."SYS\_EXPORT\_TABLE\_01" successfully loaded/unloaded  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
Dump file set for HR.SYS\_EXPORT\_TABLE\_01 is:  
/u01/app/oracle/test\_impdp\_expdp/test\_exp\_query\_1.dmp  
Job "HR"."SYS\_EXPORT\_TABLE\_01" successfully completed at 23:28:40

WRL\_TYPE  
\--------------------  
WRL\_PARAMETER  
\--------------------------------------------------------------------------------  
STATUS  
\------------------  
file  
/u01/app/oracle/admin/jiagulun/wallet  
CLOSED

**数据泵的导入：**

1，content：指定要加载的数据, 其中有效关键字值为: (ALL), DATA\_ONLY 和 METADATA\_ONLY，当设置content为ALL 时,将加载对象定义及其所有数据；

DATA\_ONLY时,只加载对象数据；为METADATA\_ONLY时,只加载对象定义 。

2，estimate：估算所占用磁盘空间分方法.默认值是BLOCKS

3，remap\_schema：用于将对象从一个用户下导入到另一个用户下。

4，remap\_tablespace：用于将对象从一个表空间下导入到另一个表空间下。

5，remap\_datafile：用于在不同文件系统的平台间，切换数据文件路径。

remap\_achema:导入

* * *

\[oracle@localhost test\_impdp\_expdp]$ expdp hr/hr@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_01.dmp schemas= hr

Export: Release 11.2.0.1.0 - Production on Thu Jan 22 00:59:42 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "HR"."SYS\_EXPORT\_SCHEMA\_01": hr/\*\*\*\*\*\*\*\*@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_01.dmp schemas=  
Estimate in progress using BLOCKS method...

\[oracle@localhost test\_impdp\_expdp]**$ impdp test1/test1@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_01.dmp**REMAP\_SCHEMA=HR:TEST1

Import: Release 11.2.0.1.0 - Production on Thu Jan 22 01:10:11 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Master table "TEST1"."SYS\_IMPORT\_FULL\_01" successfully loaded/unloaded  
Starting "TEST1"."SYS\_IMPORT\_FULL\_01": test1/\*\*\*\*\*\*\*\*@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_01.dmp REMAP\_SCHEMA=HR:TEST1  
Processing object type SCHEMA\_EXPORT/PRE\_SCHEMA/PROCACT\_SCHEMA

remap\_tablespace导入

* * *

**通过remap\_tablespace来变换表所属表空间：**

SQL&gt; select segment\_name,segment\_type,tablespace\_name from user\_extents ;

SEGMENT\_NAME SEGMENT\_TYPE TABLESPACE\_NAME

\-------------------------------------------------------------------------------- ------------------ ------------------------------

REGIONS TABLE EXAMPLE

LOCATIONS TABLE EXAMPLE

DEPARTMENTS TABLE EXAMPLE

JOBS TABLE EXAMPLE

EMPLOYEES TABLE EXAMPLE

JOB\_HISTORY TABLE EXAMPLE

DEPT TABLE USERS

DROPPED\_OBJ TABLE USERS

TEST\_JOB TABLE USERS

STUDENT TABLE TEST\_TRAN\_TS

ADDRESS TABLE TEST\_TRAN\_TS

\[oracle@localhost test\_impdp\_expdp]$expdp \\'sys/oracle@jiagulun as sysdba\\' directory=test\_impdp\_expdp dumpfile=exp\_04.dmp tablespaces=users--导出表空间

Export: Release 11.2.0.1.0 - Production on Thu Jan 22 01:20:04 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Starting "SYS"."SYS\_EXPORT\_TABLESPACE\_01": "sys/\*\*\*\*\*\*\*\*@jiagulun AS SYSDBA" directory=test\_impdp\_expdp dumpfile=exp\_02.dmp tablespaces=users  
Estimate in progress using BLOCKS method...

SQL&gt; drop table student purge;

Table dropped.--之所以要先删除再导入表是因为在一个数据库中一个用户中的对象是唯一的，所以先删除再导入

SQL&gt; drop table address purge;

Table dropped.

SQL&gt; commit;

Commit complete.

\[oracle@localhost test\_impdp\_expdp]$impdp \\'sys/oracle@jiagulun as sysdba\\' directory=test\_impdp\_expdp dumpfile=exp\_04.dmp REMAP\_TABLESPACE=test\_tran\_ts：users--导入表空间到test\_tran\_ts

Import: Release 11.2.0.1.0 - Production on Thu Jan 22 01:28:45 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Master table "SYS"."SYS\_IMPORT\_FULL\_01" successfully loaded/unloaded  
Starting "SYS"."SYS\_IMPORT\_FULL\_01": "sys/\*\*\*\*\*\*\*\*@jiagulun AS SYSDBA" directory=test\_impdp\_expdp dumpfile=exp\_02.dmp REMAP\_TABLESPACE=users:test\_tran\_ts  
Processing object type TABLE\_EXPORT/TABLE/TABLE

Processing object type TABLE\_EXPORT/TABLE/TABLE\_DATA  
. . imported "HR"."ADDRESS" 5.476 KB 2 rows  
. . imported "HR"."STUDENT" 5.937 KB 3 rows  
Processing object type TABLE\_EXPORT/TABLE/INDEX/INDEX

SQL&gt; select segment\_name,segment\_type,tablespace\_name from user\_extents ;

SEGMENT\_NAME SEGMENT\_TYPE TABLESPACE\_NAME

\-------------------------------------------------------------------------------- ------------------ ------------------------------

REGIONS TABLE EXAMPLE

LOCATIONS TABLE EXAMPLE

DEPARTMENTS TABLE EXAMPLE

JOBS TABLE EXAMPLE

EMPLOYEES TABLE EXAMPLE

JOB\_HISTORY TABLE EXAMPLE

STUDENT TABLE USERS

ADDRESS TABLE USERS

**为了把用户按表空间归类，需要把用户所有的当前数据转移到另一个表空间里，那么可以使用impdp的remap\_tablespace参数。下面就这一内容进行实验。**

SQL&gt; select du.username,du.default\_tablespace,du.temporary\_tablespace from dba\_users du where du.username='HR';

USERNAME DEFAULT\_TABLESPACE TEMPORARY\_TABLESPACE

\------------------------------ ------------------------------ ------------------------------

HR USERS TEMP2

SQL&gt; select segment\_name,segment\_type,tablespace\_name from user\_extents where rownum &lt; 10;

SEGMENT\_NAME SEGMENT\_TYPE TABLESPACE\_NAME

\-------------------------------------------------------------------------------- ------------------ ------------------------------

REGIONS TABLE EXAMPLE

LOCATIONS TABLE EXAMPLE

DEPARTMENTS TABLE EXAMPLE

JOBS TABLE EXAMPLE

EMPLOYEES TABLE EXAMPLE

JOB\_HISTORY TABLE EXAMPLE

STUDENT TABLE USERS

ADDRESS TABLE USERS

DEPT TABLE USERS

9 rows selected

SQL&gt;

\[oracle@localhost test\_impdp\_expdp]$ expdp system/oracle@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_03.dmp schemas=hr

Export: Release 11.2.0.1.0 - Production on Thu Jan 22 02:22:28 2015  
\--导出hr用户对象信息，使用system导出的更加的全  
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

\[oracle@localhost test\_impdp\_expdp]$ impdp system/oracle@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_03.dmp remap\_tablespace=users:test\_tran\_ts--导入hr用户中是users表空间的数据到test\_tran\_ts表空间中

Import: Release 11.2.0.1.0 - Production on Thu Jan 22 05:33:10 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

SQL&gt; select segment\_name,segment\_type,tablespace\_name from user\_extents where rownum &lt; 10;

SEGMENT\_NAME SEGMENT\_TYPE TABLESPACE\_NAME

\-------------------------------------------------------------------------------- ------------------ ------------------------------

REGIONS TABLE EXAMPLE

LOCATIONS TABLE EXAMPLE

DEPARTMENTS TABLE EXAMPLE

JOBS TABLE EXAMPLE

EMPLOYEES TABLE EXAMPLE

JOB\_HISTORY TABLE EXAMPLE

STUDENT TABLE USERS

ADDRESS TABLE USERS

DEPT TABLE USERS

9 rows selected

--会发现表所在表空间并没有变化，是因为原来的已经存在不会覆盖

SQL&gt; select du.username,du.default\_tablespace,du.temporary\_tablespace from dba\_users du where du.username='HR';

USERNAME DEFAULT\_TABLESPACE TEMPORARY\_TABLESPACE

\------------------------------ ------------------------------ ------------------------------

HR USERS TEMP2

注意：经过导入后，用户test\_user的缺省表空间被改成了remap\_tablespace的目的表空间，但是这里没有变化也是因为已经存在了。

把表和用户删除了，就会发现他们的表空间变额

SQL&gt; drop table student;

Table dropped.

SQL&gt; drop table address;

Table dropped.

SQL&gt; commit;

Commit complete.

SQL&gt; purge recyclebin  
2 ;

\[oracle@localhost test\_impdp\_expdp]$impdp system/oracle@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_03.dmp remap\_tablespace=users:test\_tran\_ts

Import: Release 11.2.0.1.0 - Production on Thu Jan 22 05:48:49 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
Master table "SYSTEM"."SYS\_IMPORT\_FULL\_01" successfully loaded/unloaded  
Starting "SYSTEM"."SYS\_IMPORT\_FULL\_01": system/\*\*\*\*\*\*\*\*@jiagulun directory=TEST\_IMPDP\_EXPDP dumpfile=exp\_03.dmp remap\_tablespace=users:test\_tran\_ts  
Processing object type SCHEMA\_EXPORT/USER  
ORA-31684: Object type USER:"HR" already exists--由于存在所以直接跳过  
Processing object type SCHEMA\_EXPORT/SYSTEM\_GRANT  
Processing object type SCHEMA\_EXPORT/ROLE\_GRANT  
Processing object type SCHEMA\_EXPORT/DEFAULT\_ROLE  
Processing object type SCHEMA\_EXPORT/PRE\_SCHEMA/PROCACT\_SCHEMA  
Processing object type SCHEMA\_EXPORT/SEQUENCE/SEQUENCE  
ORA-31684: Object type SEQUENCE:"HR"."EMPLOYEES\_SEQ" already exists  
ORA-31684: Object type SEQUENCE:"HR"."DEPARTMENTS\_SEQ" already exists  
ORA-31684: Object type SEQUENCE:"HR"."LOCATIONS\_SEQ" already exists  
Processing object type SCHEMA\_EXPORT/CLUSTER/CLUSTER  
ORA-31684: Object type CLUSTER:"HR"."CLUSTER1" already exists  
Processing object type SCHEMA\_EXPORT/CLUSTER/INDEX  
ORA-39111: Dependent object type INDEX:"HR"."CLUSTER\_INDEX" skipped, base object type CLUSTER:"HR"."CLUSTER1" already exists  
Processing object type SCHEMA\_EXPORT/TABLE/TABLE  
ORA-39151: Table "HR"."COUNTRIES" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."REGIONS" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."LOCATIONS" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."DEPARTMENTS" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."JOBS" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."EMPLOYEES" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."JOB\_HISTORY" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."DEPT" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."DROPPED\_OBJ" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
ORA-39151: Table "HR"."TEST\_JOB" exists. All dependent metadata and data will be skipped due to table\_exists\_action of skip  
Processing object type SCHEMA\_EXPORT/TABLE/TABLE\_DATA  
. . imported "HR"."ADDRESS" 5.476 KB 2 rows  
. . imported "HR"."STUDENT" 5.937 KB 3 rows  
Processing object type SCHEMA\_EXPORT/TABLE/GRANT/OWNER\_GRANT/OBJECT\_GRANT  
.. . . . . . . . ..

SQL&gt; select segment\_name,segment\_type,tablespace\_name from user\_extents ;

SEGMENT\_NAME SEGMENT\_TYPE TABLESPACE\_NAME

\-------------------------------------------------------------------------------- ------------------ ------------------------------

STUDENT TABLE TEST\_TRAN\_TS

ADDRESS TABLE TEST\_TRAN\_TS

CLUSTER1 CLUSTER USERS

--你会发现他们的表空间变化了。

***注意：一个用户对象是唯一的，即使在不同的表空间中也是一样的***

SQL&gt; create table test1(id number);--默认是使用sys

Table created.

SQL&gt; create table test1(id number) tablespace test\_tran\_ts;--使用test\_tran\_ts  
create table test1(id number) tablespace test\_tran\_ts  
\*  
ERROR at line 1:  
ORA-00955: name is already used by an existing object

SQL&gt;