由于导出和导入时需要关注索引是否被导入,进行实验。
本实验主要目的是理解content的两个参数项:date_only和metadata_only,其中涉及include。
1.分别使用以下三种方式导出分区表ACTIVE_PARTITION的数据、元数据
expdp scott/scott directory=HOME_O dumpfile=scott_expdp1.dmp logfile=scott_expdp1.log tables=ACTIVE_PARTITION
expdp scott/scott directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_expdp2.log tables=ACTIVE_PARTITION content=data_only
expdp scott/scott directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_expdp3.log tables=ACTIVE_PARTITION content=metadata_only
[oracle@ogg2 ~]$ expdp scott/scott directory=HOME_O dumpfile=scott_expdp1.dmp logfile=scott_expdp1.log tables=ACTIVE_PARTITION
Export: Release 11.2.0.1.0 - Production on Mon Mar 9 14:45:17 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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_02": scott/******** directory=HOME_O dumpfile=scott_expdp1.dmp logfile=scott_expdp1.log tables=ACTIVE_PARTITION
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8.5 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
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 "SCOTT"."ACTIVE_PARTITION":"P5" 5.896 MB 60275 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P4" 459.5 KB 5033 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P3" 385.1 KB 3834 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P1" 280.8 KB 2847 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P2" 31.52 KB 226 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_02" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_02 is:
/home/oracle/scott_expdp1.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_02" successfully completed at 14:45:28
[oracle@ogg2 ~]$ expdp scott/scott directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_expdp2.log tables=ACTIVE_PARTITION content=data_only
Export: Release 11.2.0.1.0 - Production on Mon Mar 9 14:45: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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_02": scott/******** directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_expdp2.log tables=ACTIVE_PARTITION content=data_only
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8.5 MB
. . exported "SCOTT"."ACTIVE_PARTITION":"P5" 5.896 MB 60275 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P4" 459.5 KB 5033 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P3" 385.1 KB 3834 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P1" 280.8 KB 2847 rows
. . exported "SCOTT"."ACTIVE_PARTITION":"P2" 31.52 KB 226 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_02" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_02 is:
/home/oracle/scott_expdp2.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_02" successfully completed at 14:45:47
[oracle@ogg2 ~]$ expdp scott/scott directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_expdp3.log tables=ACTIVE_PARTITION content=metadata_only
Export: Release 11.2.0.1.0 - Production on Mon Mar 9 14:45: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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_02": scott/******** directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_expdp3.log tables=ACTIVE_PARTITION content=metadata_only
Processing object type TABLE_EXPORT/TABLE/TABLE
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
Master table "SCOTT"."SYS_EXPORT_TABLE_02" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_02 is:
/home/oracle/scott_expdp3.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_02" successfully completed at 14:46:06
2.新建用户scott2,授予权限(实验中粗糙授权)
SQL> create user scott2 identified by scott2;
User created.
SQL> grant dba to scott2;
Grant succeeded.
SQL> grant connect ,resource to scott2;
Grant succeeded.
3.使用第一种方式导出的数据,导入时索引和数据都会被导入
[oracle@ogg2 ~]$ impdp scott2/scott2 directory=HOME_O dumpfile=scott_expdp1.dmp logfile=scott_impdp1.log remap_schema=scott:scott2
Import: Release 11.2.0.1.0 - Production on Mon Mar 9 14:49:55 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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT2"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT2"."SYS_IMPORT_FULL_01": scott2/******** directory=HOME_O dumpfile=scott_expdp1.dmp logfile=scott_impdp1.log remap_schema=scott:scott2
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT2"."ACTIVE_PARTITION":"P5" 5.896 MB 60275 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P4" 459.5 KB 5033 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P3" 385.1 KB 3834 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P1" 280.8 KB 2847 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P2" 31.52 KB 226 rows
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
Job "SCOTT2"."SYS_IMPORT_FULL_01" successfully completed at 14:53:28
SQL> set lines 200
SQL> select index_name,owner,index_type from dba_indexes where table_name='ACTIVE_PARTITION';
INDEX_NAME OWNER INDEX_TYPE
------------------------------ ------------------------------ ---------------------------
SYS_C0011466 SCOTT2 NORMAL
SYS_C0011431 SCOTT NORMAL
SQL> select TABLE_OWNER,TABLE_NAME,partition_name from dba_tab_partitions where table_name='ACTIVE_PARTITION' and table_owner='SCOTT2';
TABLE_OWNER TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------ ------------------------------
SCOTT2 ACTIVE_PARTITION P1
SCOTT2 ACTIVE_PARTITION P2
SCOTT2 ACTIVE_PARTITION P3
SCOTT2 ACTIVE_PARTITION P4
SCOTT2 ACTIVE_PARTITION P5
SQL> drop table scott2.active_partition;
Table dropped.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
4.使用第二种方式导入,由于没有表结构,会报错
[oracle@ogg2 ~]$ impdp scott2/scott2 directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_impdp2.log remap_schema=scott:scott2
Import: Release 11.2.0.1.0 - Production on Mon Mar 9 15:00: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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT2"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SCOTT2"."SYS_IMPORT_FULL_01": scott2/******** directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_impdp2.log remap_schema=scott:scott2
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.UPATE_TD_ROW_IMP [15]
TABLE_DATA:"SCOTT2"."ACTIVE_PARTITION":"P1"
ORA-31603: object "ACTIVE_PARTITION" of type TABLE not found in schema "SCOTT2"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.KUPW$WORKER", line 8170
----- PL/SQL Call Stack -----
object line object
handle number name
0x43301f90 19028 package body SYS.KUPW$WORKER
0x43301f90 8191 package body SYS.KUPW$WORKER
0x43301f90 18608 package body SYS.KUPW$WORKER
0x43301f90 4104 package body SYS.KUPW$WORKER
0x43301f90 8874 package body SYS.KUPW$WORKER
0x43301f90 1651 package body SYS.KUPW$WORKER
0x455bc588 2 anonymous block
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.UPATE_TD_ROW_IMP [15]
TABLE_DATA:"SCOTT2"."ACTIVE_PARTITION":"P1"
ORA-31603: object "ACTIVE_PARTITION" of type TABLE not found in schema "SCOTT2"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.KUPW$WORKER", line 8170
----- PL/SQL Call Stack -----
object line object
handle number name
0x43301f90 19028 package body SYS.KUPW$WORKER
0x43301f90 8191 package body SYS.KUPW$WORKER
0x43301f90 18608 package body SYS.KUPW$WORKER
0x43301f90 4104 package body SYS.KUPW$WORKER
0x43301f90 8874 package body SYS.KUPW$WORKER
0x43301f90 1651 package body SYS.KUPW$WORKER
0x455bc588 2 anonymous block
Job "SCOTT2"."SYS_IMPORT_FULL_01" stopped due to fatal error at 15:00:36
5.content=metadata_only表示只导入结构,不导入数据;而content=data_only是只导入数据。两者依次导入则等同于不加该参数。
如果需要在导入时排除索引,可以添加其他参数。
下面使用exclude=index是无效的,从导入日志可以看到导入了CONSTRAINT,因此主键索引、唯一键索引都被导入了
[oracle@ogg2 ~]$ impdp scott2/scott2 directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_impdp3.log remap_schema=scott:scott2 exclude=index
Import: Release 11.2.0.1.0 - Production on Mon Mar 9 15:14: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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT2"."SYS_IMPORT_FULL_02" successfully loaded/unloaded
Starting "SCOTT2"."SYS_IMPORT_FULL_02": scott2/******** directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_impdp3.log remap_schema=scott:scott2 exclude=index
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SCOTT2"."SYS_IMPORT_FULL_02" successfully completed at 15:14:24
[oracle@ogg2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 9 15:14:36 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select index_name,owner,index_type from dba_indexes where table_name='ACTIVE_PARTITION';
INDEX_NAME OWNER
------------------------------ ------------------------------
INDEX_TYPE
---------------------------
SYS_C0011477 SCOTT2
NORMAL
SYS_C0011431 SCOTT
NORMAL
SQL> drop table scott2.ACTIVE_PARTITION;
Table dropped.
正确的方法是导入时指定include=table/table,然后导入数据
[oracle@ogg2 ~]$ impdp scott2/scott2 directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_impdp3.log remap_schema=scott:scott2 include=table/table
Import: Release 11.2.0.1.0 - Production on Mon Mar 9 15:20: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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT2"."SYS_IMPORT_FULL_02" successfully loaded/unloaded
Starting "SCOTT2"."SYS_IMPORT_FULL_02": scott2/******** directory=HOME_O dumpfile=scott_expdp3.dmp logfile=scott_impdp3.log remap_schema=scott:scott2 include=table/table
Processing object type TABLE_EXPORT/TABLE/TABLE
Job "SCOTT2"."SYS_IMPORT_FULL_02" successfully completed at 15:20:18
[oracle@ogg2 ~]$ impdp scott2/scott2 directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_impdp2.log remap_schema=scott:scott2
Import: Release 11.2.0.1.0 - Production on Mon Mar 9 15:20:53 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 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT2"."SYS_IMPORT_FULL_02" successfully loaded/unloaded
Starting "SCOTT2"."SYS_IMPORT_FULL_02": scott2/******** directory=HOME_O dumpfile=scott_expdp2.dmp logfile=scott_impdp2.log remap_schema=scott:scott2
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT2"."ACTIVE_PARTITION":"P5" 5.896 MB 60275 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P4" 459.5 KB 5033 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P3" 385.1 KB 3834 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P1" 280.8 KB 2847 rows
. . imported "SCOTT2"."ACTIVE_PARTITION":"P2" 31.52 KB 226 rows
Job "SCOTT2"."SYS_IMPORT_FULL_02" successfully completed at 15:21:04
[oracle@ogg2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 9 15:21:10 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set lines 200
SQL> select index_name,owner,index_type from dba_indexes where table_name='ACTIVE_PARTITION';
INDEX_NAME OWNER INDEX_TYPE
------------------------------ ------------------------------ ---------------------------
SYS_C0011431 SCOTT NORMAL
注意,这时只看到了scott下的索引,scott2下是没导入的。
include参数的格式为:
INCLUDE = object_type[:name_clause] [, ...]
其中object_type指定了可以包含的对象类型,可以通过以下视图查看:
全局 select OBJECT_PATH?from DATABASE_EXPORT_OBJECTS;
用户级 select OBJECT_PATH?from SCHEMA_EXPORT_OBJECTS ;
表级 select OBJECT_PATH?from TABLE_EXPORT_OBJECTS ;
name_clause是可选的,可以用双引号包含具体的对象名称。
根据官方文档建议(utility 87页):最好使用参数文件来包含此类需要添加较多双引号的参数。
如:
hr.par文件内容为:
SCHEMAS=HR
DUMPFILE=expinclude.dmp
DIRECTORY=dpump_dir1
LOGFILE=expinclude.log
INCLUDE=TABLE:"IN ('EMPLOYEES', 'DEPARTMENTS')"
INCLUDE=PROCEDURE
INCLUDE=INDEX:"LIKE 'EMP%'"
指定的导出(导入)语句为:
expdp hr PARFILE=hr.par
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26451536/viewspace-1623690/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26451536/viewspace-1623690/
本文通过实验展示了如何在Oracle环境下使用expdp和impdp命令进行分区表数据的导出与导入,包括理解content参数(data_only, metadata_only)的作用,以及在导入时排除索引的方法。

1523

被折叠的 条评论
为什么被折叠?



