在 $ORACLE_HOME/network/admin 下面有3 个重要的文件:
• The listener.ora file is a server-side file that defines database listeners. It includes the protocols, addresses, and ports on which they will listen for incoming connection requests, and (optionally) a hard-coded list of instances against which they will launch sessions.
• The tnsnames.ora file is a client-side file used for name resolution. It is used by user processes to locate database listeners. It may also be used by the instance itself, to locate a listener with which to register.
• The sqlnet.ora file is optional and may exist (possibly with different settings) on the server side, the client side, or both. It contains settings that apply to all connections and listeners, such as security rules and encryption.
怎样添加 LISTENER
1. Create a directory to be used for the Oracle Net configuration files, and set the TNS_ADMIN variable to point to this. It doesn’t matter where the directory is, as long as the Oracle user has permission to create, read, and write it.
On Linux:
mkdir /u01/oracle/net
export TNS_ADMIN=/u01/oracle/net
Ensure that all work from now is done from a session where the variable has been set.
On Windows:
mkdir d:\oracle\net
Create and set the key TNS_ADMIN as a string variable in the registry in the Oracle Home branch. This will typically be
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1
2. Check that the variable is being read by using the TNSPING command from an operating system prompt:
tnsping orcl
This will return an error “TNS-03505: Failed to resolve name” because there are no files in the TNS_ADMIN directory. On Windows, you may need to launch a new command prompt to pick up the new TNS_ADMIN value from the registry.
3. Start the Net Manager. On Linux, run netmgr from an operating system prompt; on Windows, launch it from the Start menu. The top line of the Net Manager window will show the location of the Oracle Net files. If this is not the new directory, then the TNS_ADMIN variable has not been set correctly.
4. Create a new listener: expand the Local branch of the navigation tree, highlight Listeners, and click the + icon.
5. Enter a listener name, NEWLIST, and click OK.
6. Click Add Address.
7. For Address 1, choose TCP/IP as the protocol and enter 127.0.0.1 as the host, 2521 as the port. The illustration that follows shows the result.
8. Create a new service name: highlight Service Naming in the navigation tree, and click the + icon.
9. Enter NEW as the net service name, and click Next.
10. Select TCP/IP as the protocol, and click Next.
11. Enter 127.0.0.1 as the host name and 2521 as the port and click Next.
12. Enter SERV1 as the service name, and click Next.
13. Click Finish. If you try the test, it will fail at this time. The illustration that follows shows the result.
14. Save the configuration by clicking File and Save Network Configuration. This will create the listener.ora and tnsnames.ora files in the TNS_ADMIN directory.
15. Use an editor to check the two files. They will look like this:
LISTENER.ORA:
NEWLIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 2521))
)
TNSNAMES.ora:
NEW =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 2521))
)
(CONNECT_DATA =
(SERVICE_NAME = SERV1)
)
)
如果同一时间连接数据库的请求很多, 这些连接请求会排队, 一个一个启动服务器进程. 这样比较慢. 如果想避免, 可以在不同的端口上多设置几个监听器, 这样就可以分散客户端的请求了, 避免排队消耗太长时间.