Oracle

Oracle 11g 偵聽器失敗並出現 ORA-12514 和 ORA-12505 錯誤

  • September 20, 2017

我在我的開發機器上本地執行了一個 Oracle 11g 實例,並且可以通過 SqlPlus 直接連接到本地實例:

c:\>sqlplus ace

SQL*Plus: Release 11.2.0.2.0 Production on Mon Mar 11 11:50:20 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

Enter password:

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta

SQL> select count(*) from my_table ;

 COUNT(*)
----------
     5297

但我無法通過監聽器連接到它:

c:\>sqlplus -L "user/pw@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))"

SQL*Plus: Release 11.2.0.2.0 Production on Mon Mar 11 11:52:40 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor


SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

同樣,如果我通過 SqlDeveloper 連接,我會收到一個錯誤(儘管ORA-12505, TNS:listener does not currently know of SID given in connect descriptor)。

直到今天,星期一早上,此實例已經穩定執行了一年或更長時間。我們的企業 IT 有時確實會在周末推出新政策和更新,所以我假設發生了一些變化,但我無法弄清楚是什麼。

我已經多次重新啟動服務和監聽器,監聽器日誌沒有給出任何線索。

聽眾似乎很好:

c:\>lsnrctl status

LSNRCTL for 32-bit Windows: Version 11.2.0.2.0 - Beta on 11-MAR-2013 11:55:33

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 11.2.0.2.0 - Beta
Start Date                11-MAR-2013 11:17:30
Uptime                    0 days 0 hr. 38 min. 3 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora
Listener Log File         C:\oraclexe\app\oracle\diag\tnslsnr\FBC305BB46560\listener\alert\log.xml
Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=machine.domain.com)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
 Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
 Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

埠 1521 似乎沒問題:

c:\>netstat -an -O | find /i "1521"
 TCP    0.0.0.0:1521           0.0.0.0:0              LISTENING       4368
 TCP    169.243.90.109:55307   159.185.207.100:1521   ESTABLISHED     12416
 TCP    [::]:1521              [::]:0                 LISTENING       4368

(PID 4368 是 TNSLSNR.exe 程序。)

另外,我可以tnsping到 XE 服務:

c:\>tnsping xe

TNS Ping Utility for 32-bit Windows: Version 11.2.0.2.0 - Beta on 11-MAR-2013 12:27:47

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

Used parameter files:
C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = machine.domain.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (210 msec)

listenerr.ora文件:

SID_LIST_LISTENER =
 (SID_LIST =
   (SID_DESC =
     (SID_NAME = PLSExtProc)
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
     (PROGRAM = extproc)
   )
   (SID_DESC =
     (SID_NAME = CLRExtProc)
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
     (PROGRAM = extproc)
   )
 )

LISTENER =
 (DESCRIPTION_LIST =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
     (ADDRESS = (PROTOCOL = TCP)(HOST = machine.domain.com)(PORT = 1521))
   )
 )

DEFAULT_SERVICE_LISTENER = (XE)

此外,我不知道它是否相關,我似乎無法訪問 apex https://127.0.0.1:8080/apex(即使該權限看起來不錯)。

那麼我還應該去哪裡尋找呢?

更新請求的資訊:

SQL> show parameter service_names

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      XE
SQL> show parameter local_listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
local_listener                       string

更新 2:正如@ miracle173正確指出的那樣,聽眾不好。使用更新的“local_listener”參數現在顯示額外資訊:

Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=machine.domain.com)(PORT=1521)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
 Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
 Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
 Instance "xe", status READY, has 1 handler(s) for this service...
Service "xe" has 1 instance(s).
 Instance "xe", status READY, has 1 handler(s) for this service...
The command completed successfully

因此,感謝@YasirArsanukaev 投入的時間,我找到了一個可行的解決方案,但我無法真正解釋。

在思考這個LOCAL_LISTENER想法時,我正在閱讀另一個答案,其中說:

數據庫使用 LOCAL_LISTENER 參數來標識它應該註冊的偵聽器。預設情況下為空,根據文件,它相當於主機名:1521。

因此,我嘗試 ping 自己的主機名,但無法 - 看起來像是一些 IPv6 問題,收到一般失敗消息。

所以我從那個答案中得到了建議

SQL> alter system set LOCAL_LISTENER='(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' scope=both;
SQL> alter system register;

現在它可以工作了,大概是因為它可以解析 localhost 引用,但它無法解析實際的主機名。

引用自:https://dba.stackexchange.com/questions/36370