在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 <machine: HEJIANMIN, pid: 772>
(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 <machine: HEJIANMIN, pid: 3904>
(ADDRESS=(PROTOCOL=tcp)(HOST=hejianmin)(PORT=2066))
命令执行成功
C:\Documents and Settings\Administrator>sqlplus username/password@oralocal
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
阅读(1561) | 评论(0) | 转发(0) |