Brief Introduction to Oracle TNS

Source: Internet
Author: User
Tags failover taf

Brief Introduction to Oracle TNS

  •  What is TNS?

TNS is a part of Oracle Net. It is a tool used to manage and configure the connection between the Oracle database and the client. In most cases, to communicate with the database, TNS must be configured, of course, in a few cases, you can connect to the Oracle database without configuring TNS, such as through JDBC. if you use TNS to connect to Oracle, the Oracle client must be installed on the client.

  • What configuration files does TNS have?

The configuration file of TNS includes two parts: the server (the machine on which the Oracle database is installed) and the client. The server hasListener. ora, sqlnet. ora, tnsnames. oraIf you connect to the Domain Name Service management client through the OCM (Oracle connection manage), the server may also includeCMAN. oraFiles; the client hasTnsnames. ora, sqlnet. ora.
Listener. ora:Listener Configuration File. After the listener is successfully started, it is a service residing on the server. What is a listener? Listener is a service program used to listen for client connection requests and establish a connection channel between the client and the server. By default, Oracle listens for database connection requests on port 1521.
Sqlnet. ora:Used to manage and restrict the configuration of TNS connections. You can manage TNS connections by setting some parameters in this file. You need to configure the parameters on the server and the client separately based on the parameters.
Tnsnames. ora:Configure the Connection Service from the client to the server, including the configuration information of the server and database to which the client connects.

All the TNS configuration files in Oracle are stored in

Unix/Linux: $ ORACLE_HOME/Network/admin
Windows: % ORACLE_HOME %/Network/admin

  • What configuration tools does TNS have?

You can configure it manually or through Oracle Net configuretion assitant.

  • Oracletns configuration process

After the installation is complete on the Oracle server, listenerr is the primary component for Oracle communication, and then installs the Oracle client on the client, and configures the tnsnames. ora file.

  • Listener Configuration

The listener consists of the address, port, and communication protocol to be listened on by Oracle, and the database instance to be listened on by Oracle. in non-RAC environments, listener can only listen to the address and instance of the current server. In RAC environments, listener can also listen to remote servers. each database must have at least one listener.

LISTENER= (DESCRIPTION=  (ADDRESS_LIST=    (ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))    (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))  ) )SID_LIST_LISTENER=  (SID_LIST=    (SID_DESC=      (SID_NAME=plsextproc)      (ORACLE_HOME=/oracle10g)      (PROGRAM=extproc)     )    (SID_DESC=     (SID_NAME=mayp)     (ORACLE_HOME=/oracle10g)    )   )

The listener part is configured with the address information to be listened to by Oracle; The sid_list_listener part is configured with the instance to be listened to by Oracle.

The host parameter can be either a hostname or an IP address. You can configure listener to listen to multiple addresses on a server with multiple IP addresses at the same time. For example, the following Configuration:

LISTENER= (DESCRIPTION=   (ADDRESS_LIST=      (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.10)(PORT=1521))      (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.1) (PORT=1521))   )  )

Alternatively, you can configure multiple listeners to listen to different IP addresses.

Oracle Net supports the following communication protocols:

 ■ TCP/IP ■ TCP/IP with SSL ■ Named Pipes ■ SDP

Oracle 9i introduces the dynamic listener service registration, which means that we do not need to register the listener in listener. configure the information of the database instance to be listened to by Oracle in Ora. When the database is started, the pmon process can automatically register the current database instance to the listener list. that is to say, the sid_list_listener section above does not need to be configured. The dynamic listening server must meet the following conditions:

■ The database must be setInstance_nameAndService_naMe parameter;

■ The listener uses the default TCP protocol and port 1521 for listening;

■ If other communication protocols or listening ports are used for Listener Configuration, configure the following settings to tell Oracle to use a custom listener:

1. Use the local_listener parameter to explicitly set the listener currently in use,

2. Add the custom Listener Configuration Information to the tnsnames. ora file on the server side. If OCM is used, you can also add the Listener Configuration Information to CMAN. ora.

. Local_listener can be dynamically set through alter system.

ALTER SYSTEM SET LOCAL_LISTENER=’listener_alias’;

An example of dynamic Listener Configuration:

Configuration of the listener. ora file:

LISTENER1 =  (DESCRIPTION =      (ADDRESS_LIST =        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.205.73)(PORT = 1421))        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.64)(PORT = 1421))        (ADDRESS = (PROTOCOL = IPC)(KEY = extproc))      )   )

Local_listener parameter configuration (because a non-1521 port is used here ):

SQL> show parameter local_listenerNAME                                 TYPE         VALUE------------------------------------ ------------ -----------local_listener                       string       listener1

Tnsnames. ora Configuration:

LISTENER1= (ADDRESS_LIST=  (ADDRESS = (PROTOCOL = TCP)(HOST = dbtest)(PORT = 1421)(IP = FIRST))  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.205.73)(PORT = 1421))  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.64)(PORT = 1421)) )mayp =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = dbtest)(PORT = 1421))      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.64)(PORT = 1421))    )    (CONNECT_DATA =      (SERVICE_NAME = mayp)      (SERVER = DEDICATED)    )  )
  • TNS Configuration

The TNS configuration we mentioned is actually for tnsnames. configuration of the ora file, tnsnames. ora has client configuration and server configuration. the difference between client and server configuration is that the server configuration is related to the Listener Configuration. the following is a simple configuration example:

mayp =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = dbtest)(PORT = 1421))    )    (CONNECT_DATA =      (SERVICE_NAME = mayp)      (SERVER = DEDICATED)    )  )

Similarly, tnsnames. ora also includes two parts. The address_list part contains the listening address information of the remote database server, that is, to tell the TNS remote database to communicate with the client through some addresses; CONNECT_DATA defines the database to be connected by the client, as well as the connection mode of the database (dedicated or shared ). In a multi-IP environment, TNS can also configure multiple remote IP addresses:

mayp =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = dbtest)(PORT = 1421))      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.64)(PORT = 1421))    )    (CONNECT_DATA =      (SERVICE_NAME = mayp)      (SERVER = DEDICATED)    )  )

In a multi-IP environment, you can also configure load_balance and Failover features on the TNS side. these features are popular in the RAC environment. The load_balance feature allows clients to select any address to connect to the database and balance the connections of each address. failover enables the unique TAF feature of Oracle. TAF is short for transparent application failover. load_balance can be configured on the client or on the server. the following is a client configuration example:

mayp =(DESCRIPTION =   (ADDRESS_LIST =     (LOAD_BALANCE=ON)     (FAILOVER=ON)     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.205.73)(PORT = 1421))     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.64)(PORT = 1421))   )   (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = MAYP)      (FAILOVER_MODE =        (TYPE = SELECT)        (METHOD = BASIC)      )   ))
  • Sqlnet. ora Configuration

Sqlnet. ora is a very important configuration. It can control and manage the properties of Oracle connections, and decide whether to configure the connection on the client or on the server based on the different parameters. sqlnet. the configuration of ora is global, that is, sqlnet. the configuration of ora works for all connections. to restrict or restrict a special connection or service, you can configure the corresponding parameters in TNS. for detailed parameters, see:

Oracle Database Net Services reference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.