oracle 使用db_link 導入導出小結
阿新 • • 發佈:2017-06-02
generated cnblogs mes verify font 檢查 對象 數據 pan
客戶有一個需求,是將一個庫中的某個用戶遷移到一臺新的oracle服務器上,因數據量較小,並且不涉及版本的升級,所以可以采用創建一個dblink,然後通過這個dblink直接從源庫將用戶數據導出並導入到新庫中。
為了防止現場發生意外,因此先自己搭建一套環境進行測試,環境如下:
源庫:192.168.56.100 Abbott 數據庫:orcl 連接名:orcl1 導出用戶:test
新庫:192.168.56.40 ora-ogg 數據庫:orcl 連接名:ogg 創建用戶:abbott
實施步驟:
- 配置源庫和新庫的tnsnames.ora文件,使其可以互連,這裏源庫和新庫的tnsnames.ora文件內容相同;
[
2. 測試連接,從源庫使用abbott用戶連接到新庫上,或者從新庫用test用戶連接到源庫上:
[[email protected] admin]$ sqlplus abbott/abbott@ogg SQL*Plus: Release 11.2.0.4.0 Production on Wed May 24 16:01:36 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
3. 新庫創建dblink,這裏用sys用戶登錄,創建了一個public的dblink:
SQL> create public database link sjdr connect to test identified by test using ‘orcl1‘; Database link created.
4. 在源庫授予導出用戶test執行數據泵的權限:
[[email protected] admin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 24 16:30:58 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> grant EXP_FULL_DATABASE to test; Grant succeeded.
註:如果未授予該權限,在導入導出的時候將報如下錯誤:
[[email protected] admin]$ impdp system/oracle schemas=TEST network_link=sjdr Import: Release 11.2.0.4.0 - Production on Wed May 24 16:24:25 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options ORA-31631: privileges are required ORA-39149: cannot link privileged user to non-privileged user
5. 在新庫中創建test用戶所對應的表空間及數據文件:
SQL> create tablespace test datafile ‘/u01/app/oracle/oradata/orcl/test.dbf‘ size 20m autoextend on; Tablespace created
6. 執行導入導出:
[[email protected] admin]$ impdp system/oracle schemas=TEST network_link=sjdr Import: Release 11.2.0.4.0 - Production on Wed May 24 16:33:16 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** schemas=TEST network_link=sjdr Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 64 KB 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 . . imported "TEST"."T1" 1 rows Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Wed May 24 16:33:30 2017 elapsed 0 00:00:14
7. 檢查結果:
[[email protected] admin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 24 16:33:40 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select * from test.t1; ID NAME ---------- -------------------- 1 zx
8. 只導用戶表結構,不包含表數據,並且將test用戶表結構及對象導入到abbott用戶下,修改test用戶表空間到abbott表空間:
[[email protected] admin]$ impdp system/oracle remap_schema=test:abbott remap_tablespace=test:abbott network_link=sjdr content=metadata_only
9. 新庫中abbott用戶默認表空間為abbott,如果未指定remap_tablespace,而只是指定remap_schema為abbott,那麽導入後對象仍然在TEST表空間中:
[[email protected] ~]$ impdp system/oracle remap_schema=test:abbott network_link=impabbott Import: Release 11.2.0.4.0 - Production on Thu May 25 23:26:00 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** remap_schema=test:abbott network_link=impabbott Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 64 KB Processing object type SCHEMA_EXPORT/USER ORA-31684: Object type USER:"ABBOTT" already exists 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 . . imported "ABBOTT"."T1" 1 rows Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION Processing object type SCHEMA_EXPORT/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION ORA-39082: Object type ALTER_FUNCTION:"ABBOTT"."VERIFY_FUNCTION_11G" created with compilation warnings Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE ORA-39082: Object type ALTER_PROCEDURE:"ABBOTT"."MM" created with compilation warnings Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 3 error(s) at Thu May 25 23:26:12 2017 elapsed 0 00:00:11 [[email protected] ~]$ sqlplus / as sysdba SQL> conn abbott/abbott SQL> select * from t1; ID NAME ---------- -------------------- 1 zx SQL> select segment_name,tablespace_name from dba_segments where owner=‘ABBOTT‘ and segment_name=‘T1‘; SEGMENT_NAME TABLESPACE_NAME ----------------------------------------- T1 TEST SQL> select segment_name,tablespace_name from dba_segments where segment_name=‘T1‘; #一個test.T1 一個Abbott.T1 SEGMENT_NAME TABLESPACE_NAME ----------------------------------------------- T1 TEST T1 TEST
10. 使用sys無密碼導入導出:
[[email protected] ~]$ impdp \‘/ as sysdba\‘ directory=impdir dumpfile=full.dmp logfile=testim2.log remap_schema=test:abbott
11.用戶密碼包含特殊符號的導入導出
-
[[email protected] ~]$ impdp \‘sys/\"oracle@#123\" as sysdba\‘ directory=impdir dumpfile=full.dmp logfile=testim2.log
oracle 使用db_link 導入導出小結