在远端客户端连接RAC数据库时,通过统一的服务名连接时经常会出现ORA-12545错误。在METALINK上查询了一下,竟是Oracle的一个小bug。
环境:ORACLE 11G R2 RAC数据库,两节点。
现象:
[oracle@ted35 ~]$sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期五 6月 15 11:57:00 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn sys/ted@123e@prodb as sysdba;
ERROR:
ORA-12545: 因目标主机或对象不存在, 连接失败
故障分析:用tnsping检查一下,发现可以ping通,这是因为tnsping只检查IP地址和端口是否能连通,至于数据库实例状态,监听注册了哪些服务这些,它是不检查的。
我们看一下本地数据库TNSNAMES的配置:
TESTRAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.58.12.124)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.58.12.125)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = 10.58.12.124)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
Oracle在文档Note:364855.1:RAC Connection Redirected To Wrong Host/IP ORA-12545中进行了描述,并给出了解决方法:修改数据库中的初始化参数LOCAL_LISTENER(注:这种方法在修改初始化参数后,www.linuxidc.com 需要重启监听,重启实例)
SQL>conn / as sysdba;
Connected.
SQL> ALTER SYSTEM SET LOCAL_LISTENER = '(ADDRESS = (PROTOCOL = TCP)(HOST = 10.58.12.124)(PORT = 1521)) 'SID = 'prodb1';
系统已更改。
登录另外一个节点
SQL>conn / as sysdba;
Connected.
SQL> ALTER SYSTEM SET LOCAL_LISTENER = '(ADDRESS = (PROTOCOL = TCP)(HOST = 10.58.12.125)(PORT = 1521))' SID = 'prodb2';
系统已更改。
设置之后,再次尝试连接数据库:
SQL> conn sys/ted@123e@prodb as sysdba;
Connected.
SQL> conn sys/ted@789e@prodb as sysdba;
Connected.
修改之后,没有再次出现同样的错误。
我们也可以通过只修改客户端hosts文件的方式,来解决这个问题。
首先在linux主机上修改HOSTS文件
root@prodb1 # vi /etc/hosts
#
10.58.12.120 prodb1-public # Public
10.58.12.124 prodb1 # Virtual
23.23.23.120 prodb1-priv # Private
10.58.12.121 prodb2-public # Public
10.58.12.125 prodb2 # Virtual
23.23.23.121 prodb2-priv # Private
10.58.12.126 prodb-scan # SCAN