Copyright © Oriole Corporation, 2000
This
paper describes something on which many Oracle users waste a lot of time – configuring
a client properly. We ignore any exotic setting to concentrate on the staple
food of 99% of Oracle sites, plain vanilla TCP/IP SQL*Net, without any protocol
interchange nor even TNS names server, and a UNIX or NT server. Basic stuff.
On
the server
When
a client connects to a server, it needs a broker to establish the connection.
This broker is the listener (which of course is not named listener, it would
be too easy, but tnslsnr),
which, as the name listener implies, spends most of its time waiting on a special
port for incoming connections. What the listener receives is something such
as ‘I want to connect as SCOTT/TIGER to instance ORADB’. The only thing the
listener is interested in is the instance name (although Net8 sometimes refers
to ‘services’, probably to make things look more abstract and confusing). The
instance name is great but it is not enough to know how to connect; remember,
when you are trying to work locally with Oracle, you usually need two things,
the Oracle system identifier (SID, i.e. the instance name), and the Oracle
home directory where Oracle is installed. The reason is, that you may well have
two or more different versions of Oracle installed on the same machine (especially
on development machines) and you must run the appropriate code to connect to
the right instance. The information saying ‘this instance is running this version
of Oracle’ is recorded in the SID_LIST
section
of the listener configuration file listener.ora
Most
people use a single listener; however you may start several listeners on a machine
(may be useful as in some cases you have SQL*Net incompatibilities between two
versions of Oracle, such as 7.1 and 8.x for instance you may have to start two
separate listeners, one for Oracle8 and one for Oracle7).
Setting
up the listener What
you should check :
Most
of the setup is normally automatically done by Oracle during installation all
you have to do usually is add your databases to the listener.ora
file as you create them on the server.
The
listener must be declared as an existing service; you must find under Unix a
line such as
| listener |
1521/tcp
|
# Oracle SQL*Net listener |
in
the /etc/services
file On
the client
(the
port number is usually 1521 or 1526, but you can define anything as long as
it does not conflict with something else)
The file which matters most on the client is the so called tnsnames.ora file. What does it contain ? Basically, it associates a name (the TNS alias TNS stands for Transparent (wishful thinking !) Network Substrate) with something more physical, namely a host name and an instance identifier. It must also say which port the listener is listening on at the other side.
So what happens ?
Single_instance
= ( # This is the TNS alias Single_instance.world
= (
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = ORACLE.world)
# You can live without this
(PROTOCOL = TCP)
# Underlying protocol
(Host = chillywilly.us.oracle.com)
# Host name
(Port = 1521) #
Port the listener is listening on
)
)
(CONNECT_DATA =
(SID = PROD ) # Instance name on the target machine
#
you can live without GLOBAL_NAME
)
)
# Another alias for the same database
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = ORACLE.world)
(PROTOCOL = TCP)
(Host = chillywilly.us.oracle.com)
(Port = 1521)
)
)
(CONNECT_DATA =
(SID = PROD)
)
)
The machine may be down. Try to ping it.
There may also be problems at the TCP layer. You should check that you can telnet or ftp the machine.
There
may be firewall problem. You can check it with :
$
telnet chillywilly.us.oracle.com 1521
Trying 255.255.255.255...
telnet: Unable to connect to remote host: Connection refused
(A
typical ‘no, you can’t enter here’ message). Check with network engineers
and/or security people so that you are allowed to connect to this port on
the host from your client.
A
common error at his stage is
ORA-12505:
TNS:listener could not resolve SID given in connect descriptor
The special case of database links
One
creates a database link by specifying, on a machine, a user name, password and
connect string to another database. The thing to be aware of is that with a
database link, the actual client of the database one tries to connect to through
the database link is the database on which the database link was created, not
the ‘final’ client.
Suppose
you are using SQL*Plus on a PC, and from here accessing a database named ALPHA
on which a database link is created to give access to a database named OMEGA.
When
you are connected to ALPHA and try a
select
* from some_table@omega;
The
tnsnames.ora
file
which is used to fetch the data is located on the same server as the ALPHA machine
NOT on your PC. It often puzzles people to be able, from their machine, to be
able to connect with
sqlplus
scott/tiger@omega
And
getting an ORA-12154 error (or the reverse). In fact, different tnsnames.ora
files
are used in each case.
| Stay
tuned.... |