您的当前位置:首页正文

oracle实例和监听器

2024-11-07 来源:个人技术集锦

一、静态注册

静态注册指实例启动时读取listener.ora配置文件,将实例和服务注册到监听程序。无论何时启动一个
,默认都有两条信息注册到监听器中:实例和服务。
SID_LIST_LISTENER =
( SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = Ora8)
(SID_NAME = test)
)
)

LISTENER =
( DESCRIPTION =
(ADDRESS = (HOST = 192.168.0.8)(PROTOCOL = TCP)(PORT = 1522))
)
这是一个最简单的静态监听配置文件,SID_LIST_LISTENER部分的GLOBAL_DBNAME表示向外提供的服务名,SID_NAME是提供注册的实例。
在tnsnames.ora文件中的CONNECT_DATA部分,可分别选择SERVICE_NAME=Ora8或SID=test为客户端提供连接。
对于配置非1521监听端口,只能选择静态注册方式。
二、动态注册
动态注册不需要显示的配置listener.ora文件,实例启动的时候,PMON进程根据instance_name,service_name参数将实例和服务动态注册到listerer中。如果没有设定instance_name,将使用db_name初始化参数值。如果没有设定service_names,将拼接db_name和db_domain参数值来注册监听。
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.
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 byte
Database mounted.
Database opened.
LSNRCTL> status

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the 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
可以看到,监听注册的服务和实例已发生了相应的变化。同静态监听,这里也可以分别使用SERVICE_NAME=oratest或SID=instest来进行客户端的连接

但是PMON进程只向默认的1521端口的监听注册,当监听不在1521端口时,需要使用下面的方法:

System altered.

b、或者只在参数local_listener中输入监听的名称
sys@TEST>alter system set local_listener='test';

System altered.

4、但有3点需要注意的地方:
a、PMON进程1分钟运行一次,当监听刚刚启动的时候,可能服务还没有注册进去,这时候是不能使用此服务的
b、在修改local_listener参数时,PMON进程也会重新注册一次
c、如果数据库shutdown后,PMON进程也停止了,服务会从监听中删除,这时候只能使用OS认证的方式连入数据库


显示全文