使用datapump 匯出匯入同義詞(export and import synonym using datapump)
對於同義詞的備份我們有多種方式來實現,如直接透過指令碼生成同義詞的建立指令碼,或者使用dbms_metadata.get_ddl來提取同義詞的定義指令碼。然而在使用傳統的exp或是datapump expdp實現schema級別資料遷移時,不能匯出公共同義詞。儘管如此,我們依舊可以使用匯出匯入的方式來實現。所不同的是,我們使用FULL=Y的方式來單獨匯出同義詞,然後再將其匯入的目標資料庫。下文是對此進行的描述,末尾也給出了手動建立同義詞的指令碼。
1、環境
- --源資料庫
- SQL> select * from v$version where rownum<2;
- BANNER
- ----------------------------------------------------------------
- Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
- SQL> show parameter db_nam
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_name string XM6320
- SQL> select count(*) from dba_synonyms where table_owner='GOEX_ADMIN';
- COUNT(*)
- ----------
- 1042
- --目標資料庫
- --目標資料庫schema goex_admin的所有資料均來源於源資料庫,但是使用datapump匯入後,無同義詞
- SQL> select * from v$version where rownum<2;
- BANNER
- ----------------------------------------------------------------
- Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
- SQL> show parameter db_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_name string KM3625
- --下面的查詢中僅有兩個同義詞,這兩個同義是在建立DB的時候手動建立的,非使用datapump匯入產生的
- SQL> select count(*) from dba_synonyms where table_owner='GOEX_ADMIN';
- COUNT(*)
- ----------
- 2
2、從源資料庫匯出公共同義詞
- oracle@BKDB01p:~> env | grep SID
- ORACLE_SID=XM6320
- #使用下面的方式匯出公共同義詞,對於可匯出的物件我們可以查詢資料字典 DATABASE_EXPORT_OBJECTS
- oracle@BKDB01p:~> expdp goex_admin/xxx directory=db_dump_dir dumpfile=syns.dmp logfile=exp_syns.log full=y \
- > include=PUBLIC_SYNONYM/SYNONYM:\"IN \(SELECT synonym_name FROM dba_synonyms WHERE table_owner=\'GOEX_ADMIN\'\)\"
- Export: Release 10.2.0.3.0 - 64bit Production on Wednesday, 19 June, 2013 16:11:19
- Copyright (c) 2003, 2005, Oracle. All rights reserved.
- Connected to: Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
- Starting "GOEX_ADMIN"."SYS_EXPORT_FULL_01": goex_admin/******** directory=db_dump_dir dumpfile=syns.dmp logfile=exp_syns.log
- full=y include=PUBLIC_SYNONYM/SYNONYM:"IN (SELECT synonym_name FROM dba_synonyms WHERE table_owner='GOEX_ADMIN')"
- Estimate in progress using BLOCKS method...
- Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
- Total estimation using BLOCKS method: 0 KB
- Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM
- Master table "GOEX_ADMIN"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
- ******************************************************************************
- Dump file set for GOEX_ADMIN.SYS_EXPORT_FULL_01 is:
- /u02/database/XM6320/BNR/dump/syns.dmp
- Job "GOEX_ADMIN"."SYS_EXPORT_FULL_01" successfully completed at 16:11:23
3、匯入公共同義詞到目標資料庫
- oracle@BKDB01p:~> cp /u02/database/XM6320/BNR/dump/syns.dmp /u02/database/KM3625/BNR/dump/
- oracle@BKDB01p:~> export ORACLE_SID=KM3625
- oracle@BKDB01p:~> impdp goex_admin/xxx directory=db_dump_dir dumpfile=syns.dmp logfile=imp_syns.log full=y include=synonym
- Import: Release 10.2.0.3.0 - 64bit Production on Wednesday, 19 June, 2013 16:15:52
- Copyright (c) 2003, 2005, Oracle. All rights reserved.
- Connected to: Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
- Master table "GOEX_ADMIN"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
- Starting "GOEX_ADMIN"."SYS_IMPORT_FULL_01": goex_admin/******** directory=db_dump_dir dumpfile=syns.dmp logfile=imp_syns.log full=y include=synonym
- Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM
- ORA-31684: Object type SYNONYM:"PUBLIC"."GO_GA_SYS_DATAPUMP_PARA_TBL" already exists
- ORA-31684: Object type SYNONYM:"PUBLIC"."BO_SYS_DATAPUMP_PKG" already exists
- Job "GOEX_ADMIN"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 16:16:12
- #上面的匯入過程可以看到,Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM實現了同義詞的匯入
- #同時由於有兩個同義詞存在,也給出了提示
- #驗證匯入的同義詞
- oracle@BKDB01p:~> sqlplus / as sysdba
- SQL*Plus: Release 10.2.0.3.0 - Production on Wed Jun 19 16:16:24 2013
- Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
- Connected to:
- Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
- SQL> show parameter db_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_name string KM3625
- SQL> select count(*) from dba_synonyms where table_owner='GOEX_ADMIN';
- COUNT(*)
- ----------
- 1042
4、手動建立同義詞的指令碼
- ACCEPT input_owner PROMPT 'Enter the owner of table:'
- SET HEADING OFF VERIFY OFF FEEDBACK OFF TERMOUT OFF;
- SPOOL $LOG/create_synonym.sql
- --Author: Robinson
- --Blog : http://blog.csdn.net/robinson_0612
- SELECT 'create public synonym ' || synonym_name || ' for ' || table_owner || '.' || table_name || ';'
- FROM dba_synonyms s
- WHERE s.owner = 'PUBLIC' AND s.table_owner = UPPER ('&input_owner');
- SET HEADING ON VERIFY ON TERMOUT ON FEEDBACK OFF;
- SPOOL OFF;
- --@$LOG/create_synonym.sql;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1098047/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- datapump 匯出匯入ORA-07445
- react-native 之匯入(import)、匯出(export)深刻解析ReactImportExport
- 完全可傳輸的匯出/匯入(full transportable export/import)ExportImport
- 匯出oracle公有同義詞Oracle
- DataPump Export (EXPDP) Fails With Error LPX-216 Invalid CharacterExportAIError
- Datapump:EXCLUDE/INCLUDE
- 如何使用 JavaScript 匯入和匯出 ExcelJavaScriptExcel
- Activity 流程模型匯入匯出-activity流程模型匯入匯出模型
- Mysql匯入&匯出MySql
- doris匯入匯出
- esayExcel匯入匯出Excel
- java匯出Excel定義匯出模板JavaExcel
- vue excel匯入匯出VueExcel
- navlicat 匯入匯出SQLSQL
- Golang-import匯入包語法GolangImport
- go 語言模組匯入importGoImport
- Oracle資料庫匯入匯出。imp匯入命令和exp匯出命令Oracle資料庫
- 如何使用JavaScript匯入和匯出Excel檔案JavaScriptExcel
- java使使用者EasyExcel匯入匯出excelJavaExcel
- Python之外掛模式(使用import_module匯入子模組)Python模式Import
- 使用Import-Cost VSCode外掛控制匯入包大小ImportVSCode
- Angular Excel 匯入與匯出AngularExcel
- sqoop資料匯入匯出OOP
- Oracle 資料匯入匯出Oracle
- 資料泵匯出匯入
- .net6 匯入匯出
- Oracle資料匯入匯出Oracle
- phpMyAdmin匯入/匯出資料PHP
- 【docker】docker映象匯出匯入Docker
- scss :export 中匯出的變數為空CSSExport變數
- ASP.NET 開源匯入匯出庫Magicodes.IE 完成Csv匯入匯出ASP.NET
- import匯入檔案路徑注意點Import
- MySQL Shell import_table資料匯入MySqlImport
- mongodb使用自帶命令工具匯出匯入資料MongoDB
- 使用Dbeaver 進行資料的匯入和匯出
- 使用VUE+SpringBoot+EasyExcel 整合匯入匯出資料VueSpring BootExcel
- Vue框架下實現匯入匯出Excel、匯出PDFVue框架Excel
- [譯] 為什麼我不再使用 export default 來匯出模組Export
- ORACLE for aix 11.2.0.1 DATAPUMP expdp之BUG 9470768OracleAI