listener.ora檔案與tnsnames.ora之間的關係

paulyibinyi發表於2007-12-18

listener.ora 檔案裡面的內容如下:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = d10063)(PORT = 1521))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = D:\oracle\ora92)
      (PROGRAM = extproc)
      (GLOBAL_DBNAME = gsid)
      (ORACLE_HOME = D:\oracle\ora92)
      (SID_NAME = paul)
      (GLOBAL_DBNAME = paul)
      (ORACLE_HOME = D:\oracle\ora92)
      (SID_NAME = paul)
    )
  )

tnsnames.ora檔案內容如下:

PAUL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.163)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = paul)
    )
  )

PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.163)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = gsid)
    )
  )

SQL> show parameter service_names

NAME                                 TYPE        VALUE
------------------------------------ ----------- -----------
service_names                        string      gsid, paul,paultest

由以上可知道  監聽器提供靜態和動態註冊服務名

而tnsnames.ora檔案 根據服務名進行客戶端連線

而primary這些是連線字串

 

C:\Documents and Settings\Paul Yi>lsnrctl status

LSNRCTL for 32-bit Windows: Version 9.2.0.4.0 - Production on 18-DEC-2007 09:47:
21

Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=d10063)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 9.2.0.4.0 - Produc
tion
Start Date                18-DEC-2007 09:40:34
Uptime                    0 days 0 hr. 6 min. 46 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Parameter File   D:\oracle\ora92\network\admin\listener.ora
Listener Log File         D:\oracle\ora92\network\log\listener1.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=d10063.avocado.local)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC0ipc)))
Services Summary...
Service "gsid" has 2 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
  Instance "paul", status READY, has 1 handler(s) for this service...
Service "paul" has 1 instance(s).
  Instance "paul", status READY, has 1 handler(s) for this service...
Service "paultest" has 1 instance(s).
  Instance "paul", status READY, has 1 handler(s) for this service...
The command completed successfully

從lsnrctl status 處可以看出

初始化引數設定:instance_name=paul service_names=paul,gsid ,paultest

所以動態註冊時也會對外提供三個服務:paul和gsid ,paultest

C:\Documents and Settings\Paul Yi>tnsping primary

TNS Ping Utility for 32-bit Windows: Version 9.2.0.4.0 - Production on 18-DEC-20
07 09:50:59

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

Used parameter files:
D:\oracle\ora92\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.1.163)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = gsid)))
OK (0 msec)

所以綜上所述:instance_name只有唯一的一個名稱,而service_name可以有多個用於tnsnames.ora客戶端連線

連線字串也可以隨意取名

對於客戶端來說,它不用關心資料庫的名字、例項名到底是什麼,它只需要知道資料庫對外提供的服務名就行了,這個名字可能和例項名一樣,也可能不一樣。

 

 

 

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7199859/viewspace-783/,如需轉載,請註明出處,否則將追究法律責任。

相關文章