Mysql中的db link_【小结】数据库链接db link,有兴趣的看看。

【小结】数据库链接db link,有兴趣的看看。

假设有2台oracle数据库,一台叫test,一台叫prod,都是9204。

其中test在window xp平台,prod在RHEL AS3。

test:

db_name=dba

db_domain=world

glabal_name=dba.world

prod:

db_name=ora9i

db_domain=oracle.com

global_name=ora9i.oracle.com

db link指向是: test -> prod

假设test和prod数据库上都有scott和mhung用户。

test上指向prod的网络连接串是as3。

db link 有3种类型,我这里只讨论其中两种,connected user和fixed user。

connected user,简单来说,test数据库以connected的用户来连接远程数据库(prod)。

fixed user,简单来说,test数据库以fixed(指定的)用户来连接远程数据库(prod)。

看看创建db link语法,你对这两种类型就比较清楚了。

创建fixed user的db link语法:

create databas link foo connect to scott identified by tiger using 'as3' ;

创建fixed user的db link语法:

create databas link foo using 'as3' ;

db link 的命名和global_names有关,

如果global_names=true(test),那么db link的命名要和远程数据库(prod)的global_name相同;

如果global_names=false(test),那么你可以随便命名db link。

请注意,是test数据库的global_names,与prod数据库的global_names无关。

global_name是数据库全局名称,global_name在你所管理的数据库中要保证唯一。

数据库名称是db_name。数据库名称一般都取得比较短,我的习惯一般取长度4个字符,重名概率高。

比如你有2个数据库的db_name都是prod,重名啦。

所以,oracle模仿域名搞出一个global_name,global_name=db_name+db_domain。

有了global_name,就可以实现数据库命名的全局唯一。

4种情况如下表。

global_names(test数据库)   db link type

-----------------            -------------

1. false                        connected user

2. false                        fixed user

3. true                         connected user

4. true                         fixed user

1. global_names=false, link type=connected user

scott@DBA.WORLD> create database link foo using 'as3' ;

Database link created.

Elapsed: 00:00:00.00

scott@DBA.WORLD> select * from global_name ;

GLOBAL_NAME

--------------------------------------------------------

DBA.WORLD

Elapsed: 00:00:00.00

scott@DBA.WORLD> select * from global_name@foo ;

GLOBAL_NAME

--------------------------------------------------------

ORA9I.ORACLE.COM

Elapsed: 00:00:00.04

scott@DBA.WORLD>

2. global_names=false, link type=fixed user

scott@DBA.WORLD> create database link woo connect to mhung identified by huang using 'as3' ;

Database link created.

Elapsed: 00:00:00.00

scott@DBA.WORLD> select * from global_name@woo ;

GLOBAL_NAME

----------------------------------------------------------------------------------------------

ORA9I.ORACLE.COM

Elapsed: 00:00:00.04

scott@DBA.WORLD> select *from global_name ;

GLOBAL_NAME

----------------------------------------------------------------------------------------------

DBA.WORLD

Elapsed: 00:00:00.00

scott@DBA.WORLD>

以下测试global_names=true的情况,

3. global_name=true, link type=connected user

sys@DBA.WORLD> show parameter global

NAME                                 TYPE        VALUE

------------------------------------ ----------- ----------------

global_context_pool_size             string

global_names                         boolean     FALSE

sys@DBA.WORLD> alter system set global_names=true ;

System altered.

Elapsed: 00:00:00.01

sys@DBA.WORLD>

scott@DBA.WORLD> select * from global_name@foo ;

select * from global_name@foo

*

ERROR at line 1:

ORA-02085: database link FOO.WORLD connects to ORA9I.ORACLE.COM

Elapsed: 00:00:00.00

scott@DBA.WORLD>

看看,global_names=true后,刚才好好的foo,马上失效了。

现在我把global_names改为false再看看。

sys@DBA.WORLD> alter system set global_names=false ;

System altered.

Elapsed: 00:00:00.01

sys@DBA.WORLD> show parameter global_names

NAME                                 TYPE        VALUE

------------------------------------ ----------- ----------

global_names                         boolean     FALSE

sys@DBA.WORLD>

scott@DBA.WORLD> select * from global_name@foo ;

GLOBAL_NAME

----------------------------------------------------

ORA9I.ORACLE.COM

Elapsed: 00:00:00.00

scott@DBA.WORLD>

你看,foo又好了。

废话一堆,现在开始第3种情况测试,首先把global_names改为true。

sys@DBA.WORLD> alter system set global_names=true ;

System altered.

Elapsed: 00:00:00.01

sys@DBA.WORLD> show parameter global_names

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------

global_names                         boolean     TRUE

sys@DBA.WORLD>

开始创建db link。

scott@DBA.WORLD> create database link ora9i.oracle.com using 'as3' ;

Database link created.

Elapsed: 00:00:00.00

scott@DBA.WORLD> select * from global_name@ora9i.oracle.com ;

GLOBAL_NAME

--------------------------------------------------------------------

ORA9I.ORACLE.COM

Elapsed: 00:00:00.05

scott@DBA.WORLD>

4. global_name=true, link type=fixed user

(略)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值