阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

expdp 只导出dblink

238次阅读
没有评论

共计 7540 个字符,预计需要花费 19 分钟才能阅读完成。

最近生产数据库要修改生产用户的密码,由于用户密码修改,各个库之间创建的 dblink 就失效了,需要重建。上生产一看 dblink 还真不少,而且谁建的都有,改起来比较费劲。于是想到可以使用 expdp 的方式导出所有的 dblink,即可获取 dblink 的创建语句,然后修改原密码再在库上创建就可以了。

Oracle 生产环境中的库有两个版本 10.2.0.4 和 11.2.0.3 下面分别在 10g 和 11g 上做测试

Oracle 测试 10g:

SQL> select * from v$version;
 
BANNER
—————————————————————-
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bi
PL/SQL Release 10.2.0.4.0 – Production
CORE    10.2.0.4.0  Production
TNS for Linux: Version 10.2.0.4.0 – Production
NLSRTL Version 10.2.0.4.0 – Production

创建 dblink 到 11g 数据库

SQL> create public database link link_11g
connect to system identified by “123456”
using ‘(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )’; 
 
Database link created.
SQL> select * from dual@link_11g;
 
D

X
 
col owner for a30
col username for a30
col db_link for a30
col host for a50
set linesize 200
set pagesize 999
select OWNER,DB_LINK,USERNAME,HOST from dba_db_links;
OWNER                  DB_LINK                USERNAME                HOST
—————————— —————————— —————————— ————————————————–
PUBLIC                LINK_11G              SYSTEM              (DESCRIPTION =
                                                (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.
                                                2)(PORT = 1521))
                                                (CONNECT_DATA =
                                                  (SERVER = DEDICATED)
                                                  (SERVICE_NAME = orcl)
                                                )
                                                  )

使用 expdp 导出 dblink

[oracle@rhel5 ~]$ expdp system/123456 directory=dump dumpfile=dblink.dmp full=y include=db_link
Export: Release 10.2.0.4.0 – 64bit Production on Thursday, 10 November, 2016 15:26:02
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
FLASHBACK automatically enabled to preserve database integrity.
Starting “SYSTEM”.”SYS_EXPORT_FULL_01″:  system/******** directory=dump dumpfile=dblink.dmp full=y include=db_link
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/DB_LINK
Master table “SYSTEM”.”SYS_EXPORT_FULL_01″ successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_FULL_01 is:
  /home/oracle/dblink.dmp
Job “SYSTEM”.”SYS_EXPORT_FULL_01″ successfully completed at 15:26:13

使用 impdp 查看导出的 dblink 的创建语句

[oracle@rhel5 ~]$ impdp system/123456 directory=dump dumpfile=dblink.dmp sqlfile=dblink.sql
 
Import: Release 10.2.0.4.0 – 64bit Production on Thursday, 10 November, 2016 15:28:31
 
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
 
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table “SYSTEM”.”SYS_SQL_FILE_FULL_01″ successfully loaded/unloaded
Starting “SYSTEM”.”SYS_SQL_FILE_FULL_01″:  system/******** directory=dump dumpfile=dblink.dmp sqlfile=dblink.sql
Processing object type DATABASE_EXPORT/SCHEMA/DB_LINK
Job “SYSTEM”.”SYS_SQL_FILE_FULL_01″ successfully completed at 15:28:33
 
[oracle@rhel5 ~]$ cat /home/oracle/dblink.sql
— CONNECT SYSTEM
— new object type path is: DATABASE_EXPORT/SCHEMA/DB_LINK
CREATE PUBLIC DATABASE LINK “LINK_11G”
  CONNECT TO “SYSTEM” IDENTIFIED BY VALUES ‘0588B5151FD4089DC7B87F64727E740D26’
  USING ‘(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )’;

测试 11g

sys@ORCL>select * from v$version;
 
BANNER
——————————————————————————————————————————————————————————————————–
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
PL/SQL Release 11.2.0.4.0 – Production
CORE    11.2.0.4.0  Production
TNS for Linux: Version 11.2.0.4.0 – Production
NLSRTL Version 11.2.0.4.0 – Production

创建 dblink

create public database link link_10g
connect to system identified by “123456”
using ‘(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mydb)
    )
  )’;
 
Database link created.
 
sys@ORCL>select * from dual@link_10g;
 
DUM

X
 
sys@ORCL>select OWNER,DB_LINK,USERNAME,HOST from dba_db_links;
 
OWNER                  DB_LINK                USERNAME                HOST
—————————— —————————— —————————— ————————————————–
PUBLIC                LINK_A                  SCOTT                orcl
PUBLIC                LINK_10G              SYSTEM              (DESCRIPTION =
                                                (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.
                                                11)(PORT = 1521))
                                                (CONNECT_DATA =
                                                  (SERVER = DEDICATED)
                                                  (SERVICE_NAME = mydb)
                                                )
                                                  )

expdp 导出 dblink

[oracle@rhel6 ~]$ expdp system/123456 directory=dump dumpfile=dblink.dmp full=y include=db_link
 
Export: Release 11.2.0.4.0 – Production on Thu Nov 10 15:34:24 2016
 
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
FLASHBACK automatically enabled to preserve database integrity.
Starting “SYSTEM”.”SYS_EXPORT_FULL_01″:  system/******** directory=dump dumpfile=dblink.dmp full=y include=db_link
Estimate in progress using BLOCKS method…
Total estimation using BLOCKS method: 0 KB
Processing object type DATABASE_EXPORT/SCHEMA/DB_LINK
Master table “SYSTEM”.”SYS_EXPORT_FULL_01″ successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_FULL_01 is:
  /home/oracle/dblink.dmp
Job “SYSTEM”.”SYS_EXPORT_FULL_01″ successfully completed at Thu Nov 10 15:34:42 2016 elapsed 0 00:00:15

使用 impdp 查看导出的 dblink 的创建语句

[oracle@rhel6 ~]$ impdp system/123456 directory=dump dumpfile=dblink.dmp sqlfile=dblink.sql
 
Import: Release 11.2.0.4.0 – Production on Thu Nov 10 15:35:38 2016
 
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
Master table “SYSTEM”.”SYS_SQL_FILE_FULL_01″ successfully loaded/unloaded
Starting “SYSTEM”.”SYS_SQL_FILE_FULL_01″:  system/******** directory=dump dumpfile=dblink.dmp sqlfile=dblink.sql
Processing object type DATABASE_EXPORT/SCHEMA/DB_LINK
Job “SYSTEM”.”SYS_SQL_FILE_FULL_01″ successfully completed at Thu Nov 10 15:35:40 2016 elapsed 0 00:00:01
 
[oracle@rhel6 ~]$ cat /home/oracle/dblink.sql
— CONNECT SYSTEM
ALTER SESSION SET EVENTS ‘10150 TRACE NAME CONTEXT FOREVER, LEVEL 1’;
ALTER SESSION SET EVENTS ‘10904 TRACE NAME CONTEXT FOREVER, LEVEL 1’;
ALTER SESSION SET EVENTS ‘25475 TRACE NAME CONTEXT FOREVER, LEVEL 1’;
ALTER SESSION SET EVENTS ‘10407 TRACE NAME CONTEXT FOREVER, LEVEL 1’;
ALTER SESSION SET EVENTS ‘10851 TRACE NAME CONTEXT FOREVER, LEVEL 1’;
ALTER SESSION SET EVENTS ‘22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ‘;
— new object type path: DATABASE_EXPORT/SCHEMA/DB_LINK
CREATE PUBLIC DATABASE LINK “LINK_10G”
  CONNECT TO “SYSTEM” IDENTIFIED BY VALUES ‘:1’
  USING ‘(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mydb)
    )
  )’;
CREATE PUBLIC DATABASE LINK “LINK_A”
  CONNECT TO “SCOTT” IDENTIFIED BY VALUES ‘:1’
  USING ‘orcl’;

使用上面的方式可以查看 dblink 的创建语句。

从上面 dblink 创建语句的输出结果也可以看出 10g 导出的 dblink 创建语句可以看到密码的密文,而 11g 里就看不到了。

官方文档:http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm#i2061505

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-02/140529.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计7540字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中