Tnsping OK不代表listener正常,近日遇到一个问题,环境是11Gr2 RAC,tnsping正常,但是实际访问数据库报错

   
   
   
   
  • ORA-12545: 因目标主机或对象不存在, 连接失败 

代码如下

   
   
   
   
  1. [grid@grida ~]$ srvctl config scan 
  2. SCAN name: scan-grid, Network: 1/172.16.200.0/255.255.255.0/eth0 
  3. SCAN VIP name: scan1, IP: /scan-grid/172.16.200.219 
  4.  
  5. tnsname file: 
  6. XYZ = 
  7.  (DESCRIPTION = 
  8.    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.200.219)(PORT = 1521)) 
  9.    (LOAD_BALANCE = yes
  10.    (CONNECT_DATA = 
  11.      (SERVER = DEDICATED
  12.      (SERVICE_NAME = XYZ
  13.    ) 
  14.  ) 
  15.  
  16.  
  17. scanip:172.16.200.219 
  18. C:\Users\B010910>tnsping xyz 
  19.  
  20. TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 07-5月 - 
  21. 2012 09:02:43 
  22.  
  23. Copyright (c) 1997, 2010, Oracle.  All rights reserved. 
  24.  
  25. 已使用的参数文件: 
  26. d:\oracle\product\11.2.0\dbhome_1\network\admin\sqlnet.ora 
  27.  
  28.  
  29. 已使用 TNSNAMES 适配器来解析别名 
  30. 尝试连接 (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.200.219)(PORT 
  31. 1521)) (LOAD_BALANCE = yes) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME 
  32. = XYZ))) 
  33. OK (60 毫秒) 
  34.  
  35. C:\Users\B010910>sqlplus /nolog 
  36.  
  37. SQL*Plus: Release 11.2.0.1.0 Production on 星期一 5月 7 09:03:06 2012 
  38.  
  39. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  40.  
  41. SQL> conn system/0racle@xyz; 
  42. ERROR: 
  43. ORA-12545: 因目标主机或对象不存在, 连接失败  

经过分析,tnsping正常只能说明,该IP、1521端口、以及listener status是正常的。但是在实际需要访问instance的时候,并没有能够正常连接,主要问题就是instance并没有正常的注册到listener中,需要进一步分析没有注册的原因。

  查看CRS资源 

   
   
   
   
  1. [oracle@qr01db01 ~]$ crsctl status res -t 
  2. -------------------------------------------------------------------------------- 
  3. NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
  4. -------------------------------------------------------------------------------- 
  5. Local Resources 
  6. -------------------------------------------------------------------------------- 
  7. ora.DATA_QR01.dg 
  8.                ONLINE  ONLINE       qr01db01                                     
  9.                ONLINE  ONLINE       qr01db02                                     
  10. ora.DBFS_DG.dg 
  11.                ONLINE  ONLINE       qr01db01                                     
  12.                ONLINE  ONLINE       qr01db02                                     
  13. ora.LISTENER.lsnr 
  14.                ONLINE  ONLINE       qr01db01                                     
  15.                ONLINE  ONLINE       qr01db02                                     
  16. ora.RECO_QR01.dg 
  17.                ONLINE  ONLINE       qr01db01                                     
  18.                ONLINE  ONLINE       qr01db02                                     
  19. ora.asm 
  20.                ONLINE  ONLINE       qr01db01                 Started             
  21.                ONLINE  ONLINE       qr01db02                                     
  22. ora.gsd 
  23.                OFFLINE OFFLINE      qr01db01                                     
  24.                OFFLINE OFFLINE      qr01db02                                     
  25. ora.net1.network 
  26.                ONLINE  ONLINE       qr01db01                                     
  27.                ONLINE  ONLINE       qr01db02                                     
  28. ora.ons 
  29.                ONLINE  ONLINE       qr01db01                                     
  30.                ONLINE  ONLINE       qr01db02                                     
  31. ora.registry.acfs 
  32.                ONLINE  ONLINE       qr01db01                                     
  33.                ONLINE  ONLINE       qr01db02                                     
  34. -------------------------------------------------------------------------------- 
  35. Cluster Resources 
  36. -------------------------------------------------------------------------------- 
  37. ora.LISTENER_SCAN1.lsnr 
  38.       1        ONLINE  ONLINE       qr01db01                                     
  39. ora.cvu 
  40.       1        ONLINE  ONLINE       qr01db01                                     
  41. ora.dbm.db 
  42.       1        ONLINE  ONLINE       qr01db02                 Open                
  43.       2        ONLINE  ONLINE       qr01db01                 Open                
  44. ora.oc4j 
  45.       1        ONLINE  ONLINE       qr01db01                                     
  46. ora.qr01db01.vip 
  47.       1        ONLINE  ONLINE       qr01db01                                     
  48. ora.qr01db02.vip 
  49.       1        ONLINE  ONLINE       qr01db02                                     
  50. ora.scan1.vip 
  51.       1        ONLINE  ONLINE       qr01db01                                     

查看instance是否正常注册

   
   
   
   
  1. [oracle@qr01db01 ~]$ ps -ef | grep tns 
  2. oracle    3049     1  0 May02 ?        00:00:02 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit 
  3. oracle    3057     1  0 May02 ?        00:00:02 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit 
  4. oracle    5677  5606  0 10:33 pts/0    00:00:00 grep tns 
  5.  
  6. [oracle@qr01db01 ~]$ lsnrctl service LISTENER_SCAN1 
  7.  
  8. LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 07-MAY-2012 10:33:27 
  9.  
  10. Copyright (c) 1991, 2010, Oracle.  All rights reserved. 
  11.  
  12. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) 
  13. Services Summary... 
  14. Service "dbm.example.com" has 2 instance(s).  <<<<<<<<<<<<<<<<<这里显示已经将实例注册
  15.   Instance "dbm1", status READY, has 1 handler(s) for this service... 
  16.     Handler(s): 
  17.       "DEDICATED" established:0 refused:0 state:ready 
  18.          REMOTE SERVER 
  19.          (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.2.24)(PORT=1521))) 
  20.   Instance "dbm2", status READY, has 1 handler(s) for this service... 
  21.     Handler(s): 
  22.       "DEDICATED" established:0 refused:0 state:ready 
  23.          REMOTE SERVER 
  24.          (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.2.25)(PORT=1521))) 
  25. Service "dbmXDB.example.com" has 2 instance(s). 
  26.   Instance "dbm1", status READY, has 1 handler(s) for this service... 
  27.     Handler(s): 
  28.       "D000" established:0 refused:0 current:0 max:1022 state:ready 
  29.          DISPATCHER  
  30.          (ADDRESS=(PROTOCOL=tcp)(HOST=qr01db01.example.com)(PORT=61048)) 
  31.   Instance "dbm2", status READY, has 1 handler(s) for this service... 
  32.     Handler(s): 
  33.       "D000" established:0 refused:0 current:0 max:1022 state:ready 
  34.          DISPATCHER  
  35.          (ADDRESS=(PROTOCOL=tcp)(HOST=qr01db02.example.com)(PORT=46543)) 
  36. The command completed successfully 

查看parameter参数 

   
   
   
   
  1. [oracle@qr01db01 ~]$ sqlplus / as sysdba 
  2.   
  3. SQL> show parameter remote_listener
  4.  
  5. NAME                                 TYPE        VALUE 
  6. ------------------------------------ ----------- ------------------------------ 
  7. remote_listener                      string      qr01-scan:1521 
  8.  
  9.  
  10. SQL> show parameter local_listener

    NAME TYPE VALUE
    ------------------------------------ ----------- ------------------------------
    local_listener string (DESCRIPTION=(ADDRESS_LIST=(AD
    DRESS=(PROTOCOL=TCP)(HOST=192.
    0.2.24)(PORT=1521))))

参考hosts文件设置 

   
   
   
   
  1. [oracle@qr01db01 ~]$ cat /etc/hosts 
  2. 127.0.0.1       localhost.localdomain           localhost 
  3.  
  4. 192.0.2.11      qr01cel01.example.com           qr01cel01 
  5. 192.0.2.12      qr01cel02.example.com           qr01cel02 
  6. 192.0.2.13      qr01cel03.example.com           qr01cel03 
  7. 192.0.2.14      qr01db01.example.com            qr01db01 
  8. 192.0.2.15      qr01db02.example.com            qr01db02 
  9.  
  10. 192.0.2.21      qr01-scan.example.com           qr01-scan 
  11. 192.0.2.24      qr01db01-vip.example.com        qr01db01-vip 
  12. 192.0.2.25      qr01db02-vip.example.com        qr01db02-vip 
  13.  
  14. 192.168.1.11    qr01cel01-priv.example.com      qr01cel01-priv 
  15. 192.168.1.12    qr01cel02-priv.example.com      qr01cel02-priv 
  16. 192.168.1.13    qr01cel03-priv.example.com      qr01cel03-priv 
  17. 192.168.1.14    qr01db01-priv.example.com       qr01db01-priv 
  18. 192.168.1.15    qr01db02-priv.example.com       qr01db02-priv 

 

     以上信息都确认正常,基本就能将listener的问题解决了。