oracle 10g : ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
error message:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
出錯原因有很多,如果你檢查service裡面所有的服務都是started,那說明是監聽服務和資料庫執行個體服務的主動跟被動的關係原因導致的。
問題解決有2,
方法1.是讓listener主動載入服務
原因是 添加
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
)
後,在使用lsnrctl start監聽程式時會將listener的服務註冊到進程監視器(pmon)中
方法2.listener被動載入服務
在service裡面stop監聽服務和資料庫執行個體服務,然後先重新啟動監聽服務,再啟動資料庫執行個體服務。
原因是,如果沒有該內容,那麼由執行個體的pmon進程在listener中註冊服務,對listener來講,就是被動了。
這也就是為什麼先啟動監聽後啟動資料庫能夠正常串連的,反之不行的原因了。
Dynamically register 與Local_listener參數
因為一個測試庫安裝了特殊的服務之後會自動往LOCAL_LISTENER參數裡設定值,導致利用原參數檔案重建的資料庫無法自動註冊監聽服務。
同一主機的其他資料庫能自動註冊監聽服務。
<期間重試了Reload 刪除 LISTENER 重建立立一個新的LISTENER等無用功>
非預設監聽由於LOCAL_LISTENER參數的設定,變成動態註冊
改變參數
SQL> alter system set LOCAL_LISTENER='';
系統已更改。
SQL> show parameter lis
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string
recovery_parallelism integer 0
remote_listener string
終於解決了。
LSNRCTL> status
Service "TEST2" has 1 instance(s).
Instance "TEST2", status READY, has 1 handler(s) for this service...
Service "TEST2XDB" has 1 instance(s).
Instance "TEST2", status READY, has 1 handler(s) for this service...
a、PMON進程1分鐘運行一次,當監聽剛剛啟動的時候,可能服務還沒有註冊進去,這時候是不能使用此服務的
b、在修改local_listener參數時,PMON進程也會重新註冊一次
c、如果資料庫shutdown後,PMON進程也停止了,服務會從監聽中刪除,這時候只能使用OS認證的方式連入資料庫 】
ORA-12514: TNS: listener does not currently know of service requested in connect descriptor
這是個相當噁心的錯誤,就像癲癇病人一樣,不知道什麼時候就犯了,好好的用著,吃晚飯再連,就報no listener 起了監聽,之後就是這個錯誤。胡搞一通,不行,重啟OK。不知道哪裡的問題,因為是測試環境,經常會重啟,這個錯誤就想幽靈一樣時出時沒。現在的oracle怎麼那麼難伺候。。煩的多了終於下定決心要找出問題所在,於是在網上閱貼無數,終於找著了能按照一定規律解決問題的方法,就轉載了過來
關於這個錯誤,有很多種情況,我知道有2種情況,以下是網上摘錄的:
1、近日在配置Oracle 10G的流複製環境時,遇到一個問題,關閉資料庫(shutdown immediate)後,通過SQL Plus串連資料庫:conn sys/his@orc0 as sysdba,出現如下錯誤:
ORA-12514: TNS: 監聽程式當前無法識別串連描述符中請求的服務
通過重啟服務的方式啟動資料庫,再次串連卻能成功登入,也就是說在關閉資料庫狀態下無法串連伺服器。
開始以為是系統內容變數Oracle_SID的配置問題,因為機器有多個執行個體,一陣折騰後還是不能串連。後來查資料得知:
Oracle9i以後,後台進程PMON自動在監聽器中註冊在系統參數SERVICE_NAMES中定義的服務名,SERVICE_NAMES預設為DB_NAME+DOMAIN_NAME。監聽設定檔listener.ora中可以不必指定監聽的服務名。但是,當資料庫處於關閉狀態下PMON進程沒有啟動,也就不會自動註冊監聽的執行個體名,所以使用sqlplus sys/his@orc0 as sysdba 會出現ORA-12514錯誤。
如果在listener.ora檔案中指定監聽的執行個體名,則即使資料庫處於關閉狀態,仍然可以串連。
listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = G:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ORCL) ( http://blog.sina.com.cn/s/blog_4abe7f3a0100g7mm.html) - ORA- 12514: TNS: 監聽程式當前無法識別串連描述符中_
(ORACLE_HOME = G:\oracle\product\10.2.0\db_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = zyk)(PORT = 1521))
)
)
以上粗體組件為增加的內容,修改後重啟監聽服務後即可。
附:通過在lsnrctl中輸入set display verbose,然後再通過命令service查看,服務狀態為READY表示PMON自動註冊的服務名,而UNKNOWN則表示該服務是手工在LISTENER.ORA中配置的資料庫服務。
2、可能是資料庫伺服器蹦了,這樣的話,光重啟服務是不行的,重啟機器也無濟於事。可以用下面的方法解決。
開啟cmd視窗,輸入sqlplus / as sysdba;startup,完畢後即恢複正常,執行速度有點慢,耐心等待。
該問題附帶錯誤可能是:
oracle not available
shared memory realm does not exist
上述是我轉載的文章,試了一下第一種,成功了。應該是有用的。
用sqlplus登陸時報錯
ERROR:ORA-12514: TNS:listener does not currently know of service requested in connect
------解決方案--------------------------------------------------------
如果伺服器和用戶端在同一個子網中,在監聽器的設定檔中不填ip,填電腦名稱。
------解決方案--------------------------------------------------------
如果是同一網段的話,可以將你現在填寫的電腦ip改成對應的電腦名稱字,不過要求網段中電腦名稱唯一
------解決方案--------------------------------------------------------
關於LISTENER.ORA,TNSNAMES.ORA和SQLNET.ORA的存在問題
最近一次巡檢客戶的資料庫時發現一個小小異常,在$ORACLE_HOME/network/admin目錄下居然只有一個tnsnames.ora檔案,sqlnet.ora和listener.ora檔案都沒有,
檢查環境變數設定和當前LISTENER進程情況,沒有異常,嘗試通過TNS登入資料庫,都是正常的,馬上想到的問題是是否這個檔案是被誤刪掉了,其次就是這種情況下重新啟動資料庫監聽的話是否會因為沒有LISTENER.ORA檔案而無法正常啟動監聽。由於是客戶線上生產庫,所以沒有貿然嘗試,因為從監聽日誌中看到當前串連還是很頻繁的,平均一分鐘有20左右的連入,相對比較繁忙的狀況。
因為客戶的資料庫運行在10.2.0.4上,所以接下來的實驗找了一個10.2.0.5的庫來進行,版本比較接近,當然就這個問題來說可以估計只要是10G的版本都不會區別太大的。
首先將當前的三個檔案做了移動,
Wilson-> pwd
/u01/app/oracle/product/10.2.0/db_1/network/admin
Wilson-> mkdir temp
Wilson-> mv ./*.ora ./temp
然後嘗試啟動監聽和資料庫,
監聽啟動成功,檢查進程狀態正常,那麼這裡的結論是如果當前機器上只有一個執行個體在跑,並且連接埠使用的都是預設的1521,那麼沒有listener.ora檔案的話,lsnrctl會嘗試啟動預設的監聽器,監聽當前機器的1521連接埠。但是當前使用的listener.ora檔案在listener.log檔案中可以看到,
使用listener.ora檔案的日誌:
TNSLSNR for Linux: Version 10.2.0.1.0 - Production on 26-APR-2011 13:07:09
Copyright (c) 1991, 2005, Oracle. All rights reserved.
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Trace information written to /u01/app/oracle/product/10.2.0/db_1/network/trace/listener.trc
Trace level is currently 0
沒有使用listener.ora檔案的日誌:
TNSLSNR for Linux: Version 10.2.0.5.0 - Production on 21-JUL-2011 03:40:57
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Trace information written to /u01/app/oracle/product/10.2.0/db_1/network/trace/listener.trc
Trace level is currently 0
當然了,並不只是這點表面上的區別,下面是兩種情況下lsnrctl status的輸出:
使用listener.ora檔案的日誌:
Wilson-> lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 21-JUL-2011 04:50:46
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date 21-JUL-2011 03:40:57
Uptime 0 days 1 hr. 9 min. 48 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Wilson.MyCorp)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl_XPT" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
沒有使用listener.ora檔案的日誌:
Wilson-> lsnrctl status
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 21-JUL-2011 04:52:25
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 Linux: Version 10.2.0.5.0 - Production
Start Date 21-JUL-2011 04:51:32
Uptime 0 days 0 hr. 0 min. 53 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Wilson.MyCorp)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl_XPT" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
可見兩種情況下,首先是否啟動外部監聽是有區別的,也就是說如果程式中使用到了EXTPROC方式,那麼不配置listener.ora就可能會有問題,其次才是是否使用了參數檔案的區別。
至於sqlnet.ora檔案的存在與否,這個不用多說,如果沒有sqlnet.ora檔案,ORACLE會預設使用TNSNAMES,ONAMES,HOSTNAME三種方式來嘗試串連,
上面是三個檔案都不存在情況下的實驗,
Wilson-> sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Jul 21 05:09:47 2011
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
SQL> conn scott/tiger
Connected.
SQL> conn
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Warning: You are no longer connected to ORACLE.
SQL> conn
Connected.
SQL> conn
Connected.
(連接埠號碼如果是1521,可以省略)
下面實驗有sqlnet.ora,但是只配置使用TNSNAMES方式,
#NAMES.DIRECTORY_PATH= (HOSTNAME, TNSNAMES, EZCONNECT)
NAMES.DIRECTORY_PATH= (TNSNAMES)
Wilson-> sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Jul 21 05:14:15 2011
、
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
SQL> conn / as sysdba
Connected.
SQL> conn scott/tiger
Connected.
SQL> conn
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Warning: You are no longer connected to ORACLE.
可見沒有HOSTNAME方式或者EZCONNECT方式都會導致這種簡單串連方式的失敗。
SQL> conn
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
Warning: You are no longer connected to ORACLE.
SQL> conn
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
至於HOSTNAME和EZCONNECT這兩種方式,個人感覺在10g中已經沒有什麼大的區別,感覺是ORACLE10g中人為製造出來的一個NEW FEATURE,而相應的之前的HOSTNAME方式已經被取代,
在10.2.0.5這個版本上,我無法實驗成功HOSTNAME直接方式串連成功。
下面引用ORACLE官方的說法,
Oracle 10g Easy Connect Naming
Easy connect naming is not allowed in large or complex environments that require additional connect information. (Large or complex environments employ advanced features, such as connection pooling, external procedure calls, or Heterogeneous Services.) In these cases, you must use another naming method.
With Oracle 10g, easy connect naming is automatically configured by default at installation. However, before attempting to use this feature, you may want to ensure that EZCONNECT is specified first in the names.directory_path parameter in the sqlnet.ora file. The names.directory_path parameter is used to specify the order of naming methods that Oracle Net can use to resolve connect identifiers to connect descriptors. Verification is easy. To verify that the names.directory_path settings are correct, follow these instructions:
Start Oracle Net Manager.
In the navigator pane, expand Local > Profile.
From the list in the right pane, select Naming.
Click the Methods tab. Ensure that EZCONNECT is listed in the Selected Methods list. If it is not, then proceed to Step 5.
From the Available Methods list, select EZCONNECT, then click the right-arrow button.
From the Selected Methods list, select EZCONNECT, then use the Promote button to move the selection to the top of the list.
Choose File > Save Network Configuration. The sqlnet.ora file updates with the names.directory_path parameter, listing ezconnect first: names.directory_path =(ezconnect, tnsnames).
從上面的表述中也可以看出來,其實HOSTNAME串連方式已經是保留對之前版本的支援而已,11gR2WIN32版本中,ORACLE的NETMGR程式中還可以看到這種串連方式,但是更常被用到的NETCA程式中已經看不到這個串連方式的存在了。
最後說下tnsnames.ora,這個檔案其實取決於當前應用所需要的串連方式,在TCP/IP環境下基本上是必不可少的,否則就只能通過類似JAVA連接字串的形式來連庫了。如果需要使用TNSNAMES,也就是本地服務名方式來串連資料庫,那麼就是必須的要使用到這個檔案了。