資料泵對已經存在的表載入索引
一個朋友提到一個資料泵匯入的問題,在表存在的情況下,不刪除表,且匯入表的資料和索引。
其實這個任務對於imp很簡單,因為imp的工作方式就是如此。
SQL> CREATE TABLE T_EXP
2 (ID NUMBER, NAME VARCHAR2(30));
表已建立。
SQL> CREATE INDEX IND_T_EXP_ID
2 ON T_EXP(ID);
索引已建立。
SQL> INSERT INTO T_EXP
2 SELECT ROWNUM, TNAME
3 FROM TAB;
已建立72行。
SQL> COMMIT;
提交完成。
SQL> HOST exp test/test file=t_exp.dmp buffer=2048000 tables=t_exp
Export: Release 9.2.0.4.0 - Production on 星期三 6月 2 15:12:26 2010
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
連線到: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
已匯出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即將匯出指定的表透過常規路徑 ...
. . 正在匯出表 T_EXP 72 行被匯出
在沒有警告的情況下成功終止匯出。
SQL> DROP INDEX IND_T_EXP_ID;
索引已丟棄。
SQL> HOST imp test/test file=t_exp.dmp buffer=2048000 tables=t_exp ignore=y
Import: Release 9.2.0.4.0 - Production on 星期三 6月 2 15:13:10 2010
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
連線到: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
經由常規路徑匯出由EXPORT:V09.02.00建立的檔案
已經完成ZHS16GBK字符集和AL16UTF16 NCHAR 字符集中的匯入
. 正在將TEST的物件匯入到 TEST
. . 正在匯入表 "T_EXP" 72行被匯入
成功終止匯入,但出現警告。
SQL> SELECT COUNT(*) FROM T_EXP;
COUNT(*)
----------
144
SQL> SELECT INDEX_NAME
2 FROM USER_INDEXES
3 WHERE TABLE_NAME = 'T_EXP';
INDEX_NAME
------------------------------
IND_T_EXP_ID
而impdp的預設工作並非如此,如果監測到表存在,impdp會跳過索引的建立:
SQL> CREATE TABLE T_EXP (ID NUMBER, NAME VARCHAR2(30));
Table created.
SQL> INSERT INTO T_EXP
2 SELECT ROWNUM, TNAME
3 FROM TAB;
95 rows created.
SQL> COMMIT;
Commit complete.
SQL> CREATE INDEX IND_T_EXP_ID
2 ON T_EXP (ID);
Index created.
下面執行匯出:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t_exp.dp tables=t_exp
Export: Release 10.2.0.3.0 - 64bit Production on 星期三, 02 6月, 2010 15:18:59
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "TEST"."SYS_EXPORT_TABLE_01": test/******** directory=d_output dumpfile=t_exp.dp tables=t_exp
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/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "TEST"."T_EXP" 6.890 KB 95 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t_exp.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 15:19:27
清除資料,並刪除索引:
SQL> DROP INDEX IND_T_EXP_ID;
Index dropped.
SQL> TRUNCATE TABLE T_EXP;
Table truncated.
執行impdp匯入:
[oracle@yans1 ~]$ impdp test/test directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate
Import: Release 10.2.0.3.0 - 64bit Production on 星期三, 02 6月, 2010 15:20:26
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TABLE_01": test/******** directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39153: Table "TEST"."T_EXP" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."T_EXP" 6.890 KB 95 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job "TEST"."SYS_IMPORT_TABLE_01" completed with 1 error(s) at 15:31:28
檢查索引和資料:
SQL> SELECT COUNT(*) FROM T_EXP;
COUNT(*)
----------
95
SQL> SELECT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'T_EXP';
no rows selected
資料雖然匯入了,但是索引沒有建立。不過要解決這個問題也很簡單,透過INCLUDE就可以解決這個問題:
SQL> TRUNCATE TABLE T_EXP;
Table truncated.
加上INCLUDE=INDEX執行匯入:
[oracle@yans1 ~]$ impdp test/test directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate include=index
Import: Release 10.2.0.3.0 - 64bit Production on 星期三, 02 6月, 2010 15:21:32
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TABLE_01": test/******** directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate include=index
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job "TEST"."SYS_IMPORT_TABLE_01" successfully completed at 15:21:34
可以看到,這次似乎沒有匯入資料,檢查一下:
SQL> SELECT COUNT(*) FROM T_EXP;
COUNT(*)
----------
0
SQL> SELECT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'T_EXP';
INDEX_NAME
------------------------------
IND_T_EXP_ID
果然,雖然索引匯入了,但是資料沒有匯入。
不過這就更簡單了,透過INCLUDE=INDEX和INCLUDE=TABLE_DATA,就可以解決這個問題了:
SQL> DROP INDEX IND_T_EXP_ID;
Index dropped.
刪除索引,執行匯入:
[oracle@yans1 ~]$ impdp test/test directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate include=index include=table_data
Import: Release 10.2.0.3.0 - 64bit Production on 星期三, 02 6月, 2010 15:23:06
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TABLE_01": test/******** directory=d_output dumpfile=t_exp.dp tables=t_exp table_exists_action=truncate include=index include=table_data
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."T_EXP" 6.890 KB 95 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job "TEST"."SYS_IMPORT_TABLE_01" successfully completed at 15:23:08
最後檢查一下是否成功:
SQL> SELECT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'T_EXP';
INDEX_NAME
------------------------------
IND_T_EXP_ID
SQL> SELECT COUNT(*) FROM T_EXP;
COUNT(*)
----------
95
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-664247/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料泵對已經存在的表載入索引 imp 和impdp索引
- 資料泵匯入-在物件已存在的情況下執行匯入物件
- SmartSVN開啟已經存在的資料夾
- 資料泵匯出匯入表
- Oracle使用資料泵匯出匯入表Oracle
- 把一個已存在資料的大表改成分割槽表
- mysql對資料庫表建索引MySql資料庫索引
- 表資料的儲存對索引的影響索引
- 資料泵匯出索引資料和統計資訊嗎索引
- Impdp資料泵匯入
- 資料泵的匯入匯出
- 資料泵避免個別表資料的匯出
- 使用資料泵impdp匯入資料
- 資料泵匯入分割槽表長時間HANG住
- 對比資料泵與原始匯入匯出工具(五)
- 對比資料泵與原始匯入匯出工具(四)
- 對比資料泵與原始匯入匯出工具(三)
- 對比資料泵與原始匯入匯出工具(八)
- 對比資料泵與原始匯入匯出工具(七)
- 對比資料泵與原始匯入匯出工具(六)
- 資料泵匯出匯入
- 資料泵IMPDP 匯入工具的使用
- 外部表載入資料(ExternalTables)
- 資料泵避免個別表資料的匯出(二)
- oracl11g下exp_imp匯入已經存在表或其它物件的使用者物件
- dbca是透過哪個檔案發現已經存在的資料庫的?資料庫
- Redis Manager 接入已經存在的叢集Redis
- 索引對直接路徑載入的影響索引
- 對資料泵資料傳輸的時間統計
- 資料泵匯入分割槽表統計資訊報錯(七)
- 資料泵匯入分割槽表統計資訊報錯(二)
- 資料泵匯入分割槽表統計資訊報錯(四)
- 資料泵匯入分割槽表統計資訊報錯(三)
- 資料泵匯入分割槽表統計資訊報錯(六)
- 資料泵匯入分割槽表統計資訊報錯(五)
- 獨家對話李飛飛:雲資料庫戰爭已經進入下半場資料庫
- 10G資料泵載入命令expdp/impdp的引數說明
- Oracle資料泵的匯入和匯出Oracle