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網絡文件的配置目錄的環境變量,所以也不正確