oracle靜態(tài)監(jiān)聽和動態(tài)監(jiān)聽辨析 收藏
一、靜態(tài)注冊
靜態(tài)注冊指實例啟動時讀取listener.ora配置文件,將實例和服務(wù)注冊到監(jiān)聽程序。無論何時啟動一個數(shù)據(jù)庫,默認(rèn)都有兩條信息注冊到監(jiān)聽器中:實例和服務(wù)。
SID_LIST_LISTENER =
( SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = Ora8)
(SID_NAME = test)
)
)
LISTENER =
( DESCRIPTION =
(ADDRESS = (HOST = 192.168.0.88)(PROTOCOL = TCP)(PORT = 1522))
)
這是一個最簡單的靜態(tài)監(jiān)聽配置文件,SID_LIST_LISTENER部分的GLOBAL_DBNAME表示向外提供的服務(wù)名,SID_NAME是提供注冊的實例。
在tnsnames.ora文件中的CONNECT_DATA部分,可分別選擇SERVICE_NAME=Ora8或SID=test為客戶端提供連接。
對于配置非1521監(jiān)聽端口,只能選擇靜態(tài)注冊方式。
二、動態(tài)注冊
動態(tài)注冊不需要顯示的配置listener.ora文件,實例啟動的時候,PMON進(jìn)程根據(jù)instance_name,service_name參數(shù)將實例和服務(wù)動態(tài)注冊到listerer中。如果沒有設(shè)定instance_name,將使用db_name初始化參數(shù)值。如果沒有設(shè)定service_names,將拼接db_name和db_domain參數(shù)值來注冊監(jiān)聽。
SQL> show parameter service_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string test
SQL> show parameter instance_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string test
LSNRCTL> status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 24-SEP-2008 16:50:01
Uptime 0 days 0 hr. 0 min. 33 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test1)(PORT=1521)))
Services Summary...
Service "test" 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
SQL> alter system set service_names='oratest' scope=both;
System altered.
SQL> alter system set instance_name='instest' scope=spfile;
System altered.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 96468992 bytes
Fixed Size 1217884 bytes
Variable Size 88083108 bytes
Database Buffers 4194304 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
LSNRCTL> status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 24-SEP-2008 16:52:44
Uptime 0 days 0 hr. 1 min. 52 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test1)(PORT=1521)))
Services Summary...
Service "oratest" has 1 instance(s).
Instance "instest", status READY, has 1 handler(s) for this service...
Service "test" has 1 instance(s).
Instance "instest", status READY, has 1 handler(s) for this service...
Service "test_XPT" has 1 instance(s).
Instance "instest", status READY, has 1 handler(s) for this service...
The command completed successfully
可以看到,監(jiān)聽注冊的服務(wù)和實例已發(fā)生了相應(yīng)的變化。同靜態(tài)監(jiān)聽,這里也可以分別使用SERVICE_NAME=oratest或SID=instest來進(jìn)行客戶端的連接