【原創】Oracle的動態監聽註冊

木頭一個發表於2008-04-14

ORACLE例項在啟動時,或使用命令ALTER SYSTEM REGISTER ,或每隔一分鐘,PMON程式會向監聽進行動態註冊

1、監聽在啟動時,會從$ORACLE_HOME/network/admin/listener.ora讀取監聽配置,如果該檔案不存在,則監聽會在主機名對應的IP和1521埠上進行監聽。可以看到監聽剛剛啟動的時候,並沒有註冊的服務
LSNRCTL> start
Starting tnslsnr: please wait...

TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Log messages written to f:\oracle\product\10.2.0\network\log\listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linan)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date                14-APR-2008 21:29:40
Uptime                    0 days 0 hr. 0 min. 2 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         f:\oracle\product\10.2.0\network\log\listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linan)(PORT=1521)))
The listener supports no services
The command completed successfully

2、過了大概1分鐘,PMON程式會將服務註冊進來
LSNRCTL> status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date                14-APR-2008 21:29:40
Uptime                    0 days 0 hr. 1 min. 57 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         f:\oracle\product\10.2.0\network\log\listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linan)(PORT=1521)))
Services Summary...
Service "test" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
Service "testXDB" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
Service "test_XPT" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
The command completed successfully

3、但是PMON程式只向預設的1521埠的監聽註冊,當監聽不在1521埠時,需要使用下面的方法:

a、直接在引數local_listener中輸入監聽地址,PMON程式會根據此資訊,並進行註冊
sys@TEST>alter system set local_listener='(address=(protocol=tcp)(port=1522)(host=linan))';

System altered.

b、或者只在引數local_listener中輸入監聽的名稱
sys@TEST>alter system set local_listener='test';

System altered.

在$ORACLE_HOME/network/admin/tnsnames.ora中包含監聽地址,PMON程式會從此處得監聽資訊,並進行註冊
TEST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1522))

4、但有3點需要注意的地方:
a、PMON程式1分鐘執行一次,當監聽剛剛啟動的時候,可能服務還沒有註冊進去,這時候是不能使用此服務的
b、在修改local_listener引數時,PMON程式也會重新註冊一次
c、如果資料庫shutdown後,PMON程式也停止了,服務會從監聽中刪除,這時候只能使用OS認證的方式連入資料庫

LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=linan)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     listener1
Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date                14-APR-2008 21:14:04
Uptime                    0 days 0 hr. 10 min. 15 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   f:\oracle\product\10.2.0\network\admin\listener.ora
Listener Log File         f:\oracle\product\10.2.0\network\log\listener1.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linan)(PORT=1522)))
Services Summary...
Service "test" has 1 instance(s).
  Instance "test", status BLOCKED, has 1 handler(s) for this service...
Service "testXDB" has 1 instance(s).
  Instance "test", status BLOCKED, has 1 handler(s) for this service...
Service "test_XPT" has 1 instance(s).
  Instance "test", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully

sys@TEST>shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down
.

LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=linan)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     listener1
Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production
Start Date                14-APR-2008 21:14:04
Uptime                    0 days 0 hr. 10 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   f:\oracle\product\10.2.0\network\admin\listener.ora
Listener Log File         f:\oracle\product\10.2.0\network\log\listener1.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linan)(PORT=1522)))
The listener supports no services
The command completed successfully

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

相關文章