【DBLINK】“ORA-02085: database link %s connects to %s”故障排查及處理策略兩則

secooler發表於2011-05-19
  今天在使用連線遠端資料庫例項的database link時遭遇“ORA-02085: database link DBLINK_TO_SECGC connects to SECGC”報錯,導致遠端資料無法獲取。本文給出ORA-02085報錯過程、以及兩種處理方法。該問題處理過程具有普遍參考意義。

  約定:雖然這裡secdb例項和secgc例項都在一套物理伺服器上。我們在此假設secdb作為本地資料庫,secgc作為遠端資料庫

1.在遠端secgc資料庫例項user_secgc使用者中建立基表T並初始化資料
secdb@secdb1 /home/oracle$ export ORACLE_SID=secgc
secgc@secdb1 /home/oracle$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 19 20:24:43 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

sys@secgc> create user user_secgc identified by user_secgc;

User created.

sys@secgc> grant connect,resource to user_secgc;

Grant succeeded.

sys@secgc> conn user_secgc/user_secgc
Connected.
user_secgc@secgc> create table t (x varchar2(10));

Table created.

user_secgc@secgc> insert into t values ('secooler');

1 row created.

user_secgc@secgc> commit;

Commit complete.

user_secgc@secgc> select * from t;

X
----------
secooler

2.在本地secdb例項上建立database link連線到secgc例項的user_secgc使用者
1)在本地secdb例項上建立到secgc例項的連線串
secdb@secdb1 /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
SECGC =
  (DESCRIPTION =
    (address = (protocol = tcp)(host = secdb1)(port = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = secgc)
    )
  )

2)在本地secdb資料庫例項上建立database link
secdb@secdb1 /home/oracle$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 19 20:31:06 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

sys@secdb> create public database link dblink_to_secgc connect to user_secgc identified by user_secgc using 'SECGC';

Database link created.

3.測試database link是否可用,出現ORA-02085錯誤
sys@secdb> select * from t@dblink_to_secgc;
select * from t@dblink_to_secgc
                *
ERROR at line 1:
ORA-02085: database link DBLINK_TO_SECGC connects to SECGC

4.報錯原因
1)獲取ORA-02085錯誤的參考資訊
secdb@secdb1 /home/oracle$ oerr ora 2085
02085, 00000, "database link %s connects to %s"
// *Cause: a database link connected to a database with a different name.
//  The connection is rejected.
// *Action: create a database link with the same name as the database it
//  connects to, or set global_names=false.
//

2)從報錯資訊的描述上已經可以得到問題的原因和處理方法
錯誤原因:使用的dblink名字與要連線的資料庫名字不相同
處理方法:有兩種處理方法
第一種處理方法:建立與對方資料庫名字相同的dblink
第二種處理方法:調整資料庫引數global_names值為false,取消這種限制

5.故障處理方法兩則
按照上面給出的兩種處理方法進行驗證。
1)第一種處理方法:使用與遠端資料庫名字相同的dblink
(1)獲取遠端資料庫名字
sys@secgc> select * from global_name;

GLOBAL_NAME
----------------------
SECGC

(2)建立與遠端資料庫名字相同的dblink
sys@secdb> create public database link secgc connect to user_secgc identified by user_secgc using 'SECGC';

Database link created.

(3)在global_names引數為TRUE的時候測試dblink可用性
注意:僅需調整使用dblink端的資料庫引數即可。
sys@secdb> show parameter global_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------
global_names                         boolean     TRUE

sys@secdb> select * from t@secgc;

X
----------
secooler

成功。

2)第二種處理方法:調整資料庫引數global_names值為false
sys@secdb> show parameter global_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------
global_names                         boolean     FALSE

sys@secdb> alter system set global_names=FALSE;

System altered.

sys@secdb> show parameter global_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------
global_names                         boolean     FALSE

sys@secdb> select * from t@dblink_to_secgc;

X
----------
secooler

可見,此時dblink連線遠端資料庫例項獲取資料成功。

6.10g官方文件中關於global_names引數的描述
官方文件參考連結:

GLOBAL_NAMES

Property Description
Parameter type Boolean
Default value false
Modifiable ALTER SESSION, ALTER SYSTEM
Range of values true | false
Basic No

GLOBAL_NAMES specifies whether a database link is required to have the same name as the database to which it connects.

If the value of GLOBAL_NAMES is false, then no check is performed. If you use or plan to use distributed processing, then Oracle recommends that you set this parameter to true to ensure the use of consistent naming conventions for databases and links in a networked environment.


7.小結
  本文圍繞global_names引數對dblink使用過程中出現的ORA-02085錯誤展開的分析和驗證。建議對資料庫常用引數的功能和用法諳熟於心。

Good luck.

secooler
11.05.19

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-695851/,如需轉載,請註明出處,否則將追究法律責任。

相關文章