您好,登錄后才能下訂單哦!
Oracle中service_name和service_names的關系是什么,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
從oracle9i開始,后臺進程PMON自動在監聽器中注冊初始化參數SERVICE_NAMES中定義的服務名,SERVICE_NAMES默認為db_name.db_dimain。客戶端tns配置中SERVICE_NAME的名稱必須是SERVICE_NAMES或其中的一個NAME。
1 listenter.ora文件中的 GLOBAL_DBNAME和tnsnames.ora文件SERVICE_NAME的配置一樣時,GLOBAL_DBNAME = A, 連接串中的SERVICE_NAME = A,此時就可以連接上數據庫。根據tnsnames.ora文件中的連接串中的SERVICE_NAME = A 找到監聽器listener.ora中的SID_DESC = (GLOBAL_DBNAME= A),之后在找到SID_NAME, 來連接到數據庫實例。
2listenter.ora文件中的 GLOBAL_DBNAME和tnsnames.ora文件的SERVICE_NAME的配置一樣時,tnsnames.ora中的SERVICE_NAME要與參數文件中的SERVICE_NAMES 參數一樣或者是其中之一,否則無法通過tns連接到數據庫。
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)
)
)
監聽文件中的配置信息:
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
參數service_names是靜態的,必須重啟機器才能夠生效。
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
進行連接測試:
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
查看監聽服務狀態,可以知道共有6個監聽服務名。
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 <machine: rac3, pid: 17581>
(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=45357))
The command completed successfully
tnsnames.ora文件中的service_name 和 參數文件中的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 = ----連接標識,可以為任意值
(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 <machine: rac3, pid: 17581>
(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,并相應的修改listener.ora文件中的global_dbname的值為lily ,也可以成功連接數據庫。
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 --動態監聽里面沒有lily 這樣的服務
YANG@yangdb-rac3> exit
說明:如果 參數文件中的service_names沒有lily這個值,但是listener.ora文件中有與之對應的GLOBAL_DBNAME,并且已經啟動了靜態監聽服務,則sqlplus通過@lily也可以連接數據庫。
如果沒有啟動靜態監聽,即沒有lily 這樣的service,則不可以連接數據庫,(當然修改過之后沒有執行reload 或沒有重啟監聽,則還可以連接,因為之前存在,這樣的例子不討論)
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
編輯過之后重新啟動數據庫(可選),重啟監聽,目的重新注冊服務,去掉靜態監聽的服務。
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 --沒有靜態監聽服務,這時只能通過動態監聽的服務來連接到數據庫。
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 --報錯,監聽沒有lily這樣的服務
Enter user-name: ^[[
--通過pmon動態監聽的服務名來連接數據庫。
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
看完上述內容,你們掌握Oracle中service_name和service_names的關系是什么的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。