oracle监听的动态注册和静态注册

参考资料:


https://blog.csdn.net/tianlesoftware/article/details/5543166

https://www.cnblogs.com/guilingyang/p/6074867.html

 现象1:


1、动态注册

参数文件中指定service_names(多个服务名vmdb,sn01,sn02),8i以后数据库实例启动后,会根据参数文件的service_names以及instance_name动态注册到监听器:

 1 SQL> show parameter service_names;
 2 
 3 NAME                     TYPE     VALUE
 4 ------------------------------------ ----------- ------------------------------
 5 service_names                 string     vmdb,sn01,sn02
 6 SQL> show parameter instance_name;
 7 
 8 NAME                     TYPE     VALUE
 9 ------------------------------------ ----------- ------------------------------
10 instance_name                 string     vmdb

2、静态注册

实例启动时读取文件$ORACLE_HOME/network/admin/listener.ora文件的配置,将实例和服务注册到监听程序。listener.ora文件配置如下:

 1 SID_LIST_LISTENER =
 2   (SID_LIST =
 3     (SID_DESC =
 4       (GLOBAL_DBNAME = sn03)
 5       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
 6       (SID_NAME = vmdb)
 7     )
 8   )
 9 
10 LISTENER =
11   (DESCRIPTION =
12     (ADDRESS = (PROTOCOL = TCP)(HOST = CentOS)(PORT = 1521))
13   )
14 
15 ADR_BASE_LISTENER = /u01/app/oracle

3、先启动数据库再启动监听

 1 SQL> startup
 2 ORACLE instance started.
 3 
 4 Total System Global Area  776646656 bytes
 5 Fixed Size            2217384 bytes
 6 Variable Size          583010904 bytes
 7 Database Buffers      188743680 bytes
 8 Redo Buffers            2674688 bytes
 9 Database mounted.
10 Database opened.
启动数据库
 1 [oracle@CentOS ~]$ lsnrctl start
 2 
 3 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 28-MAR-2018 13:03:11
 4 
 5 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 6 
 7 TNS-01106: Listener using listener name LISTENER has already been started
 8 [oracle@CentOS ~]$ lsnrctl reload
 9 
10 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 28-MAR-2018 13:03:19
11 
12 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
13 
14 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS)(PORT=1521)))
15 The command completed successfully
16 [oracle@CentOS ~]$ lsnrctl status
17 
18 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 28-MAR-2018 13:03:25
19 
20 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
21 
22 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS)(PORT=1521)))
23 STATUS of the LISTENER
24 ------------------------
25 Alias                     LISTENER
26 Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
27 Start Date                28-MAR-2018 13:03:08
28 Uptime                    0 days 0 hr. 0 min. 16 sec
29 Trace Level               off
30 Security                  ON: Local OS Authentication
31 SNMP                      OFF
32 Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
33 Listener Log File         /u01/app/oracle/diag/tnslsnr/CentOS/listener/alert/log.xml
34 Listening Endpoints Summary...
35   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS)(PORT=1521)))
36 Services Summary...
37 Service "sn03" has 1 instance(s).
38   Instance "vmdb", status UNKNOWN, has 1 handler(s) for this service...
39 The command completed successfully
启动监听器

发现监听服务只有静态注册的sn03

4、手工注册

 1 SQL> alter system register; 2 3 System altered. 

再次查看监听,动态注册成功:

 1 [oracle@CentOS ~]$ lsnrctl status
 2 
 3 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 28-MAR-2018 12:41:00
 4 
 5 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 6 
 7 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS)(PORT=1521)))
 8 STATUS of the LISTENER
 9 ------------------------
10 Alias                     LISTENER
11 Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
12 Start Date                28-MAR-2018 12:40:45
13 Uptime                    0 days 0 hr. 0 min. 15 sec
14 Trace Level               off
15 Security                  ON: Local OS Authentication
16 SNMP                      OFF
17 Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
18 Listener Log File         /u01/app/oracle/diag/tnslsnr/CentOS/listener/alert/log.xml
19 Listening Endpoints Summary...
20   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS)(PORT=1521)))
21 Services Summary...
22 Service "sn01" has 1 instance(s).
23   Instance "vmdb", status READY, has 1 handler(s) for this service...
24 Service "sn02" has 1 instance(s).
25   Instance "vmdb", status READY, has 1 handler(s) for this service...
26 Service "sn03" has 1 instance(s).
27   Instance "vmdb", status UNKNOWN, has 1 handler(s) for this service...
28 Service "vmdb" has 1 instance(s).
29   Instance "vmdb", status READY, has 1 handler(s) for this service...
30 Service "vmdbXDB" has 1 instance(s).
31   Instance "vmdb", status READY, has 1 handler(s) for this service...
32 The command completed successfully
查看监听状态

动态注册到非默认端口


如果要向非默认监听注册,则要修改相应系统参数。将要监听的信息添加到tnsnames.ora文件(pmon动态注册监听时从tnsnames.ora文件读取信息)。

对于专用服务器模式:

LOCAL_LISTENER=listener_alias

对于共享服务器模式:

DISPATCHERS="(PROTOCOL=tcp)(LISTENER=listener_alias)"

例如对于专用服务器模式,监听端口1522:

1、修改listener.ora文件监听器的监听端口

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = CentOS)(PORT = 1522))
  )

2、修改tnsnames.ora,设置pmon动态注册的目标端口

1 listener_alias =
2   (DESCRIPTION =
3     (ADDRESS = (PROTOCOL = TCP)(HOST = CentOS)(PORT = 1522))
4   )

3、修改参数LOCAL_LISTENER

alter system set local_listener=listener_alias;
alter system register;

4、查看监听状态

 1 [oracle@CentOS admin]$ lsnrctl status
 2 
 3 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 31-MAR-2018 06:55:42
 4 
 5 Copyright (c) 1991, 2009, Oracle.  All rights reserved.
 6 
 7 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS)(PORT=1522)))
 8 STATUS of the LISTENER
 9 ------------------------
10 Alias                     LISTENER
11 Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
12 Start Date                31-MAR-2018 06:55:14
13 Uptime                    0 days 0 hr. 0 min. 28 sec
14 Trace Level               off
15 Security                  ON: Local OS Authentication
16 SNMP                      OFF
17 Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
18 Listener Log File         /u01/app/oracle/diag/tnslsnr/CentOS/listener/alert/log.xml
19 Listening Endpoints Summary...
20   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS)(PORT=1522)))
21 Services Summary...
22 Service "sn01" has 1 instance(s).
23   Instance "vmdb", status READY, has 1 handler(s) for this service...
24 Service "sn02" has 1 instance(s).
25   Instance "vmdb", status READY, has 1 handler(s) for this service...
26 Service "sn03" has 1 instance(s).
27   Instance "vmdb", status UNKNOWN, has 1 handler(s) for this service...
28 Service "vmdb" has 1 instance(s).
29   Instance "vmdb", status READY, has 1 handler(s) for this service...
30 Service "vmdbXDB" has 1 instance(s).
31   Instance "vmdb", status READY, has 1 handler(s) for this service...
32 The command completed successfully
View Code 

静态注册的意义


//TODO 

总结:


与文章开头的引用的外部文章说法有些差异:

1、动态注册只会在PMON进程启动时才会自动将服务注册到监听器(一般在启动一分钟内完成注册),如果此时监听器未启动,则动态注册失败,此时如果再启动监听器,依然不会有动态注册信息。

2、静态注册与实例是否启动无关,启动监听器时会读取listener.ora文件进行静态注册,此时即便数据库未启动,监听状态依然能看到静态注册信息。重启监听器也一样,只会进行静态注册,所以可能导致动态注册信息丢失。

3、动态注册默认只注册到默认的监听器(名称LISTENER,端口1521,协议TCP),否则PMON不能动态注册listener,除非修改参数local_listener。

原文地址:https://www.cnblogs.com/ZeroTiny/p/8652111.html