listener的動態註冊

tolywang發表於2009-12-18

 

在oracle中,除了可以利用listener.ora檔案實現靜態的註冊外,還能自動的實現動態註冊。
透過lsnrctl status我們可以看到unknown狀態的偵聽是靜態註冊的偵聽,因為它無法知道當前instance的狀態,而ready狀態的偵聽是動態註冊的偵聽,在instance啟動的時候,會向偵聽進行動態註冊,告知偵聽已經啟動的instance name和service names??也基於這個原因,如果在instance啟動後,再重啟lsnr,lnsr會在剛剛開始的一段時間內(大約不到1分鐘)無法得知 instance的狀態,只有等待pmon程式動態註冊。下面的例子就是演示重啟偵聽但是不重啟instance,在剛剛開始的一段時間內會提示偵聽不提供服務:
(1)透過ls看到,listener.ora已經被重新命名成listener.ora111,oracle找不到靜態偵聽的檔案listener.ora,因此採用動態註冊:

D:\oracle\ora92\network\admin>ls
SAMPLE                 listener.bak           master.cfg             snmp_rw.ora            tnsnames.ora           復件 tnsnames.ora
encaps.cfg             listener.ora111        snmp_ro.ora            sqlnet.ora             復件 (2) tnsnames.ora
(2)停lsnr,重啟lsnr:

D:\oracle\ora92\network\admin>lsnrctl stop
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-JUL-2007 00:35:37
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
The command completed successfully
 
D:\oracle\ora92\network\admin>
D:\oracle\ora92\network\admin>
D:\oracle\ora92\network\admin>lsnrctl start
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-JUL-2007 00:35:46
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
Starting tnslsnr: please wait...
 
TNSLSNR for 32-bit Windows: Version 9.2.0.1.0 - Production
寫入D:\oracle\ora92\network\log\listener.log的日誌資訊
監聽:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=1521)))
 
Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 9.2.0.1.0 - Production
Start Date                22-7月 -2007 00:35:48
Uptime                    0 days 0 hr. 0 min. 2 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Log File         D:\oracle\ora92\network\log\listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=1521)))
The listener supports no services
The command completed successfully
進一步檢視其對外的service,也是發現沒有提供:

D:\oracle\ora92\network\admin>lsnrctl service
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-JUL-2007 00:36:02
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
The listener supports no services
The command completed successfully
(3)重啟instance,再檢查lnsr的狀態

sys@ORALOCAL(192.168.0.22)> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORALOCAL(192.168.0.22)> startup
ORACLE instance started.
 
Total System Global Area  133765984 bytes
Fixed Size                   453472 bytes
Variable Size              79691776 bytes
Database Buffers           50331648 bytes
Redo Buffers                3289088 bytes
Database mounted.
Database opened.
sys@ORALOCAL(192.168.0.22)> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
 
D:\oracle\ora92\network\admin>lsnrctl service
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-JUL-2007 00:37:15
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
Services Summary...
Service "oralocal" has 1 instance(s).
  Instance "oralocal", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "oralocalXDB" has 1 instance(s).
  Instance "oralocal", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1002 state:ready
         DISPATCHER
         (ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=1951))
The command completed successfully
 
D:\oracle\ora92\network\admin>
發現重啟instance後,instance重新註冊lnsr,在lsnrctl service也看到了其對外已經重新提供了服務。
注:如果不重啟instance,將有pmon進行動態註冊。

另外,如果要實現動態註冊,我們在對初始化檔案還有有一定的設定,必須設定instance_name和service_names引數(我試了一下,其實只要設定了service_names就能實現動態註冊的,並且用這個服務名對外提供服務)。
修改初始化檔案,先全部取消instanace_name和service_names,然後逐個設定測試:
(1)先設定instance_name

sys@ORALOCAL(192.168.0.22)> alter system set instance_name='oralocal' scope=spfile;
 
系統已更改。
 
已用時間:  00: 00: 00.01
sys@ORALOCAL(192.168.0.22)> startup force;
ORACLE 例程已經啟動。
 
Total System Global Area  133765984 bytes
Fixed Size                   453472 bytes
Variable Size              79691776 bytes
Database Buffers           50331648 bytes
Redo Buffers                3289088 bytes
資料庫裝載完畢。
資料庫已經開啟。
sys@ORALOCAL(192.168.0.22)> show parameter instance_name
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
instance_name                        string      oralocal
 
sys@ORALOCAL(192.168.0.22)> show parameter service_names
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string
sys@ORALOCAL(192.168.0.22)> exit
檢查lsnr的狀況:

C:\Documents and Settings\Administrator>lsnrctl status
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-7月 -2007 00:42:56
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
正在連線到 (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
LISTENER 的 STATUS
------------------------
別名                      LISTENER
版本                      TNSLSNR for 32-bit Windows: Version 9.2.0.1.0 - Production
啟動日期                  22-7月 -2007 00:35:48
正常執行時間              0 天 0 小時 7 分 9 秒
跟蹤級別                  off
安全性                    OFF
SNMP                      OFF
監聽器日誌檔案          D:\oracle\ora92\network\log\listener.log
監聽端點概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=8080))(Presentation=HTTP)(Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=2100))(Presentation=FTP)(Session=RAW))
服務摘要..
服務 "oralocalXDB" 包含 1 個例程。
命令執行成功
 
C:\Documents and Settings\Administrator>lsnrctl service
 
LSNRCTL for 32-bit Windows: Version 9.2.0.1.0 - Production on 22-7月 -2007 00:43:09
 
Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.
 
正在連線到 (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
服務摘要..
服務 "oralocalXDB" 包含 1 個例程。
    處理程式:
      "D000" 已建立:0 已被拒絕:0 當前: 0 最大: 1002 狀態: ready
         DISPATCHER
         (ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=2066))
命令執行成功
 
C:\Documents and Settings\Administrator>sqlplus
 
SQL*Plus: Release 9.2.0.1.0 - Production on 星期日 7月 22 00:47:09 2007
 
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
 
ERROR:
ORA-12514: TNS: 監聽程式不能解析在連線描述符中給出的 SERVICE_NAME
發現其還是沒有提供oralocal的服務,登入也不能成功。並且,如果在客戶端的tnsnames中設定:INSTANCE_NAME = oralocal,透過這個雖然能解析到提供的服務,但是登入還是不能登入,會報錯:
ERROR:
ORA-12504: TNS: 監聽器在 CONNECT_DATA 中未獲得 SID

(2)設定service_names,取消instance_name的設定

username@ORALOCAL(192.168.0.22)> show parameter instance_name
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
instance_name                        string
username@ORALOCAL(192.168.0.22)>  show parameter service_names
 
NAME                                 TYPE        VALUE 


 

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

相關文章