导入导出 Oracle 分区表数据
--****************************
--?導(dǎo)入導(dǎo)出?Oracle?分區(qū)表數(shù)據(jù)
--****************************
???
????導(dǎo)入導(dǎo)入Oracle?分區(qū)表數(shù)據(jù)是Oracle DBA?經(jīng)常完成的任務(wù)之一。分區(qū)表的導(dǎo)入導(dǎo)出同樣普通表的導(dǎo)入導(dǎo)出方式,只不過導(dǎo)入導(dǎo)出需要考
慮到分區(qū)的特殊性,如分區(qū)索引,將分區(qū)遷移到普通表,或使用原始分區(qū)表導(dǎo)入到新的分區(qū)表。下面將描述使用imp/exp,impdp/expdp導(dǎo)入導(dǎo)出
分區(qū)表數(shù)據(jù)。
?
????有關(guān)分區(qū)表的特性請(qǐng)參考:?
????????Oracle?分區(qū)表
????????SQL server 2005?切換分區(qū)表
????????SQL server 2005?基于已存在的表創(chuàng)建分區(qū)
?
????有關(guān)導(dǎo)入導(dǎo)出工具請(qǐng)參考:
????????數(shù)據(jù)泵EXPDP?導(dǎo)出工具的使用
????????數(shù)據(jù)泵IMPDP?導(dǎo)入工具的使用
?
????有關(guān)導(dǎo)入導(dǎo)出的官方文檔請(qǐng)參考:
????????Original Export and Import?????
?
一、分區(qū)級(jí)別的導(dǎo)入導(dǎo)出
????可以導(dǎo)出一個(gè)或多個(gè)分區(qū),也可以導(dǎo)出所有分區(qū)(即整個(gè)表)。
????可以導(dǎo)入所有分區(qū)(即整個(gè)表),一個(gè)或多個(gè)分區(qū)以及子分區(qū)。
????對(duì)于已經(jīng)存在數(shù)據(jù)的表,使用imp導(dǎo)入時(shí)需要使用參數(shù)IGNORE=y,而使用impdp,加table_exists_action=append | replace?參數(shù)。
?
二、創(chuàng)建演示環(huán)境
????1.查看當(dāng)前數(shù)據(jù)庫(kù)的版本
????????SQL>?select?*?from?v$version?where?rownum?<?2;
?
????????BANNER
????????--------------------------------------------------------------------------------
????????Oracle?Database?11g Enterprise Edition Release 11.2.0.1.0?-?Production
?
????2.創(chuàng)建一個(gè)分區(qū)表
????????SQL>?alter?session?set?nls_date_format='yyyy-mm-dd';
?
????????SQL>?CREATE?TABLE?tb_pt?(
????????sal_date???DATE?NOT?NULL,
????????sal_id NUMBER?NOT?NULL,
????????sal_row????NUMBER(12)?NOT?NULL)
????????partition?by?range(sal_date)
????????(
????????partition?sal_11?values?less than(to_date('2012-01-01','YYYY-MM-DD'))?,
????????partition?sal_12?values?less than(to_date('2013-01-01','YYYY-MM-DD'))?,
????????partition?sal_13?values?less than(to_date('2014-01-01','YYYY-MM-DD'))?,
????????partition?sal_14?values?less than(to_date('2015-01-01','YYYY-MM-DD'))?,
????????partition?sal_15?values?less than(to_date('2016-01-01','YYYY-MM-DD'))?,
????????partition?sal_16?values?less than(to_date('2017-01-01','YYYY-MM-DD'))?,
????????partition?sal_other?values?less than?(maxvalue)
????????)?nologging;
?
????3.創(chuàng)建一個(gè)唯一索引
????????CREATE?UNIQUE?INDEX?tb_pt_ind1
????????ON?tb_pt(sal_date)?nologging;
???
????4.為分區(qū)表生成數(shù)據(jù)
????????SQL>?INSERT?INTO?tb_pt
????????SELECT?TRUNC(SYSDATE)+ROWNUM,?dbms_random.random,?ROWNUM
????????FROM?dual
????????CONNECT?BY?LEVEL<=5000;
?
????????SQL>?commit;
?
????????SQL>?select?count(1)?from?tb_pt?partition(sal_11);
?
??????????COUNT(1)
????????----------
???????????????300
?
????????SQL>?select?count(1)?from?tb_pt?partition(sal_other);
?
??????????COUNT(1)
????????----------
??????????????2873
?
????????SQL>?select?*?from?tb_pt?partition(sal_12)?where?rownum?<?3;
?
????????SAL_DATE??????SAL_ID????SAL_ROW
????????--------- ---------- ----------
????????01-JAN-12?-1.356E+09????????301
????????02-JAN-12?-761530183????????302
?
三、使用exp/imp導(dǎo)出導(dǎo)入分區(qū)表數(shù)據(jù)
????1.導(dǎo)出整個(gè)分區(qū)表
???
????????[oracle@node1 ~]$?exp scott/tiger file='/u02/dmp/tb_pt.dmp' log='/u02/dmp/tb_pt.log' tables=tb_pt
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:52:18 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export done in US7ASCII character set and AL16UTF16 NCHAR character set
????????server uses ZHS16GBK character set (possible charset conversion)
????????About to export specified tables via Conventional Path ...
????????. . exporting table??????????????????????????TB_PT
????????. . exporting partition?????????????????????????SAL_11????????300 rows exported
????????. . exporting partition?????????????????????????SAL_12????????366 rows exported
????????. . exporting partition?????????????????????????SAL_13????????365 rows exported
????????. . exporting partition?????????????????????????SAL_14????????365 rows exported
????????. . exporting partition?????????????????????????SAL_15????????365 rows exported
????????. . exporting partition?????????????????????????SAL_16????????366 rows exported
????????. . exporting partition??????????????????????SAL_OTHER???????2873 rows exported
????????EXP-00091: Exporting questionable statistics.
????????EXP-00091: Exporting questionable statistics.
????????Export terminated successfully with warnings.
???????
????????[oracle@node1 ~]$ oerr exp 00091
????????00091, 00000, "Exporting questionable statistics."
????????// *Cause:??Export was able export statistics, but the statistics may not be
????????//??????????usuable. The statistics are questionable because one or more of
????????//??????????the following happened during export: a row error occurred, client
????????//??????????character set or NCHARSET does not match with the server, a query
????????//??????????clause was specified on export, only certain partitions or
????????//??????????subpartitions were exported, or a fatal error occurred while
????????//??????????processing a table.
????????// *Action: To export non-questionable statistics, change the client character
????????//??????????set or NCHARSET to match the server, export with no query clause,
????????//??????????export complete tables. If desired, import parameters can be
????????//??????????supplied so that only non-questionable statistics will be imported,
????????//??????????and all questionable statistics will be recalculated.
?
????????在上面的導(dǎo)出中出現(xiàn)了錯(cuò)誤提示,即EXP-00091,該錯(cuò)誤表明exp工具所在的環(huán)境變量中的NLS_LANG與DB中的NLS_CHARACTERSET不一致
????????盡管該錯(cuò)誤對(duì)最終的數(shù)據(jù)并無影響,但調(diào)整該參數(shù)來避免異常還是有必要的。因此需要將其設(shè)置為一致即可解決上述的錯(cuò)誤提示。
???????
????????SQL>?select?userenv('language')?from?dual;
?
????????USERENV('LANGUAGE')
????????----------------------------------------------------
????????AMERICAN_AMERICA.ZHS16GBK
?
????????[oracle@node1 ~]$ export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'???
?
????????經(jīng)過上述設(shè)置之后再次導(dǎo)出正常,過程略。
?
????2.導(dǎo)出單個(gè)分區(qū)
?
????????[oracle@node1 ~]$?exp scott/tiger file='/u02/dmp/tb_pt_sal_16.dmp' log='/u02/dmp/tb_pt_sal_16.log' tables=tb_pt:sal_16
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:52:38 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
????????About to export specified tables via Conventional Path ...
????????. . exporting table??????????????????????????TB_PT
????????. . exporting partition?????????????????????????SAL_16????????366 rows exported
????????EXP-00091: Exporting questionable statistics.
????????EXP-00091: Exporting questionable statistics.
????????Export terminated successfully with warnings
?
????????在上面的導(dǎo)出過程中再次出現(xiàn)了統(tǒng)計(jì)信息錯(cuò)誤的情況,因此采取了對(duì)該對(duì)象收集統(tǒng)計(jì)信息,但并不能解決該錯(cuò)誤,但在exp命令行中增
????????加statistics=none即可,如下:
????????[oracle@node1 ~]$?exp scott/tiger file='/u02/dmp/tb_pt_sal_16.dmp' log='/u02/dmp/tb_pt_sal_16.log' /
????????> tables=tb_pt:sal_16 statistics=none
?
????????如果要導(dǎo)出多個(gè)分區(qū),則在tables參數(shù)中增加分區(qū)數(shù)。如:tables=(tb_pt:sal_15,tb_pt:sal_16)
?
????3.使用imp工具生成創(chuàng)建分區(qū)表的DDL語句
????????[oracle@node1 ~]$?imp scott/tiger tables=tb_pt indexfile='/u02/dmp/cr_tb_pt.sql' /
????????> file='/u02/dmp/tb_pt.dmp' ignore=y
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:54:38 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export file created by EXPORT:V11.02.00 via conventional path
????????import done in US7ASCII character set and AL16UTF16 NCHAR character set
????????import server uses ZHS16GBK character set (possible charset conversion)
????????. . skipping partition "TB_PT":"SAL_11"??????????????????
????????. . skipping partition "TB_PT":"SAL_12"??????????????????
????????. . skipping partition "TB_PT":"SAL_13"??????????????????
????????. . skipping partition "TB_PT":"SAL_14"??????????????????
????????. . skipping partition "TB_PT":"SAL_15"??????????????????
????????. . skipping partition "TB_PT":"SAL_16"??????????????????
????????. . skipping partition "TB_PT":"SAL_OTHER"???????????????
????????Import terminated successfully without warnings.
?
????4.導(dǎo)入單個(gè)分區(qū)(使用先前備份的單個(gè)分區(qū)導(dǎo)入文件)
????????SQL>?alter?table?tb_pt?truncate?partition?sal_16;???--導(dǎo)入前先將分區(qū)實(shí)現(xiàn)truncate
?
????????Table?truncated.
?
????????SQL>?select?count(1)?from?tb_pt?partition(sal_16);
?
??????????COUNT(1)
????????----------
?????????????????0
?
????????SQL>?ho imp scott/tiger tables=tb_pt:sal_16 file='/u02/dmp/tb_pt_sal_16.dmp' ignore=y
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:55:39 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export file created by EXPORT:V11.02.00 via conventional path
????????import done in US7ASCII character set and AL16UTF16 NCHAR character set
????????import server uses ZHS16GBK character set (possible charset conversion)
????????. importing SCOTT's objects into SCOTT
????????. importing SCOTT's objects into SCOTT
????????. . importing partition???????????????"TB_PT":"SAL_16"
????????IMP-00058: ORACLE error 1502 encountered
????????ORA-01502: index 'SCOTT.TB_PT_IND1' or partition of such index is in unusable state
????????Import terminated successfully with warnings.
?
????????收到了ORA-01502錯(cuò)誤,下面查看索引的狀態(tài),并對(duì)其重建索引后再執(zhí)行導(dǎo)入
????????SQL>?select?index_name?,status?from?dba_indexes?where?table_name='TB_PT';??--查看索引的狀態(tài)
?
????????INDEX_NAME?????????????????????STATUS
????????------------------------------ --------
????????TB_PT_IND1?????????????????????UNUSABLE
?
????????SQL>?alter?index?TB_PT_IND1?rebuild?online;????????????????--重建索引
?
????????Index?altered.
?
????????SQL>?ho imp scott/tiger tables=tb_pt:sal_16 file='/u02/dmp/tb_pt_sal_16.dmp' ignore=y??--再次導(dǎo)入成功
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:56:15 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export file created by EXPORT:V11.02.00 via conventional path
????????import done in US7ASCII character set and AL16UTF16 NCHAR character set
????????import server uses ZHS16GBK character set (possible charset conversion)
????????. importing SCOTT's objects into SCOTT
????????. importing SCOTT's objects into SCOTT
????????. . importing partition???????????????"TB_PT":"SAL_16"????????366 rows imported
????????Import terminated successfully without warnings.
???????
????????SQL>?select?count(*)?from?tb_pt?partition(sal_16);
?
??????????COUNT(*)
????????----------
???????????????366
?
????5.導(dǎo)入整個(gè)表
????????SQL>?truncate?table?tb_pt;????--首先truncate?整個(gè)表
?
????????Table?truncated.
?
????????SQL>?ho imp scott/tiger tables=tb_pt file='/u02/dmp/tb_pt.dmp' ignore=y indexes=y
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 13:57:10 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing o
????????Export file created by EXPORT:V11.02.00 via conventional path
????????import done in US7ASCII character set and AL16UTF16 NCHAR character set
????????import server uses ZHS16GBK character set (possible charset conversion)
????????. importing SCOTT's objects into SCOTT
????????. importing SCOTT's objects into SCOTT
????????. . importing partition???????????????"TB_PT":"SAL_11"????????298 rows imported
????????. . importing partition???????????????"TB_PT":"SAL_12"????????366 rows imported
????????. . importing partition???????????????"TB_PT":"SAL_13"????????365 rows imported
????????. . importing partition???????????????"TB_PT":"SAL_14"????????365 rows imported
????????. . importing partition???????????????"TB_PT":"SAL_15"????????365 rows imported
????????. . importing partition???????????????"TB_PT":"SAL_16"????????366 rows imported
????????. . importing partition????????????"TB_PT":"SAL_OTHER"???????2875 rows imported
????????Import terminated successfully without warnings.
???????
????????SQL>?select?count(1)?from?tb_pt?partition(sal_other);
?
??????????COUNT(1)
????????----------
??????????????2875
?
四、使用expdp/impdb來實(shí)現(xiàn)分區(qū)表的導(dǎo)入導(dǎo)出
????1.查看導(dǎo)入導(dǎo)出的目錄設(shè)置
????????SQL>?select?directory_name,directory_path?from?dba_directories?where?directory_name='DMP';
?
????????DIRECTORY_NAME?????????????????DIRECTORY_PATH
????????------------------------------ ------------------------------------------------------------
????????DMP????????????????????????????/u02/dmp
?
????2.為分區(qū)表創(chuàng)建一個(gè)本地索引
????????create?index?tb_pt_local_idx
????????on?tb_pt(sal_id)
????????local
????????(partition?local1,
????????partition?local2,
????????partition?local3,
????????partition?local4,
????????partition?local5,
????????partition?local6,
????????partition?local7)
????????;
?
????3.導(dǎo)出整個(gè)表
????????[oracle@node1 ~]$?expdp scott/tiger directory=dmp dumpfile=tb_pt.dmp logfile=tb_pb.log tables=tb_pt parallel=3
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 14:04:28 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing options
????????Starting "SCOTT"."SYS_EXPORT_TABLE_01":??scott/******** directory=dmp dumpfile=tb_pt.dmp logfile=tb_pb.log tables=
????????????tb_pt parallel=3??????????????????????????????????????????????????????????????????
????????Estimate in progress using BLOCKS method...
????????Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
????????Total estimation using BLOCKS method: 512 KB
????????. . exported "SCOTT"."TB_PT":"SAL_OTHER"?????????????????71.63 KB????2875 rows
????????. . exported "SCOTT"."TB_PT":"SAL_11"????????????????????12.54 KB?????298 rows
????????. . exported "SCOTT"."TB_PT":"SAL_12"????????????????????14.22 KB?????366 rows
????????. . exported "SCOTT"."TB_PT":"SAL_13"????????????????????14.18 KB?????365 rows
????????. . exported "SCOTT"."TB_PT":"SAL_14"????????????????????14.18 KB?????365 rows
????????. . exported "SCOTT"."TB_PT":"SAL_15"????????????????????14.19 KB?????365 rows
????????. . exported "SCOTT"."TB_PT":"SAL_16"????????????????????14.23 KB?????366 rows
????????Processing object type TABLE_EXPORT/TABLE/TABLE
????????Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
????????Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
????????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_01" successfully loaded/unloaded
????????******************************************************************************
????????Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
??????????/u02/dmp/tb_pt.dmp
????????Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:04:51
?
????4.導(dǎo)出多個(gè)分區(qū)
????????[oracle@node1 ~]$?expdp scott/tiger directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt.log /
????????> tables=(tb_pt:sal_16,tb_pt:sal_other) parallel=2
????????Export: Release 11.2.0.1.0 - Production on Wed Mar 9 14:08:06 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing options
????????Starting "SCOTT"."SYS_EXPORT_TABLE_01":??scott/******** directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt.log
????????????tables=(tb_pt:sal_16,tb_pt:sal_other) parallel=2????????????????????????--*/
????????Estimate in progress using BLOCKS method...
????????Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
????????Total estimation using BLOCKS method: 192 KB
????????. . exported "SCOTT"."TB_PT":"SAL_OTHER"?????????????????71.63 KB????2875 rows
????????. . exported "SCOTT"."TB_PT":"SAL_16"????????????????????14.23 KB?????366 rows
????????Processing object type TABLE_EXPORT/TABLE/TABLE
????????Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
????????Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
????????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_01" successfully loaded/unloaded
????????******************************************************************************
????????Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
??????????/u02/dmp/tb_pts.dmp
????????Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:08:17
?
????5.截?cái)喾謪^(qū)sal_other
????????SQL>?alter?table?tb_pt?truncate?partition(sal_other);
?
????????Table?truncated.
?
????????SQL>?select?count(*)?from?tb_pt?partition(sal_other);
?
??????????COUNT(*)
????????----------
?????????????????0
?
????????SQL>?select?index_name,status,partitioned?from?dba_indexes?where?table_name='TB_PT';?--查看索引的狀態(tài),?TB_PT_IND1不可用
?
????????INDEX_NAME?????????????????????STATUS???PAR
????????------------------------------ -------- ---
????????TB_PT_IND1?????????????????????UNUSABLE?NO
????????TB_PT_LOCAL_IDX????????????????N/A??????YES
???????
????????SQL>?select?index_name?,partition_name,?status?from?dba_ind_partitions?where?index_owner='SCOTT';
???????
????????INDEX_NAME?????????????????????PARTITION_NAME?????????????????STATUS
????????------------------------------ ------------------------------ --------
????????TB_PT_LOCAL_IDX????????????????LOCAL1?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL2?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL3?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL4?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL5?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL6?????????????????????????USABLE
????????TB_PT_LOCAL_IDX????????????????LOCAL7?????????????????????????USABLE
???????
????6.導(dǎo)入單個(gè)分區(qū)
????????[oracle@node1 ~]$?impdp scott/tiger directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt_imp.log /
????????> tables=tb_pt:sal_other skip_unusable_indexes=y table_exists_action=replace
????????Import: Release 11.2.0.1.0 - Production on Wed Mar 9 14:13:28 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing options
????????Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
????????Starting "SCOTT"."SYS_IMPORT_TABLE_01":??scott/******** directory=dmp dumpfile=tb_pts.dmp logfile=tb_pt_imp.log
????????????tables=tb_pt:sal_other skip_unusable_indexes=y table_exists_action=replace?????????????--*/
????????Processing object type TABLE_EXPORT/TABLE/TABLE
????????Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
????????. . imported "SCOTT"."TB_PT":"SAL_OTHER"?????????????????71.63 KB????2875 rows
????????Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
????????Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
????????Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
????????Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
????????Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 14:13:33
?
????????SQL>?select?index_name,status,partitioned?from?dba_indexes?where?table_name='TB_PT';
?
????????INDEX_NAME?????????????????????STATUS???PAR
????????------------------------------ -------- ---
????????TB_PT_IND1?????????????????????VALID????NO
????????TB_PT_LOCAL_IDX????????????????N/A??????YES
???????
????????從上面的導(dǎo)入情況可以看出,盡管執(zhí)行了truncate partition,然而使用impdp導(dǎo)入工具,并且使用參數(shù)table_exists_action=replace
????????可以避免使用imp導(dǎo)入時(shí)唯一和主鍵索引需要重建的問題。注意,如果沒有使用table_exists_action=replace參數(shù),將會(huì)收到ORA-39151
????????錯(cuò)誤,如下
????????????ORA-39151: Table "SCOTT"."TB_PT" exists. All dependent metadata and data will be skipped due to
????????????????table_exists_action of skip
?
????7.導(dǎo)入整個(gè)表
????????[oracle@node1 ~]$?impdp scott/tiger directory=dmp dumpfile=tb_pt.dmp logfile=tb_pt_fullimp.log /
????????> tables=tb_pt skip_unusable_indexes=y table_exists_action=replace
????????Import: Release 11.2.0.1.0 - Production on Wed Mar 9 14:17:35 2011
????????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, Real Application Clusters, Automatic Storage Management, OLAP,
????????Data Mining and Real Application Testing options
????????Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
????????Starting "SCOTT"."SYS_IMPORT_TABLE_01":??scott/******** directory=dmp dumpfile=tb_pt.dmp logfile=tb_pt_fullimp.log
????????????tables=tb_pt skip_unusable_indexes=y table_exists_action=replace?????????????????????--*/
????????Processing object type TABLE_EXPORT/TABLE/TABLE
????????Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
????????. . imported "SCOTT"."TB_PT":"SAL_OTHER"?????????????????71.63 KB????2875 rows
????????. . imported "SCOTT"."TB_PT":"SAL_11"????????????????????12.54 KB?????298 rows
????????. . imported "SCOTT"."TB_PT":"SAL_12"????????????????????14.22 KB?????366 rows
????????. . imported "SCOTT"."TB_PT":"SAL_13"????????????????????14.18 KB?????365 rows
????????. . imported "SCOTT"."TB_PT":"SAL_14"????????????????????14.18 KB?????365 rows
????????. . imported "SCOTT"."TB_PT":"SAL_15"????????????????????14.19 KB?????365 rows
????????. . imported "SCOTT"."TB_PT":"SAL_16"????????????????????14.23 KB?????366 rows
????????Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
????????Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
????????Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
????????Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
????????Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 14:17:40
?
五、參數(shù)skip_unusable_indexes的作用
????SQL>?show parameter skip
?
????NAME?????????????????????????????????TYPE????????VALUE
????------------------------------------ ----------- ------------------------------
????skip_unusable_indexes????????????????boolean?????TRUE
?
????該參數(shù)允許在導(dǎo)入分區(qū)數(shù)據(jù)時(shí)延遲對(duì)索引的處理,即先將數(shù)據(jù)導(dǎo)入,導(dǎo)入后再來重建索引分區(qū)。
????在命令行導(dǎo)入中未指定導(dǎo)入?yún)?shù)skip_unusable_indexes時(shí),則對(duì)于索引相關(guān)的問題,根據(jù)數(shù)據(jù)庫(kù)初始化參數(shù)的值來確定。
????在命令行導(dǎo)入中如果指定了參數(shù)skip_unusable_indexes時(shí),則該參數(shù)的值優(yōu)先于數(shù)據(jù)庫(kù)初始化參數(shù)的設(shè)定值。
????skip_unusable_indexes=y對(duì)unique index不起作用,因?yàn)榇藭r(shí)的unique index扮演者constraint的作用,所以在insert數(shù)據(jù)時(shí)index必須被
????????更新。
????對(duì)于單個(gè)分區(qū)導(dǎo)入時(shí)PK,unique index的處理,必須先重建索引然后進(jìn)行導(dǎo)入。
????使用impdp數(shù)據(jù)泵實(shí)現(xiàn)導(dǎo)入并使用參數(shù)table_exists_action=replace可以解決上述問題,即ORA-01502錯(cuò)誤。
總結(jié)
以上是生活随笔為你收集整理的导入导出 Oracle 分区表数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Automatic Diagnostic
- 下一篇: Nagios 请检查HTTP服务器关于该