Oracle中service_name和service_names的關(guān)系是什么,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
創(chuàng)新互聯(lián)專注于梁園網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供梁園營銷型網(wǎng)站建設(shè),梁園網(wǎng)站制作、梁園網(wǎng)頁設(shè)計(jì)、梁園網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造梁園網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供梁園網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
從oracle9i開始,后臺(tái)進(jìn)程PMON自動(dòng)在監(jiān)聽器中注冊初始化參數(shù)SERVICE_NAMES中定義的服務(wù)名,SERVICE_NAMES默認(rèn)為db_name.db_dimain??蛻舳藅ns配置中SERVICE_NAME的名稱必須是SERVICE_NAMES或其中的一個(gè)NAME。
1 listenter.ora文件中的 GLOBAL_DBNAME和tnsnames.ora文件SERVICE_NAME的配置一樣時(shí),GLOBAL_DBNAME = A, 連接串中的SERVICE_NAME = A,此時(shí)就可以連接上數(shù)據(jù)庫。根據(jù)tnsnames.ora文件中的連接串中的SERVICE_NAME = A 找到監(jiān)聽器listener.ora中的SID_DESC = (GLOBAL_DBNAME= A),之后在找到SID_NAME, 來連接到數(shù)據(jù)庫實(shí)例。
2listenter.ora文件中的 GLOBAL_DBNAME和tnsnames.ora文件的SERVICE_NAME的配置一樣時(shí),tnsnames.ora中的SERVICE_NAME要與參數(shù)文件中的SERVICE_NAMES 參數(shù)一樣或者是其中之一,否則無法通過tns連接到數(shù)據(jù)庫。
tnsnames.ora文件中的service_name 和 listener.oar文件中的GLOBAL_DBNAME一樣的情況:
查看tnsnames.ora文件的配置信息:
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>cat tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
YANGDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb)
)
)
YANGDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb1)
)
)
YANGDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb2)
)
)
YANGDB3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb3)
)
)
RAC =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.250.7.200)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rac)
)
)
監(jiān)聽文件中的配置信息:
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>cat listener.ora
# listener.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = yangdb)
(ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
(SID_NAME = yangdb)
)
)
yangdb =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/oracle
參數(shù)service_names是靜態(tài)的,必須重啟機(jī)器才能夠生效。
oracle@rac3:/home/oracle>sqlplus "/as sysdba"
SYS@yangdb-rac3> alter system set service_names='yangdb,yangdb1,yangdb2,yangdb3' scope=both;
System altered.
SYS@yangdb-rac3> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@yangdb-rac3> startup
ORACLE instance started.
Database mounted.
Database opened.
SYS@yangdb-rac3> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3
進(jìn)行連接測試:
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@yangdb1
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:12:13 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
YANG@yangdb-rac3> show parameter service_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3
YANG@yangdb-rac3> exit
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@yangdb2
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:57:26 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
YANG@yangdb-rac3> show parameter service_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3
YANG@yangdb-rac3> exit
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@yangdb3
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:57:38 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
YANG@yangdb-rac3> show parameter service_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3
YANG@yangdb-rac3> exit
查看監(jiān)聽服務(wù)狀態(tài),可以知道共有6個(gè)監(jiān)聽服務(wù)名。
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>lsnrctl service
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-OCT-2011 11:59:11
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "PLSExtProc"has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "yangdb" has 2 instance(s).
Instance "yangdb", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb1"has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb2"has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb3"has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdbXDB"has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER
(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=45357))
The command completed successfully
tnsnames.ora文件中的service_name 和 參數(shù)文件中的service_name不一樣的情況:
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>vi tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
lily= ----連接標(biāo)識(shí),可以為任意值
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = lily)
)
)
YANGDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb1)
)
)
YANGDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb2)
)
)
YANGDB3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb3)
)
)
"tnsnames.ora" 60L, 1198C 已寫入
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>vi listener.ora
# listener.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = lily)
(ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
(SID_NAME = yangdb)
)
)
yangdb =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/oracle
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-OCT-2011 10:58:30
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 27-SEP-2011 21:47:16
Uptime 22 days 13 hr. 11 min. 14 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/rac3/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "yangdb" has 2 instance(s).
Instance "yangdb", status UNKNOWN, has 1 handler(s) for this service...
Instance "yangdb", status READY, has 1 handler(s) for this service...
Service "yangdb1" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Service "yangdb2" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Service "yangdb3" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Service "yangdbXDB" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
The command completed successfully
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>lsnrctl service
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-OCT-2011 10:58:37
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "yangdb" has 2 instance(s).
Instance "yangdb", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb1" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb2" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdb3" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:4 refused:0 state:ready
LOCAL SERVER
Service "yangdbXDB" has 1 instance(s).
Instance "yangdb", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER
(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=45357))
The command completed successfully
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>lsnrctl reload
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-OCT-2011 10:58:45
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>
更改tnsnames.ora文件中的service_name的值 yangdb為lily,并相應(yīng)的修改listener.ora文件中的global_dbname的值為lily ,也可以成功連接數(shù)據(jù)庫。
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>vi tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
lily =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = lily)
)
)
YANGDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb1)
)
)
YANGDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb2)
)
)
YANGDB3 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = yangdb3)
)
)
"tnsnames.ora" 60L, 1196C 已寫入
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@lily
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:00:11 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
YANG@yangdb-rac3> show parameter service_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3 --動(dòng)態(tài)監(jiān)聽里面沒有l(wèi)ily 這樣的服務(wù)
YANG@yangdb-rac3> exit
說明:如果 參數(shù)文件中的service_names沒有l(wèi)ily這個(gè)值,但是listener.ora文件中有與之對應(yīng)的GLOBAL_DBNAME,并且已經(jīng)啟動(dòng)了靜態(tài)監(jiān)聽服務(wù),則sqlplus通過@lily也可以連接數(shù)據(jù)庫。
如果沒有啟動(dòng)靜態(tài)監(jiān)聽,即沒有l(wèi)ily 這樣的service,則不可以連接數(shù)據(jù)庫,(當(dāng)然修改過之后沒有執(zhí)行reload 或沒有重啟監(jiān)聽,則還可以連接,因?yàn)橹按嬖?,這樣的例子不討論)
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>vi listener.ora
# listener.ora Network Configuration File: /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
# Generated by Oracle configuration tools.
# SID_LIST_LISTENER =
# (SID_LIST =
# (SID_DESC =
# (SID_NAME = PLSExtProc)
# (ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
# (PROGRAM = extproc)
# )
# (SID_DESC =
# (GLOBAL_DBNAME = lily)
# (ORACLE_HOME = /opt/oracle/11.2.0/alifpre)
# (SID_NAME = yangdb)
# )
# )
yangdb =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/oracle
編輯過之后重新啟動(dòng)數(shù)據(jù)庫(可選),重啟監(jiān)聽,目的重新注冊服務(wù),去掉靜態(tài)監(jiān)聽的服務(wù)。
SYS@yangdb-rac3> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@yangdb-rac3> startup
Database mounted.
Database opened.
SYS@yangdb-rac3>
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-OCT-2011 11:11:24
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /opt/oracle/11.2.0/alifpre/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/rac3/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 20-OCT-2011 11:11:24
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/11.2.0/alifpre/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/rac3/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=1521)))
The listener supports no services --沒有靜態(tài)監(jiān)聽服務(wù),這時(shí)只能通過動(dòng)態(tài)監(jiān)聽的服務(wù)來連接到數(shù)據(jù)庫。
The command completed successfully
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@lily
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:11:35 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor --報(bào)錯(cuò),監(jiān)聽沒有l(wèi)ily這樣的服務(wù)
Enter user-name: ^[[
--通過pmon動(dòng)態(tài)監(jiān)聽的服務(wù)名來連接數(shù)據(jù)庫。
oracle@rac3:/opt/oracle/11.2.0/alifpre/network/admin>sqlplus yang/yang@yangdb1
SQL*Plus: Release 11.2.0.1.0 Production on Thu Oct 20 11:12:13 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
YANG@yangdb-rac3> show parameter service_
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string yangdb,yangdb1,yangdb2,yangdb3
看完上述內(nèi)容,你們掌握Oracle中service_name和service_names的關(guān)系是什么的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!