You are on page 1of 26

Oracle Net Services

Configure Oracle Net on Server Side (LISTENER)

Main points in this section

 General information about Listener


 How does listener respond to client requests
 How to configure LISTENER (Net Manager or notepad/vi)
 How to manage LISTENER(lsnrctl commands – start, stop,
reload, set
 Dynamic registration of service
 Troubleshooting LISTENER - TNS errors
 LISTENER logging
 LISTENER tracing
General information about Listeners

• Listener is a separate process that listens on a


specific port(Default - 1521) – like lgwr, pmon (ps –
ef | grep LISTENER)
• Listener can listen for multiple services (instances)
• Listener can listen for multiple protocols – TCP/IP,
DECnet, LU6.2
• Client connection can come from the same machine or
remote machine
• $ORACLE_HOME/network/admin/listener.ora is the
LISTENER configuration file – should be backup up
• Multiple listeners can listen for one service
(instance) – to balance load for the listener
• Listener can be on a separate machine than database
instance
• Listener has a name – default name is LISTENER

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracledb.newfocus.biz)(PORT
= 1521))
)
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME=/u01/app/oracle/product/9.2.0)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = gpdb92.newfocus.biz)
(ORACLE_HOME=/u01/app/oracle/product/9.2.0)
(SID_NAME = gpdb92)
)
)

#----ADDED BY TNSLSNR 06-APR-2008 13:53:26---


PASSWORDS_LISTENER = BF9CF2DC8F4E24AC
#--------------------------------------------
How does listener respond to client requests

• Bequeath Connections
o Only for UNIX – OS has ability to spawn a new
process and pass (bequeath) information to new
process
1. Client contacts listener on specific port –
service name resolution has happened at this
point
2. Listener spawns a server process and passes
client information to the server process
3. Server process sends “RESEND” packet to client
4. Client sends “CONNECT” packet to server process
5. Server responds back with “ACCEPT” packet – and
the connection is established

Note:
Windows can simulate bequeath connection by setting up
USE_SHAERD_SOCKET registry entry
• Redirect Connections

o Client request is redirected to server process or


dispatcher when
 OS does not support bequeath connections
 When listener is on different machine than
DB instance
1. Client contacts listener on specific port –
service name resolution has happened at this
point
2. Listener spawns a new server process or a
dispatcher process if necessary
3. Server process send port number to listener
4. Listener sends port number to client
5. Client sends connect signal to server process
6. Dispatcher sends back the acknowledgement to
client – connection is established
7. PMON sends information to listener process about
number of connections with dispatcher
How to configure Listener

Net Manager
Profile  sqlnet.ora
Service Naming  tnsnames.ora
Listeners  listner.ora
Oracle Names Server  names.ora (New technology - OID)
Other parameters
• PASSWORDS
Managing Listener

Listener runs as s service on Windows


• lsnrctl
• Start
• Stop
• Status
• Services
• Reload
• Trace user/off/admin/support
• Save_config
• Change_password
• Show (trc_file, log_file, trc_level, log_status)
• Set (password, trc_file, log_file, trc_level,
log_status)
• Version
• Exit/quit

[oracle@oracledb log]$ lsnrctl

LSNRCTL for Linux: Version 9.2.0.4.0 - Production on 06-APR-2008


13:47:52

Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> help
The following operations are available
An asterisk (*) denotes a modifier or extended command:

start stop status


services version reload
save_config trace spawn
change_password quit exit
set* show*

LSNRCTL> show
The following operations are available after show
An asterisk (*) denotes a modifier or extended command:
rawmode displaymode trc_file
trc_directory trc_level log_file
log_directory log_status current_listener
startup_waittime snmp_visible save_config_on_stop

LSNRCTL> set
The following operations are available after set
An asterisk (*) denotes a modifier or extended command:

password rawmode displaymode


trc_file trc_directory trc_level
log_file log_directory log_status
current_listener startup_waittime save_config_on_stop
inbound_connect_timeout  low values can create ORA 12525 (in seconds)

LSNRCTL>
Dynamic registration of service
• Oracle 9i instance automatically registers with
listener –
o Listener must be running on same machine
o Listener name must be LISTENER
o Listener port must be 1521
o Must use the fllowing init.ora parameters
 Instance_name=GPDB92
 Service_name=GPDB92.newfocus.biz
• PMON does registration
• Useful for load balancing & automatic fail-over
• No Service listed in listner.ora – use lsnrctl
services
• Listener should beo started before the instance –
otherwise there is a time lag
• Listener must run on same machine as DB instance
• Init.ora entry – if listener is not default
o Local_listener=”(ADDRESS_LIST = (Address =
(Protocol = TCP) (host=oracledb.newfocus.biz)
(Port=1522)))”
Connect Time Failover
If one listener is down, client connects to another
listener. The following entry is place in tnsnames.ora

ORCL =
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=DBPROD)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=DBFAIL)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=PROD)(SERVER=DEDICATED)
)
)

Transparent Application Failover(TAF)


• Used in RAC
• If connection to service PROD is lost from machine
DBPROD, a new connection is established through
another machine DBFAIL
• Reconnection happens through OCI library
• Select statement is resumed without user knowing it

ORCL =
(DESCRIPTION=
(FAILOVER=ON)
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=DBPROD)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=DBFAIL)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=PROD)(SERVER=DEDICATED)
(FAILOVER_MODE=(TYPE=select)(METHOD=basic))
)
)

Client Load Balancing


Client randomly chooses the listener to connect to

ORCL =
(DESCRIPTION=
(LOAD_BALANCE=ON)
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=MWEISHAN-DELL)(PORT=1522))
(ADDRESS=(PROTOCOL=TCP)(HOST=MWEISHAN-DELL)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=ORCL))
)

Troubleshooting LISTENER - TNS errors

• Check if you can ping the machine


• Check if DB is running (mounted and open)
• DB should not be running in restricted mode
• User has “Create session” privilege
• Check if Listsner is running
• Check that tnsnames.ora entry is correct – client side
• Check entries in sqlnet.ora – client side
• Listener configured to listen for the instance

Tools

• Ping
• Lsnrctl status
• Lsnrctl services
• Listener.log
• Sqlplus scott/manager from server machine – without
listener
Listener Logging

By default listener is configured to generate log file


$ORACLE_HOME/network/log/listster.log

LOG_DIRECTORY_LISTENER =
LOG_FILE_LISTENER =

• * delimited file
• Listener startup and shutdown
• Successful and unsuccessful connection attempts
• network errors

No longer listening on:


(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
No longer listening on:
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb.newfocus.biz)(PORT=1
521)))
06-APR-2008 13:13:22 *
(CONNECT_DATA=(CID=(PROGRAM=)(HOST=oracledb.newfocus.biz)(USER=oracle))
(COMMAND=stop)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=153093120)) *
stop * 0

TNSLSNR for Linux: Version 9.2.0.4.0 - Production on 06-APR-2008


13:13:25

Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

System parameter file is


/u01/app/oracle/product/9.2.0/network/admin/listener.ora
Log messages written to
/u01/app/oracle/product/9.2.0/network/log/listener.log
Trace information written to
/u01/app/oracle/product/9.2.0/network/trace/listener.trc
Trace level is currently 0

Started with pid=3402


Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on:
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb.newfocus.biz)(PORT=1
521)))

TIMESTAMP * CONNECT DATA [* PROTOCOL INFO] * EVENT [* SID] * RETURN


CODE
06-APR-2008 13:13:25 *
(CONNECT_DATA=(CID=(PROGRAM=)(HOST=oracledb.newfocus.biz)(USER=oracle))
(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=153093120)) *
status * 0
06-APR-2008 13:13:33 *
(CONNECT_DATA=(SERVICE_NAME=gpdb.newfocus.biz)(CID=(PROGRAM=)(HOST=orac
ledb.newfocus.biz)(USER=oracle))) *
(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=10933)) * establish *
gpdb.newfocus.biz * 12514
TNS-12514: TNS:listener could not resolve SERVICE_NAME given in connect
descriptor
06-APR-2008 13:14:22 * service_register * GPDB92 * 0
06-APR-2008 13:24:22 * service_update * GPDB92 * 0
06-APR-2008 13:34:22 * service_update * GPDB92 * 0
06-APR-2008 13:36:15 *
(CONNECT_DATA=(CID=(PROGRAM=)(HOST=oracledb.newfocus.biz)(USER=oracle))
(COMMAND=services)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=153093120))
* services * 0
06-APR-2008 13:37:00 *
(CONNECT_DATA=(SERVICE_NAME=gpdb.newfocus.biz)(CID=(PROGRAM=)(HOST=orac
ledb.newfocus.biz)(USER=oracle))) *
(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=8290)) * establish *
gpdb.newfocus.biz * 12514
TNS-12514: TNS:listener could not resolve SERVICE_NAME given in connect
descriptor
06-APR-2008 13:38:35 *
(CONNECT_DATA=(SERVICE_NAME=gpdb92.newfocus.biz)(CID=(PROGRAM=)(HOST=or
acledb.newfocus.biz)(USER=oracle))) *
(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=8291)) * establish *
gpdb92.newfocus.biz * 0
06-APR-2008 13:38:43 * service_update * GPDB92 * 0

Listener Tracing
TRACE_LEVEL_LISTENER = ADMIN (OFF, USER, ADMIN, SUPPORT)
TRACE_FILE_LISTENER = LISTENER.trc
TRACE_DIRECTORY_LISTENER =

Tracing at packet levels


Side Note
How to check if the correct protocol adapters are installed
on the server side

[root@localhost] ./adapters oracle  This command is in $ORACLE_HOME/bin


Net protocol adapters linked with oracle are:
BEQ
IPC
TCP/IP
RAW
Net Naming Adapters linked with oracle are:
Oracle TNS Naming Adapter
Oracle Naming Adapter
Advanced Networking Option/Network Security products
linked with oracle are:
Oracle Security server Authentication Adapter
Configure Oracle Net on Client Side

Main points in this section

 Name resolution on client side


 Local Naming (tnsnames.ora)
 OID – LDAP implementation of Oracle (not covered)
 Host Naming (/etc/hosts or DNS)
 EZ Connect
 Troubleshooting client side connections
 What is sqlnet.ora file
What is names resolution

It is the process of finding out where the database


instance is
Local Naming

Tnsnames.ora (on client)

Important things are:


• Net Service Name (DBA) – also known as host string or
connection string
• Protocol (TCP)
• Host (gr99c0073 – you can use IP if no DNS or host
file is present)
• Port number (1521)
• Service_name (DBA - SID in older systems)
Host Naming

sqlplus shekhar/password@machine_name

• No need for any client side configuration (default –


local naming followed by host naming)
• Must use TCP/IP protocol
• Must have external naming mechanism like DNS or hosts
file available to client
• Listener should be running on default port - 1521
• Listener must be setup GLOBAL_DBNAME = name of machine

Listener.ora (Server)

How to configure for two databases on same machine


In /etc/hosts
172.24.0.236 prodDB
172.24.0.236 testDB

In listener.ora
GLOBAL_DB_NAME = prodDB & SID_NAME – prodDB
GLOBAL_DB_NAME = testDB & SID_NAME – testDB

How to connect
Sqlplus shekhar/password@prodDB
Sqlplus shekhar/password@testDB

Tnsnames.ora (client)  Not present

Sqlnet.ora(client)  may be present (see last section in


this article)

Hosts (Client)  present if no DNS is used


Trouble Shooting connectivity problems

• Use Net manager to generate all files (listener.ora,


tnanames.ora, sqlnet.ora)
• Do not use sqlnet.ora during local naming – my
recommendation
• Use ping
• Use tnsping
• Set TNS_ADMIN variable where all network files are
located
• Check for sqlnet.expire_time parameter on server side
sqlnet.ora file
• Turn Client tracing on – or check listener log file on
the server ($ORACLE_HOME/network/log/listener.log)
What is SQLNET.ORA File

Sqlnet.ora is a text file that provides SQL*Net with basic


configuration details like tracing options, default domain,
encryption, etc. This file can be found in the
$ORACLE_HOME\NETWORK\ADMIN directorySample sqlnet.ora files

Example 1:

NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, HOSTNAME)


NAMES.DEFAULT_DOMAIN = WORLD
TRACE_LEVEL_CLIENT = OFF
SQLNET.EXPIRE_TIME = 30

Parameters

• names.default_domain

The value of this parameter is appended to the net


service name if the net service name doesn't already
have a domain.

• names.directory_path

Specifies the order of naming methods that are used


when a client tries to connect to a database. Possible
values: TNSNAMES, LDAP, ONAMES, HOSTNAME, EZCONNECT.

• sqlnet.expire_time

Enables dead connection detection, that is, after the


specified time (in minutes) the server checks if the
client is still connected. If not, the server process
exits. This parameter must be set on the server.

• trace_level_client

Enables tracing if not set to off (or 0, which is the


default). Possible values: USER (4), ADMIN (10) and
SUPPORT (16).

• trace_file_client
Specifies the name of the (client) trace file. The
default is sqlnet.trc.

Common Errors

ORA-12154 “TNS: could not resolve connect identifier specified”


ORA-12198 “TNS: could not find path to destination”
ORA-12203 “TNS: Unable to connect to destination”
ORA-12533 “TNS: illegal address parameters”
ORA-12541 “TNS: No listener”

You might also like