TNS listener(s) local listener remote listenrer 11g之前

How to create an additional TNS listener(s) and load balance connections between those listeners.

ie run with multiple TNS listeners. This can assist when a single TNS listener is stressed or overwhelmed with a high connection rate, particularly during peak periods or when a login storm occurs.

Increasing the value for QUEUESIZE for TNS listener can also assist. See section 5 of Note 67983.1

SOLUTION

Adding Additional TNS Listener Standalone Database

1. Setup the LISTENER.ORA file with a unique TNS listener. Either cut and paste from below LISTENER.ORA example or use Net Manager

Example Listener.ora

LISTENERA =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2001))

)

)

SID_LIST_LISTENERA =

(SID_LIST =

(SID_DESC =

(SID_NAME = <instance_name>)

)

)

LISTENERB =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2002))

)

)

SID_LIST_LISTENERB =

(SID_LIST =

(SID_DESC =

(SID_NAME = <instance_name>)

)

)

To setup via Net Manager (NetMgr)

  • Select Local from the left hand panel, within Net Manager.

  • Select Listeners from the tree and plus button "+" will go green.

  • Click the plus button and enter a listener name. This must be a unique name.

  • Click ok and then select add address.

Hostname and port number will be added automatically for TCPIP protocol.

The Port number must be unique

  • File Save Network Configuration and a basic listener is setup

If you wish to set a SID entry change Listening Locations to Database Services

  • Click Add Database button

  • Enter details, SID is the minimum requirement.

  • File Save Network Configuration

To start the TNS listeners use start command, with the listener name. For example lsnrctl start listenera

2. Database must know of all addresses for service registration to work.

Add to TNSNAMES.ORA file

LISTENERS =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2001))

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2002))

)

)

Register the database with the TNS listeners

sqlplus /nolog

SQL>connect / as sysdba

SQL>alter system set local_listener='LISTENERS' scope=both

也可以不用tnsnames.ora 直接

alter system set local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2001))

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2002))'

Both listeners will then show services for the database <instance_name>

>lsnrctl services listenera

LSNRCTL for Solaris: Version 10.2.0.3 - Production on 16-MAR-2008 12:31:17

Copyright (c) 1991, 2004, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<sample_hostname>)(PORT=2001)))

Services Summary...

Service "<service_name>" has 1 instance(s).

Instance "<instance_name>", status UNKNOWN, has 1 handler(s) for this service...

Handler(s):

"DEDICATED" established:0 refused:0

LOCAL SERVER

Service "<service_name.domain>" has 1 instance(s).

Instance "<instance_name>", status READY, has 2 handler(s) for this service...

Handler(s):

"DEDICATED" established:0 refused:0 state:ready

LOCAL SERVER

The command completed successfully

>lsnrctl services listenerb

LSNRCTL for Solaris: Version 10.2.0.3 - Production on 16-MAR-2008 12:32:43

Copyright (c) 1991, 2004, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<sample_hostname>)(PORT=2002)))

Services Summary...

Service "<service_name>" has 1 instance(s).

Instance "<instance_name>", status UNKNOWN, has 1 handler(s) for this service...

Handler(s):

"DEDICATED" established:0 refused:0

LOCAL SERVER

Service "<service_name.domain>" has 1 instance(s).

Instance "<instance_name>", status READY, has 2 handler(s) for this service...

Handler(s):

"DEDICATED" established:0 refused:0 state:ready

LOCAL SERVER

The command completed successfully

*Notes:

  • Status "unknown" is due the static service status using the SID_LIST section of the LISTENER.ORA file.

  • Status "ready" is the DYNAMIC service registration from the LOCAL_LISTENER (Database) parameter setting.

3. Example TNSNAMES.ORA entry for using both listeners in a connection:

LOADBALANCE =

(DESCRIPTION =

(LOAD_BALANCE = yes)

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2001))

(ADDRESS = (PROTOCOL = TCP)(HOST = <sample_hostname>)(PORT = 2002))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = <service_name.domain>)

)

)

Example JDBC Thin connection:

"jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=<sample_hostname>)(PORT=2001))(ADDRESS=(PROTOCOL=TCP)(HOST=<sample_hostname>)(PORT=2002)) (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=<service_name.domain>)))"

*Note:

  • The (LOAD_BALANCE = yes or on) parameter makes a random selection of the addresses in the address list.

如果第一个要先尝试可以OFF,这样ADG环境下 只有主库出问题才去备库查询

Adding Additional TNS Listener RAC

Adding additional TNS listeners to RAC must be done via the netca tool.

Please note this is only valid for versions 9.2.0.1 to 11.1.0.7

1. Run NetCA

Step 1 Select the type of Oracle Net Service Configuration = Cluster Configuration
Step 2 Select the nodes to config = All the nodes where additional listener required
Step 3 Choose the configuration you would like todo = Listener configuration
Step 4 Select what you want to do = Add
Step 5 Listener Name = Add unique listener name
Step 6 Select Protocol = TCP
Step 7 Which TCP/IP port number should be used = Use Another port and ensure its free

(netstat -a -n command can confirm this for you)
Step 8 Would you like to configure another listener = no
Step 9 Select the listener you want to start = entry new listener name

Exit Netca.

On exit the screen should show following

Example for Listener called "Listener2" added to Nodes called Node1 and Node2

Oracle Net Services Configuration:

Configuring Listener:LISTENER2

Node1...

Node2...

Listener configuration complete.

Configuring Listener:LISTENER2

Node1...

Node2...

Listener configuration complete.

Oracle Net Services configuration successful. The exit code is 0

Listener.ora for RAC should look similar to following for Node1

LISTENER_NODE1 =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1521)(IP = FIRST))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA_hostname>)(PORT = 1521)(IP = FIRST ))

)

)

LISTENER2_NODE1 =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1535)(IP = FIRST))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA_hostname>)(PORT = 1535)(IP = FIRST ))

)

)

*Similar with Node2 / NodeB but with that hostname information.

**2.**Registering the instances with the listeners.Add to TNSNAMES.ORA file

LOCAL_NodeA =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1535))

)

LOCAL_NodeB =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeB-vip_hostname>)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeB-vip_hostname>)(PORT = 1535))

)

3. Connect to each instance and register PMON for each instance.

Instance 1

SQL > alter system set LOCAL_LISTENER='LOCAL_NodeA' scope=both sid='<instance_name1>';

Instance 2

SQL > alter system set LOCAL_LISTENER='LOCAL_NodeB' scope=both sid='<instance_name2>';

**4.**With Server side load balancing enabled, REMOTE_LISTENER value will also have to include the new addresses. Entry in TNSNAMES.ORA should be similar to following:

REMOTE_TNSLSNR =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeA-vip_hostname>)(PORT = 1535))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeB-vip_hostname>)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = <NodeB-vip_hostname>)(PORT = 1535))

)

5. Command to register is

SQL > alter system set REMOTE_LISTENER='REMOTE_TNSLSNR' scope=both;

Windows :

Please note adding new TNS listener to a Windows platform will error, when it is first started via command line. This is expected,as the Windows Service is being created for the TNS listener

相关推荐
刘大浪16 分钟前
后端数据增删改查基于Springboot+mybatis mysql 时间根据当时时间自动填充,数据库连接查询不一致,mysql数据库连接不好用
数据库·spring boot·mybatis
无敌岩雀23 分钟前
MySQL中的索引
数据库·mysql
a_安徒生1 小时前
linux安装TDengine
linux·数据库·tdengine
程序员学习随笔1 小时前
PostgreSQL技术内幕19:逻辑备份工具pg_dump、pg_dumpall
数据库·postgresql
尘浮生1 小时前
Java项目实战II基于微信小程序的校运会管理系统(开发文档+数据库+源码)
java·开发语言·数据库·微信小程序·小程序·maven·intellij-idea
偶尔。5351 小时前
什么是事务?事务有哪些特性?
数据库·oracle
安迁岚1 小时前
【SQL Server】华中农业大学空间数据库实验报告 实验六 视图
数据库·sql·mysql·oracle·实验报告
xoxo-Rachel2 小时前
(超级详细!!!)解决“com.mysql.jdbc.Driver is deprecated”警告:详解与优化
java·数据库·mysql
JH30732 小时前
Oracle与MySQL中CONCAT()函数的使用差异
数据库·mysql·oracle
蓝染-惣右介2 小时前
【MyBatisPlus·最新教程】包含多个改造案例,常用注解、条件构造器、代码生成、静态工具、类型处理器、分页插件、自动填充字段
java·数据库·tomcat·mybatis