The tnsnames.ora file has an entry for the service alias ORCL as follows:
The TNS ping command executes successfully when tested with ORCL; however, from the
same OS user session, you are not able to connect to the database instance with the
following command:
SQL > CONNECT scott/tiger@orcl
What could be the reason for this?
A. The listener is not running on the database node.
B. The TNS_ADMIN environment variable is set to the wrong value.
C. The orcl.oracle.com database service is not registered with the listener.
D. The DEFAULT_DOMAIN parameter is set to the wrong value in the sqlnet.ora file.
E. The listener is running on a different port.
Answer: C
正确答案解析:
这儿讨论的是,tnsping这个命令究竟是检测什么东西
我们来做下简单的测试
我们也创建一个跟题目一样的名称解析
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = kiwi)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.oracle.com)
)
)
查看监听的配置
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = kiwi)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
可以看到,还是使用的是静态的监听
看看监听的状态
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 18-MAR-2016 22:01:18
Uptime 0 days 17 hr. 27 min. 5 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/12.1.0/grid/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/kiwi/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=kiwi)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=kiwi)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM", status READY, has 1 handler(s) for this service...
Service "enmo" has 1 instance(s).
Instance "enmo", status READY, has 1 handler(s) for this service...
Service "enmoXDB" has 1 instance(s).
Instance "enmo", status READY, has 1 handler(s) for this service...
Service "kiwi" has 1 instance(s).
Instance "kiwi", status READY, has 1 handler(s) for this service...
Service "kiwiXDB" has 1 instance(s).
Instance "kiwi", status READY, has 1 handler(s) for this service...
The command completed successfully
1,我们先把监听关闭
[15:28:39 oracle(grid)@kiwi admin]$ lsnrctl stop
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 19-MAR-2016 15:39:55
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=kiwi)(PORT=1521)))
The command completed successfully
测试
[15:40:23 oracle(db)@kiwi admin]$ tnsping ORCL
TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 19-MAR-2016 15:40:47
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = kiwi)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.oracle.com)))
TNS-12541: TNS:no listener
监听报错
2.启动监听,但是service没有注册到监听中
查看监听的状态
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=kiwi)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 19-MAR-2016 15:41:17
Uptime 0 days 0 hr. 0 min. 55 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/12.1.0/grid/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/kiwi/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=kiwi)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=kiwi)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM", status READY, has 1 handler(s) for this service...
Service "enmo" has 1 instance(s).
Instance "enmo", status READY, has 1 handler(s) for this service...
Service "enmoXDB" has 1 instance(s).
Instance "enmo", status READY, has 1 handler(s) for this service...
Service "kiwi" has 1 instance(s).
Instance "kiwi", status READY, has 1 handler(s) for this service...
Service "kiwiXDB" has 1 instance(s).
Instance "kiwi", status READY, has 1 handler(s) for this service...
The command completed successfully
可以看到,没有orcl.oracle.com的service
这个时候进行测试
[15:40:47 oracle(db)@kiwi admin]$ tnsping ORCL
TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 19-MAR-2016 15:43:26
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = kiwi)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.oracle.com)))
OK (0 msec)
能够ping通,我们直接使用本地连接测试
[15:43:26 oracle(db)@kiwi admin]$ sqlplus sys/oracle@ORCL
SQL*Plus: Release 12.1.0.2.0 Production on Sat Mar 19 15:44:13 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
并不能进行连接,就是我们考题中的情况,
所以,我们得出结论
1.tnsping 命令可以检查tcp协议是否已同,俗称我们说的网络通不通
2.tnsping命令监听服务器上的监听是否已开启
3.tnsping命令不检测服务器上的监听的服务名,所以tnsping通,不代表就能连通。
对于答案B,TNS_ADMIN参数,是修改oracle网络文件的配置目录的环境变量,所以也不正确