动态监听与静态监听(转载)
Posted 大叔聚
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态监听与静态监听(转载)相关的知识,希望对你有一定的参考价值。
1.认识下注册
2.静态监听
3.动态注册
在lsnrctl命令的status时,常会看到如下返回值:
[plain] view plain copy print?
- Service "elvis" has 2 instance(s).
- Instance "elvis", statusUNKNOWN, has 1 handler(s) for this service...
- Instance "elvis", statusREADY, has 1 handler(s) for this service...
- Service "elvisXDB" has 1 instance(s).
- Instance "elvis", statusREADY, has 1 handler(s) for this service...
- The command completed successfully
Service "elvis" has 2 instance(s).
Instance "elvis", statusUNKNOWN, has 1 handler(s) for this service...
Instance "elvis", statusREADY, has 1 handler(s) for this service...
Service "elvisXDB" has 1 instance(s).
Instance "elvis", statusREADY, has 1 handler(s) for this service...
The command completed successfully
这里的,状态UNKOWN即表明为静态注册(手动填写参数);
状态为READY的记录,表明为动态注册(listener.ora参数由PMON进程自动从参数文件获取);你可能会奇怪,可能我这个与你的有点不同,elvis下面有两个实例,原因是elvis是我的实例名,系统自带了一个,而服务名默认的话是与数据库名一致(如果没有域名的话),可能对于实例名,域名,服务名有点绕,这个概念可以看我的另一篇帖子:
http://blog.csdn.net/elvis_dataguru/article/details/8984961
而unknown那个是我手动创建的监听(静态监听),而创建的我也用了elvis,也就是与系统的重复了,所以合并到了一起,如果你手动创建个别的名字,比如a(在创建监听的时候指定的全局数据库名,这个可以随便起,SID一定要保持一致啦!!!),那就会如下:
[plain] view plain copy print?
- Service "a" has 2 instance(s).
- Instance "elvis", statusUNKNOWN, has 1 handler(s) for this service...
- Instance "elvis", statusREADY, has 1 handler(s) for this service...
- Service "elvisXDB" has 1 instance(s).
- Instance "elvis", statusREADY, has 1 handler(s) for this service...
- The command completed successfully
Service "a" has 2 instance(s).
Instance "elvis", statusUNKNOWN, has 1 handler(s) for this service...
Instance "elvis", statusREADY, has 1 handler(s) for this service...
Service "elvisXDB" has 1 instance(s).
Instance "elvis", statusREADY, has 1 handler(s) for this service...
The command completed successfully
1 认识下注册
注册就是将数据库作为一个服务注册到监听程序。客户端不需要知道数据库名和实例名,只需要知道该数据库对外提供的服务名就可以申请连接到数据库。这个服务名可能与实例名一样,也有可能不一样。
在数据库服务器启动过程中,数据库服务器会向监听程序注册相应的服务(无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。)
相当于是这样:在数据库服务器和客户端之间有一监听程序(Listener),在监听程序中,会记录相应数据库对应的服务名(一个数据库可能对应有多个服务名),当客户端需要连接数据库时,只需要提供服务名,就可以建立客户端和服务器之间的连接。
2 静态监听
监听配置中,数据库服务中的全局数据库名,可以写任意内容,与数据库无关,只要保证SID正确即可连上数据库。
由于静态注册,参数是手动静态添加,与数据库无关。数据库无法确认监听是否正确配置。因此,lsnrctl中的status显示状态为unkown。即不保证能连通数据库。
注意:静态注册监听,客户端在配置tnsnames.ora服务命名时,“(Oracle 8i或更高版本)服务名”里填写内容要与服务端静态注册监听器时的全局数据库名一致。否则,无法连通。
lsnrctl中显示如下:
[plain] view plain copy print?
- Service"a" has 1 instance(s).
- Instance "elvis", status UNKNOWN,has 1 handler(s) for this service...
Service"a" has 1 instance(s).
Instance "elvis", status UNKNOWN,has 1 handler(s) for this service...
elvis即从监听配置过程,数据库服务中的“全局数据库名”读到的值(即配置文件中GLOBAL_DBNAME的值),“elvis”是从监听配置中,数据库服务中的SID读到的值(SID_NAME的值)
[plain] view plain copy print?
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (GLOBAL_DBNAME = elvis)
- (ORACLE_HOME =/u01/oracle/product/11.2.0/dbhome_1)
- (SID_NAME = elvis)
- )
- )
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = elvis)
(ORACLE_HOME =/u01/oracle/product/11.2.0/dbhome_1)
(SID_NAME = elvis)
)
)
客户端在配置tnsname时,服务名(SERVICE_NAME)即为test。否则,连接不到数据库。
[plain] view plain copy print?
- ABC =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.201.128)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = elvis)
- )
- )
ABC =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.201.128)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = elvis)
)
)
这里的ABC,为服务命名。可以为任意值,在客户端连接服务器时,填写的主机字符串,即为此服务名ABC。
3 动态注册
3.1 缺省的动态注册
pmon在数据库启动到mount或open时,动态从参数文件中读取service_names值。service_names可以为多值(可以有64个,其中包括两个系统的)。
service_names缺省为建立数据库时的全局数据库名。
设置参数service_names为’b,c,d’,命令如下:
alter system set service_names=b,c,d;
lsnrctl状态如下:
[plain] view plain copy print?
- Service "B" has 1 instance(s).
- Instance "elvis", status READY, has1 handler(s) for this service...
- Service "C" has1 instance(s).
- Instance "elvis", status READY, has1 handler(s) for this service...
- Service "D" has1 instance(s).
- Instance "elvis", status READY, has1 handler(s) for this service...
- Service "a" has1 instance(s).
- Instance "elvis", status UNKNOWN,has 1 handler(s) for this service...
- Service "elvis"has 1 instance(s).
- 10. Instance "elvis", status READY, has1 handler(s) for this service...
11. Service"elvisXDB" has 1 instance(s).
- 12. Instance "elvis", status READY, has1 handler(s) for this service...
13. The command completedsuccessfully
Service "B" has 1 instance(s).
Instance "elvis", status READY, has1 handler(s) for this service...
Service "C" has1 instance(s).
Instance "elvis", status READY, has1 handler(s) for this service...
Service "D" has1 instance(s).
Instance "elvis", status READY, has1 handler(s) for this service...
Service "a" has1 instance(s).
Instance "elvis", status UNKNOWN,has 1 handler(s) for this service...
Service "elvis"has 1 instance(s).
Instance "elvis", status READY, has1 handler(s) for this service...
Service"elvisXDB" has 1 instance(s).
Instance "elvis", status READY, has1 handler(s) for this service...
The command completedsuccessfully
以上服务名b,c,d,elvis都为READY,为动态注册。
注意:不管参数service_names为何值,pmon都会自动以全局数据库名(这里为elvis)为服务名,动态注册一个监听。
缺省情况下,若启用动态注册监听,端口号必须为1521.若启用其他端口的动态监听注册,必须要做相关配置。
3.2 自定义端口的动态注册监听
若要启用非默认端口1521的动态监听注册,缺省状态,Oracle不会进行动态注册。要启用动态注册,必须设置local_listener参数。并在服务端配置tnsnames.ora指定监听参数,或者直接通过修改local_listener指定监听参数。步骤如下:
1)服务端
netmgr,配置监听程序,监听端口为1525(非默认端口)
2)指定监听参数
(1)方法1:直接通过修改local_listener参数指定
[sql] view plain copy print?
- SQL>alter system set LOCAL_LISTENER=’(ADDRESS=(PROTOCOL=TCP)
- (HOST=192.168.201.128)(PORT=1525))’;
- SQL>alter system register
SQL>alter system set LOCAL_LISTENER=’(ADDRESS=(PROTOCOL=TCP)
(HOST=192.168.201.128)(PORT=1525))’;
SQL>alter system register
(2)方法2:
在Oracle服务器建立$ORACLE_HOME/network/admin/tnsnames.ora。解析文件,位置并填入如下内容
[plain] view plain copy print?
- mytest=
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.201.128)(PORT = 1522))
- )
mytest=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.201.128)(PORT = 1522))
)
这里的mytest也可以根据自己的需要,修改为其他字符串。如a或b等。
设置参数,指定通过tnsnames.ora内的信息指定监听参数
[sql] view plain copy print?
- SQL>alter system setlocal_listener=mytest;
- SQL>alter system register;
以上是关于动态监听与静态监听(转载)的主要内容,如果未能解决你的问题,请参考以下文章