先写结论,tnsping命令只识别到tnsname.ora文件中的ip和端口号,而对之后的service_name或者sid不进行识别,因此tnsping能ping通并不意味着sqlplus **/**@tnsname一定能登录。
测试:
本机IP:172.16.4.183
tnsname文件内容:
DRB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.137)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(sid = drb)
)
)
由于172.16.4.137的监听起着,尝试tnsping drb
[oracle@dbra admin]$ tnsping drb
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 10-APR-2012 16:05:21
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.137)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (sid = drb)))
OK (10 msec)
由于本来就已知137这个IP并不是想要的数据库所在ip,但是对tnsping能通产生疑惑
sqlplus登录:
[oracle@dbra admin]$ sqlplus sys/oracle@drb as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Apr 10 16:05:42 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12505: TNS:listener does not currently know of SID given in connect
descriptor
Enter user-name:
172.16.4.137上的监听状态如下:
LSNRCTL for 32-bit Windows: Version 10.2.0.4.0 - Production on 10-4月 -2012 16:0
7:09
Copyright (c) 1991, 2007, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=VQBDTC9FC795994)(PORT=1521)
))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for 32-bit Windows: Version 10.2.0.4.0 - Produ
ction
启动日期 10-4月 -2012 09:00:03
正常运行时间 0 天 7 小时 7 分 7 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 F:\oracle\product\10.2.0\db_1\network\admin\listener.o
ra
监听程序日志文件 F:\oracle\product\10.2.0\db_1\network\log\listener.log
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=VQBDTC9FC795994)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC0ipc)))
服务摘要..
服务 "PLSExtProc" 包含 1 个例程。
例程 "PLSExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "mangdb" 包含 1 个例程。
例程 "mangdb", 状态 READY, 包含此服务的 1 个处理程序...
服务 "mangdbXDB" 包含 1 个例程。
例程 "mangdb", 状态 READY, 包含此服务的 1 个处理程序...
服务 "mangdb_XPT" 包含 1 个例程。
例程 "mangdb", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.137)(PORT = 1521))
# (CONNECT_DATA =
# (SERVER = DEDICATED)
# (sid = drb)
# )
)
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.137)(PORT = 1521)))
OK (10 msec)