標籤:ota read content xxxx version 對象 cli def ext
資料泵是10g推出的功能,個人倒資料比較喜歡用資料泵。
其匯入的時候利用remap參數很方便轉換資料表空間以及schema,並且可以忽略服務端與用戶端字元集問題(exp/imp需要排查字元集)。
資料泵也有不方便的地方,如果遠程匯出匯入,必須安裝資料庫服務端(client不行);需要在資料庫中建立一個路徑directory(dba_directories);並且主流工具支援exp/imp的匯入匯出(plsql developer),所以探索資料泵流行程度沒有想象中高。
以下簡單介紹schema的匯入匯出
以schema方式匯出生產庫使用者下所有對象,並匯入測試庫。
註:eamdb為生產庫,eamprd為生產庫使用者,密碼為eamprd
eamuat為測試庫,eamprduat為測試庫使用者,密碼為eamprduat
一、生產庫的匯出(以sqlplus命令列的方式)。
1.以sys或者system使用者身份登入生產資料庫。
2.建立schema匯出路徑(DUMP_DIR名稱可替換),並在dba_directories中查看
create directory DUMP_DIR as ‘/xxx/xxx’;select * from dba_directories;
3.把匯出路徑與匯出許可權授權給eamprd,如果用system等進階帳號匯出,則不用。
grant read,write on directory DUMP_DIR to eamprd;grant exp_full_database to eamprd;
4.退出sqlplus,在oracle系統使用者下運行,匯出對應的SCHEMA,推薦第二種。
expdp eamprd/[email protected] DIRECTORY=DUMP_DIR DUMPFILE=eamdb.dmpexpdp system/[email protected] directory=dump_dir dumpfile=eamdb.dmp schemas=eamprd
匯出重點參數:
版本:高往低需加version=xx.x 匯出某些張表tables=xxxx content=metadata_only(只要結構) content=data_only(只要資料)
5.把eamdb.dmp拷貝到測試庫。
二、測試庫的匯入
1.以sys或者system身份登陸測試庫。
2.建立匯入資料表空間和暫存資料表空間(名稱、路徑、資料表空間大小,請自行替換)。
create tablespace tbs_EAMUAT datafile ‘/xxxx/xxxxx/EAMUAT.DBF‘ size 10240M autoextend on next 1024M maxsize 20480M;create temporary tablespace EAMUAT_TEMP tempfile ‘/xxx/xxx/EAMUAT_TEMP.DBF‘ size 5120M;
3.建立使用者及賦予許可權(也可以不建立使用者),匯入時最好給予使用者dba許可權,以防匯入時建立某些對象許可權不夠,注意需要回收其對users資料表空間的許可權。
create user eamprduat identified by eamprduat default tablespace tbs_EAMUAT temporary tablespace EAMUAT_TEMP;grant connect,resource,create view,create session,dba to eamprduat;revoke unlimited tablespace from eamprduat;alter user eamprduat quota unlimited on tbs_EAMUAT;
4.建立匯入路徑(把eamdb.dmp放在此路徑下),並授權。
create directory DUMP_DIR as ‘/xxxxx/xxxxx‘;grant read,write on directory DUMP_DIR to eamprduat;
5.匯入資料(在oracle系統使用者下運行),注意remap_schema參數,請自行替換
impdp eamprduat/[email protected] DIRECTORY=DUMP_DIR DUMPFILE=eamdb.dmp LOGFILE=impdp.log remap_schema=eamprd:eamprduat;
匯入重點參數:
remap_schema=eamprd:eamprduat,eamxxx:xxx,xxx:xxx
remap_tablespace=eamdev:eamxxx,eamxxx:xxx,xxx:xxx
table_exists_action=replace(替換)append(追加)
exclude=table_statistics 此參數是取消對錶的統計資訊收集,如果表太多,不取消的話特別慢,之後可以手動收集,或等oracle自動收集。
execute dbms_stats.gather_table_stats(ownname=>‘USERNAME‘,tabname=>‘TABLE_NAME‘,cascade=>TRUE)
如匯入報錯:ORA-31684: Object type USER:"xxxxx" already exists,不用理會,因為之前建立了使用者。
也可以在匯入的語句中直接remap一個不存在的使用者,會自動產生,其密碼和許可權與匯出時候一樣,但其資料表空間如果不想用users,必須手工建立。
oracle資料泵匯入匯出資料