TNS or Transparent Network Substrate is Oracle's networking architecture. TNS provides a uniform application interface to enable network applications to access the underlying network protocols transparently.
The TNS architecture consists of three software components: TNS-based applications, Oracle Protocol Adapters, and networking software like TCP/IP.
SQL*Net V1 | SQL*Net V2 | Net8 | |
Default port | 1525/tcp | 1521/tcp | 1521/tcp |
Start command | tcpctl start | lsnrctl start | lsnrctl start |
Stop command | tcpctl stop | lsnrctl stop | lsnrctl stop |
Connect string | protocol:host:sid eg. T:SRV1:DB1 | Specified in TNSNAMES.ORA | Specified in TNSNAMES.ORA |
Config files | /etc/oratab | tnsnames.ora, sqlnet.ora & listener.ora | tnsnames.ora, sqlnet.ora & listener.ora |
Env variable | LOCAL= | TWO_TASK= | TWO_TASK= |
This configuration utility is PC based. You need to generate the necessary files on your PC and FTP or copy them to the relevant operating systems you use Oracle on.
Look at the following sample configuration files:
$ORACLE_HOME/network/admin/listener.ora --------------------------------------- LISTENER = # Listener name is LISTENER (address_list = (address= (protocol=ipc) (key=yourSID) ) (address= (protocol = tcp) (host = yourHost.domain) (port = 1521) ) ) STARTUP_WAIT_TIME_LISTENER = 0 CONNECT_TIMEOUT_LISTENER = 10 TRACE_LEVEL_LISTENER = ON TRACE_FILE_LISTENER = $ORACLE_HOME/network/trace/listener.trc SID_LIST_LISTENER = (SID_LIST= (SID_DESC= (SID_NAME=yourSID) (ORACLE_HOME=YOUR_ORACLE_HOME) ) ) $ORACLE_HOME/network/admin/sqlnet.ora ------------------------------------- automatic_ipc = ON # Set to OFF for PC's trace_level_client = OFF # Set to 16 if tracing is required sqlnet.expire_time = 0 # Idle time in minutes sqlnet.authentication_services = (ALL) names.directory_lookup = (TNSNAMES,ONAMES) names.default_domain = world name.default_zone = world $ORACLE_HOME/network/admin/tnsnames.ora --------------------------------------- dbname1, aliasname1, aliasname2 = (description = (address_list = (address = (protocol = tcp) (host = yourHost.domain) (port = 1521) ) ) (connect_data = (sid = yourSID) ) )
trace_level_client=16 trace_unique_client=yesSometimes it is useful to only trace TNSPING packets. Add the following parameters to your SQLNET.ORA file:
TNSPING.TRACE_LEVEL = 16 TNSPING.TRACE_DIRECTORY = /tmp/tnsping/The following parameters are also worth setting:
trace_file_client = cli.trc trace_directory_client = <path_to_trace_dir> log_file_client = sqlnet.log log_directory_client = <path_to_log_dir>
SQLPLUS SCOTT/TIGER@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (PORT=1521) (NODE=yourServerName))) (CONNECT_DATA=(SID=yourSid) (SERVER=DEDICATED)))You can also edit your TNSNAMES.ORA file and add the (SERVER=DEDICATED) part in the CONNECT_DATA list or simply set USE_DEDICATED_SERVER=ON in your SQLNET.ORA file.
You can also list V1 connect strings in your TNSNAMES.ORA file. Eg:
ORA1_NET1 = T:machine_name/port:database_name
Note that SQL*Net V1 is not available from version 7.3 of the database.
NOTE: This parameter is only useful on the database server side, specifying it on a client workstation will have no effect.
The following SQLNET.ORA parameter can be specified to reduce polling overhead on your system:
BREAK_POLL_SKIP=n # Number of packets to skip between checking for breaks (default=4)
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = yourSID) (PRESPAWN_MAX = 50) (PRESPAWN_LIST = (PRESPAWN_DESC = (PROTOCOL = TCP) (POOL_SIZE = 5) (TIMEOUT = 2)))) )PRESPAWN_MAX: if there are over 50 sessions connected to the database, the listener won't prespawn any more.
In LISTENER.ORA, specify multiple listeners as in:
# Define listener A... STARTUP_WAIT_TIME_LISTENER_A = 0 CONNECT_TIMEOUT_LISTENER_A = 10 LISTENER_A= (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = yourHost.domain) (PORT = 1521))) SID_LIST_LISTENER_A = (SID_LIST = (SID_DESC = (SID_NAME = yourSID) (PRESPAWN_MAX = 50))) # Define the second listener... STARTUP_WAIT_TIME_LISTENER_B = 0 CONNECT_TIMEOUT_LISTENER_B = 10 LISTENER_B= (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = yourHost.domain) (PORT = 1522))) SID_LIST_LISTENER_B = (SID_LIST = (SID_DESC = (SID_NAME = yourSID) (PRESPAWN_MAX = 50)))The TNSNAMES.ORA service for this database would be something like:
oradb1.world = (description_list= (description= (address_list= (address= (protocol=tcp) (host=yourHost.domain) (port=1521))) (connect_data = (sid = yourSID))) (description = (address_list = (address= (protocol=tcp) (host=yourHost.domain) (port=1522))) (connect_data = (sid = yourSID))))
oradb1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = TCP_COMM) (PROTOCOL = TCP) (HOST = Machine01)) (ADDRESS = (COMMUNITY = TCP_COMM) (PROTOCOL = TCP) (HOST = Machine02))) (CONNECT_DATA=( (SID=oradb1))))Suppose Machine01 is down, then every new SQL*NET connection using service oradb1 will automatically login to Machine02. However, there is one restriction, the SID must be the same on both machines. This feature can provide guaranteed login for application servers and for the Oracle Parallel Server.
tcp.validnode_checking = yes tcp.invited_nodes = (www.orafaq.org,139.185.5.111) tcp.tcp.excluded_nodes = (133.17.15.21)
Sample LISTENER.ORA file:
USE_PLUG_AND_PLAY_LISTENER = ON LISTENER = (ADDRESS_LIST = (ADDRESS= (PROTOCOL=IPC) (KEY= wblp-nt-011b_orcl.companyX.com) ) (ADDRESS= (PROTOCOL=IPC) (KEY= orcl) ) (ADDRESS = (COMMUNITY = TCPIP.companyX.com) (PROTOCOL = TCP) (Host = wblp-nt-011b.companyX.com) (Port = 1526) ) ) STARTUP_WAIT_TIME_LISTENER = 0 CONNECT_TIMEOUT_LISTENER = 10 TRACE_LEVEL_LISTENER = OFF SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = wblp-nt-011b_orcl.companyX.com) (SID_NAME = orcl) (ORACLE_HOME = /) (PRESPAWN_MAX = 10) ) )
You can also manually register an entry on your server using the NAMESCTL command. Eg:
NAMESCTL> register mydb.world -t oracle_database -d (description=(address=(protocol=tcp)(host=123.45.67.8)(port=1526))(connect_data=(sid=MYDB)))NOTE: the whole command must be entered on one line. Also, make sure you register this database with all Names Servers running in your domain.
To check if your entry is correctly recorded in the Names Server, issue this command:
NAMESCTL> query mydb.world *
Services Summary... oraweb(Registered) has 1 service handler(s)