listener之一二
一、注册
注册就是将数据库作为一个服务注册到监听程序。客户端不需要知道数据库名和实例名,只需要
知道该数据库对外提供的服务名就可以申请连接到数据库。这个服务名可以与实例名一致,也可以不
一致,且可以注册多个服务。
注册可以分为静态注册与动态注册,下面分别介绍静态注册和动态注册。
二、静态注册
静态注册就是预先配置好listener.ora文件,配置信息如下:
#listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/10.2/db_1) (PROGRAM = extproc) ) (SID_DESC = (SID_NAME = orcl)##数据库的实例名 (ORACLE_HOME = /u01/app/oracle/product/10.2/db_1)##监听程序所在路径 (GLOBAL_DBNAME = test01)##数据库对外提供的服务名 ) )LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = db01)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) )
当用户通过客户端申请连接数据库时,首先通过监听程序读取listener.ora中的配置信息(无论数据库
是否启动,用户的连接请求都会通过监听程序的检查,因为静态监听是无法识别数据库的启动状态的
,只有用户试图连接数据库时,数据库才会返回相关信息。)
下面我们来看下数据库处于打开和关闭状态时,服务test01的实例状态:
1、打开状态
[oracle@db01 admin]$ lsnrctl statusLSNRCTL for Linux: Version 10.2.0.1.0 - Production on 16-OCT-2013 06:58:27Copyright (c) 1991, 2005, Oracle. All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db01)(PORT=1521)))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 10.2.0.1.0 - ProductionStart Date 16-OCT-2013 06:39:09Uptime 0 days 0 hr. 19 min. 18 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /u01/app/oracle/product/10.2/db_1/network/admin/listener.oraListener Log File /u01/app/oracle/product/10.2/db_1/network/log/listener.logListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db01)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))Services Summary...Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...Service "orcl_XPT" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...Service "test01" has 1 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... =>实例orcl的状态为unknownThe command completed successfully此时当用户通过客户端连接数据库时:SQL> conn system/hat@test01
已连接。
2、关闭状态:
[oracle@db01 admin]$ lsnrctl statusLSNRCTL for Linux: Version 10.2.0.1.0 - Production on 16-OCT-2013 06:54:44Copyright (c) 1991, 2005, Oracle. All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db01)(PORT=1521)))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 10.2.0.1.0 - ProductionStart Date 16-OCT-2013 06:39:09Uptime 0 days 0 hr. 15 min. 35 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /u01/app/oracle/product/10.2/db_1/network/admin/listener.oraListener Log File /u01/app/oracle/product/10.2/db_1/network/log/listener.logListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db01)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))Services Summary...Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...Service "test01" has 1 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... =>实例orcl的状态为unknownThe command completed successfully
此时当用户通过客户端连接数据库时:
SQL> conn system/hat@test01
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
由此可知,用户的连接请求通过了监听的检查,但数据库没有打开,于是就返回了ora-01034的错误。
通过上面的实验,验证了当监听静态注册时,服务的实例状态均为unknown,监听程序无法知道数据库
是否处于打开状态。
三、动态注册
动态注册就是不需预先配置listener.ora文件,而是instance在启动的时候PMON进程根据
init.ora中的instance_name、service_names两个参数将实例和服务动态的注册到listener中。
注册到监听器中的实例名从init.ora文件中的instance_name参数取得。如果该参数没有设定值,
那么它将取init.ora文件中的db_name值。
注册到监听器中的服务名从init.ora文件中的参数service_names(该参数可以设置多个值,且值
以逗号分隔)和db_domain取得。如果service_names参数没有设定值,数据库将取init.ora文件中的
db_name值。
采取动态注册时,listener.ora配置如下:
#listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/10.2/db_1) (PROGRAM = extproc) ) )LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = db01)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) )
动态注册默认只注册到默认的监听器上(名称是LISTENER、端口是1521、协议是TCP),如果需要向
非默认监听注册,则只需要配置local_listener参数。
四、如何区分静态注册与动态注册
方法一:通过lsnrctl status监测
静态注册的监听实例状态为unknown,动态注册的监听实例状态为ready
方式二:查看listener.ora文件
listener.ora文件中添加了如下信息的为静态注册,没有添加为动态注册
(SID_DESC =
(SID_NAME = orcl)##数据库的实例名
(ORACLE_HOME = /u01/app/oracle/product/10.2/db_1)##监听程序所在路径
(GLOBAL_DBNAME = test01)##数据库对外提供的服务名
)
注:1、由于动态注册监听是通过pmon进程来动态添加的,因此一旦数据库关闭,那么动态注册的服务便立即从监听程序中消除。
2、如果想远程启动数据库,需要通过静态注册。
bitsCN.com