【IMPDP】使用IMPDP自動建立使用者並完成資料的匯入

secooler發表於2010-04-04
在《【IMPDP】【IMP】SQL指令碼盡收眼底——SHOW引數與SQLFILE引數對比》http://space.itpub.net/519536/viewspace-631290文章中談到,使用EXPDP匯出的dump檔案中包含使用者的建立資訊,因此在使用IMPDP匯入資料時,如果使用者不存在的情況下,IMPDP工具可以自動完成使用者的建立工作(當然,完成匯入的使用者需要具有建立使用者的許可權,如使用system使用者)。

1.使用EXPDP生成備份檔案
sec@secDB /expdp$ expdp sec/sec directory=expdp_dir dumpfile=`date +"%Y%m%d%H%M%S"`_sec.dmp logfile=`date +"%Y%m%d%H%M%S"`_sec.log

Export: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:29:17

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, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 3 MB
Processing object type SCHEMA_EXPORT/USER
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/TABLE/TABLE
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
. . exported "SEC"."T"                                   2.259 MB   24360 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/20100401102917_sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:29:20

2.刪除使用者sec
sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> drop user sec cascade;

User dropped.

3.使用IMPDP完成資料的匯入
sec@secDB /expdp$ impdp system/password directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:44:07

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, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log
Processing object type SCHEMA_EXPORT/USER
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/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SEC"."T"                                   2.259 MB   24360 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 10:44:10

可見,在sec使用者自動建立,並完成資料的匯入。

4.最終的驗證
登入到資料庫sec使用者,驗證資料是否匯入成功。
sec@secDB /expdp$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Thu Apr 1 10:44:23 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

sys@ora10g> conn sec/sec
Connected.
sec@ora10g> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
T                              TABLE

sec@ora10g> select count(*) from t;

  COUNT(*)
----------
     24360

OK,資料匯入完成。

5.小結
IMPDP的使用者自動建立功能也體現了Oracle自動化的思想。不過在使用過程中,一定要注意dump檔案中建立使用者指令碼的細節引數,防止帶來不必要的麻煩。
雖然IMPDP工具具有自動建立使用者的功能,不過儘量不要採用這種方法,還是應該按部就班的手工完成使用者的建立及使用者授權,然後再完成資料的匯入。

Good luck.

secooler
10.04.04

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-631325/,如需轉載,請註明出處,否則將追究法律責任。

相關文章