ORACLE資料庫中Global Database Name與DB LINKS的關系還真是有點糾纏不清,在說清楚這個關系前,我們先來了解一下Global Database Name的概念
Global DataBase Name 概念
1. What is a global database name?
-------------------------------------------------------------------------------
The global database name is the unique name of the database. In a distributed
database system (a set of databases stored on multiple computers that typically
appears to applications as a single database) the global database name ensures
that each database is distinct from all other databases in the system. Oracle
forms a database's global database name by prefixing the database's network
domain with the individual database's name. For example: sales.us.oracle.com
and sales.uk.oracle.com.
The global database name defaults to DB_NAME.DB_DOMAIN and this value is marked
at database creation time. If you change the DB_NAME or DB_DOMAIN after the
database has been created, the value for the global database name (GLOBAL_NAME)
will not change.
說簡單一點,global database name就是用來唯一辨別資料庫的東東。global database name由兩部分組成,DB_NAME和DB_DOMAIN。在建立db link的時候,Oracle會自動将db_domain作為字尾添加上去。而且一旦加入就很難變更。是以在進行進階複制、Streams複制等配置時,最好首先将多個節點的global_name規劃好。
如何檢視Global Database Name
如下所示,可以知道global_name為一個視圖。
視圖global_name的定義可以從DBA_VIEWS裡面檢視,如下所示,它來源于sys.props$内部表
select value$ from sys.props$ where name = 'GLOBAL_DB_NAME'
那麼參數global_name與Global Database Name又沒有差別呢? 其實參數global_name僅僅表示指定資料庫的連結是否需要和它所連接配接的資料庫相同的名稱。
GLOBAL_NAMES specifies whether a database link is required to have the same name as the database to which it connects.
是以兩者完全是兩個不同的概念,但是global_name也很重要,因為它的值會影響DB LINK.接下來,我們來建立一個DB Link,如下所示
<a href="http://images2015.cnblogs.com/blog/73542/201606/73542-20160608112721605-2034613269.png"></a>
如上所示,我建立的DB Link名字為TEST,但是你查詢DBA_DB_LINKS時,你會發現連結伺服器自動加上了域名,變成了TEST.REGRESS.RDBMS.DEV.US.ORACLE.COM, 當你查詢時,使用TEST或TEST.REGRESS.RDBMS.DEV.US.ORACLE.COM都OK。
<a href="http://images2015.cnblogs.com/blog/73542/201606/73542-20160608112722324-1929857012.png"></a>
當Global Database Name隻有DB_NAME,但是沒有DB_DOMAIN時,此時,如果建立的DB Link是沒有db_domain作為字尾添加上去的,你查詢時,就必須使用全名TEST.REGRESS.RDBMS.DEV.US.ORACLE.COM,不能像上面那樣使用TEST,否則會報ORA-02019: connection description for remote database not found 錯誤。
<a href="http://images2015.cnblogs.com/blog/73542/201606/73542-20160608112724105-754130555.png"></a>
DB_LINK與GLOBAL_NAMES參數的關系
當GLOBAL_NAMES為TURE時,影響的是建立資料庫連結的那個庫對資料庫連結的使用。而不是連結到該資料庫的連結伺服器的使用。也就是說,如果一個庫(執行個體)的global_names參數設值為TRUE,則該庫連接配接其他庫的資料庫連結,其名稱必須要與被連接配接的庫的global_name相同,是否有點繞口,那麼從下面實驗看看。
伺服器B
伺服器A
在伺服器B上建立連結伺服器,連結到伺服器A
在伺服器A上啟用參數global_names,設定為TRUE。
然後在伺服器B上,再次建立連結伺服器LINK2,如下所示
從上可以看出,伺服器B上的global_names設定為TRUE是不影響伺服器A上的DB LINK的,那麼在伺服器A上,将參數global_names設定為TRUE呢?
<a href="http://images2015.cnblogs.com/blog/73542/201606/73542-20160608112725230-187190142.png"></a>
此時我們來建立一個與被連結資料庫global_name一緻的DB Link,如下所示
另外,我們來看看如何修改Global Database Name,如下所示
<a href="http://images2015.cnblogs.com/blog/73542/201606/73542-20160608112725996-1033076086.png"></a>
如上所示,修改rename global_name隻能修改DB_NAME部分,不能修改DB_DOMAIN,沒有正常的辦法去掉"."分隔符後面部分,要去掉隻能用update語句
you don't UPDATE a global_name like that. You NEVER update any data dictionary table -- never.
參考資料:
<a href="http://www.laoxiong.net/oracle_global_name.html">http://www.laoxiong.net/oracle_global_name.html</a>
<a href="http://www.laoxiong.net/database_link_global_names.html">http://www.laoxiong.net/database_link_global_names.html</a>
<a href="https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1392538395678">https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1392538395678</a>
<a href="https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=265322928260367&parent=DOCUMENT&sourceId=742140.1&id=115499.1&_afrWindowMode=0&_adf.ctrl-state=1hwssfmxb_203">https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=265322928260367&parent=DOCUMENT&sourceId=742140.1&id=115499.1&_afrWindowMode=0&_adf.ctrl-state=1hwssfmxb_203</a>