Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Laura.

Asked: July 29, 2003 - 10:00 pm UTC

Last updated: November 08, 2005 - 9:48 pm UTC

Version: 8.1.7

Viewed 10K+ times! This question is

You Asked

Hello Tom:

Apologies in advance for the lengthy background information:

On a Solaris 8 box, I have two 8i and one 9i database. The listener for all three is the 8i version; the 9i listener is not running. I created public db links in the 9i database to each of the 8i databases, and verified they were active. The 9i db links were created using the syntax "create public database link linkname connect to user identified by password using 8i_service_name." The 8i_service_name = database name. Also, in the 9i tnsnames.ora, I created an alias for the 9i database.

Although user oracle owns all three databases, I source different environment files before starting/stopping 8i or 9i databases.

All that said:

On Solaris, having sourced my 9i environment, if I connected to the 9i database using syntax "connect system/password", the statement "select * from dual@8i_database_link" worked correctly.

However, if I connected to my 9i database using syntax "connect system/password@9i_alias", the the same statement failed with error "ORA-12154: TNS could not resolve service name."
This is the alias that is defined in the 9i tnsnames.ora file.

Last, on Windows, I used a query tool to connect to the 9i database, with a local tnsnames.ora file where the service name = database name. The statement "select * from dual@8i_database_link" worked correctly.

The db link failed to work when I connected to the database using the tns alias. Other non-db link queries against the database worked correctly, and I verified that the database information in v$instance was the same when connected via the tns alias or the standard database name.

What worked is why I'm submitting this question for consideration: when I updated the 8i tnsnames.ora file with the 9i database alias (which I had only placed into the 9i tnsnames.ora file), the db link finally worked.

Why would a 9i database and 9i db link refer to the 8i tnsnames.ora file to resolve the connection via the link?

Thank you

LHSallwasser

and Tom said...

when you connect "system/manager" -- the dedicated server is spawned by you, it inherits your environment. so the dedicated server finds the tnsnames.ora by looking in the environment which is set for 9i.

When you connect "system/manager@tns" -- the dedicated server is spawned by the listener, it inherits the listeners environment. so now the dedicated server finds the tnsnames.ora by looking in the environment which is set for 8i!


You should have a SINGLE, COMMON tnsnames.ora file on this server

All environments should use TNS_ADMIN (environment variable) to locate this single file.


Also -- the supported configuration is to use the 9i listener to access 9i and 8i. It is not supported to use the listener of the lower release like you are.



Here is a detailed example of the system/manager vs system/manager@tns

if you use scott/tiger, then you (your sqlplus) forks off the dedicated server. That is what reads the tnsnames.ora. It (dedicated server) inherits YOUR environment (oracle_home, tns_admin).

When you use scott/tiger@database -- the dedicated server inherits the LISTENERS environment (oracle_home,tns_admin)

scott/tiger -- dedicated server could be reading a TOTALLY different tnsnames.ora then
scott/tiger@database -- is.

Consider the following:

1) I copied the tnsnames.ora from /var/opt/oracle into my home directory.
2) I added an entry tomsentry for a database to that file only
3) I created a database link ora817dev.us.oracle.com connect to scott identified by tiger using 'tomsentry.world'

Now, the following are cuts and pastes:

$ sqlplus scott/tiger
SQL*Plus: Release 8.1.5.0.0 - Production on Wed Jan 29 18:45:20 2003
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

scott@ORA815> select * from dual@ora817dev.us.oracle.com;

D
-
X

scott@ORA815> set echo on
scott@ORA815> @getspid
scott@ORA815> select a.spid dedicated_server,
2 b.process clientpid
3 from v$process a, v$session b
4 where a.addr = b.paddr
5 and b.audsid = userenv('sessionid')
6 /

DEDICATED CLIENTPID
--------- ---------
11959 11958

scott@ORA815> !/usr/ucb/ps -auxwwe | grep 11959 | grep -v grep
ora815 11959 0.1 3.68954453776 ? S 18:45:20 0:00 oracleora815 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) HOME=/export/home/tkyte PATH=/export/home2/ora815/bin:/opt/gnu/bin:/usr/local/bin:/usr/ucb:/usr/bin:/export/home/tkyte/bin:/usr/ucb:/export/home/ora817/bin:/export/home/tkyte/src/sqlstuff:/usr/openwin/bin:/usr/etc:.:/usr/ccs/bin:/usr/sbin LOGNAME=tkyte HZ=100 TERM=vt100 TZ=US/Eastern SHELL=/usr/bin/csh MAIL=/var/mail/tkyte PWD=/export/home/tkyte USER=tkyte ORACLE_HOME=/export/home2/ora815 ORACLE_SID=ora815 NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1 ORACLE_PROC_MAKEFILE=/export/home2/ora815/precomp/demo/proc/demo_proc.mk LD_LIBRARY_PATH=/export/home2/ora815/lib SQLPATH=/net/aria/export/home/tkyte/src/sqlstuff MANPATH=/usr/openwin/share/man:/usr/man:/usr/local/man:/opt/GCC2723/man CLASSPATH=.:/export/home2/ora815/jdbc/lib/classes12.zip LARCH_PATH=.:/export/home/tkyte/lclint-2.4b/lib LCLIMPORTDIR=/export/home/tkyte/lclint-2.4b/imports PW=tkyte/tkyte TNS_ADMIN=/export/home/tkyte ORA_NET2_DESC=9,12

Notice how the dedicated servers environment has my tns_admin...

scott@ORA815> exit
Disconnected from Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

$ sqlplus scott/tiger@ora815.us.oracle.com
SQL*Plus: Release 8.1.5.0.0 - Production on Wed Jan 29 18:46:04 2003
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

scott@ORA815> select * from dual@ora817dev.us.oracle.com;
select * from dual@ora817dev.us.oracle.com
*
ERROR at line 1:
ORA-12154: TNS:could not resolve service name


scott@ORA815> @getspid

DEDICATED CLIENTPID
--------- ---------
11996 11994

scott@ORA815> !/usr/ucb/ps -auxwwe | grep 11996 | grep -v grep
ora815 11996 0.1 3.68947253800 ? S 18:46:04 0:00 oracleora815 (LOCAL=NO) HOME=/export/home/rmattama PATH=/export/home/ora817/bin:/opt/gnu/bin:/usr/local/bin:/usr/ucb:/usr/bin:/export/home/rmattama/bin:/usr/ucb:/export/home/ora817/bin:/export/home/rmattama/src/sqlstuff:/usr/openwin/bin:/usr/etc:.:/usr/ccs/bin:/usr/sbin:/export/home/sdillon/sail/bin LOGNAME=rmattama HZ=100 TERM=vt100 TZ=US/Eastern SHELL=/usr/bin/csh MAIL=/var/mail/rmattama _INIT_PREV_LEVEL=S _INIT_RUN_LEVEL=3 _INIT_RUN_NPREV=0 _INIT_UTS_ISA=sparc _INIT_UTS_MACHINE=sun4u _INIT_UTS_NODENAME=aria-dev _INIT_UTS_PLATFORM=SUNW,Ultra-4 _INIT_UTS_RELEASE=5.7 _INIT_UTS_SYSNAME=SunOS _INIT_UTS_VERSION=Generic_106541-20 PWD=/export/home/rmattama/platform/people/owb USER=rmattama ORACLE_HOME=/export/home2/ora815 ORACLE_SID=ora815 ORACLE_PROC_MAKEFILE=/export/home/ora817/precomp/demo/proc/demo_proc.mk LD_LIBRARY_PATH=/export/home/ora817/lib SQLPATH=/net/aria/export/home/tkyte/src/sqlstuff MANPATH=/usr/openwin/share/man:/usr/man:/opt/gnu/man:/opt/GCC2723/man CLASSPATH=/export/home/ora817/jdbc/lib/classes111.zip:/export/home/tkyte/j:/export/home/oracle8i/sqlj/lib/runtime.zip:. LARCH_PATH=.:/export/home/tkyte/lclint-2.4b/lib LCLIMPORTDIR=/export/home/tkyte/lclint-2.4b/imports PW=tkyte/tkyte ORACLE_BASE=/export/home/ora817 ORA_NET2_DESC=20,23


In the second case -- you can see that in the environment of our dedicated server, there is NO tns_admin.

This is undoubtably what you are seeing -- that the environment of the listener is DIFFERENT then your environment and when you connect direct, you are reading a wholly different tnsnames.ora file.


Rating

  (13 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

inherits the listeners environment

Kiro, July 30, 2003 - 9:36 am UTC

Hi Tom
You said:
When you connect "system/manager@tns" -- the dedicated server is spawned by the
listener, it inherits the listeners environment
I am a little bit confused about it. I am using locally installed sqlplus and have entry in registry "TNS_ADMIN" pointing to my local tnsnames.ora(c:\orant\tnsnames.ora). Listener in on another(remote) Win2000 box.

By my opinion every time when I have connected to "system/manager@tns" this local tnsnames.ora will be used instead of tnsnames.ora from listeners environment. Am I right or not?
Regard
Kiro

Tom Kyte
July 30, 2003 - 10:18 am UTC

you are wrong, the example above proves that.


when you connect via a listener, the environment comes from THAT LISTENER. if you use an 8i listener, you'll have an 8i environment;

when you connect direct, without the listener, the environment comes FROM YOU.


that was the entire point of the exercise above.

kiro, July 30, 2003 - 10:39 am UTC

Thanks Tom

inherits the listeners environment

Haratsaris, July 30, 2003 - 2:02 pm UTC

Tom,
I have a Oracle Applications 11.0.3 environment with 8.1.7 database that uses different TNS_ADMINS because I´ve got some special services like Report Agents and Transaction Managers (FNDFS,OEORPC) which belongs from a different Oracle Version (8.0.6). Could I just use one 8.1.7 listener for both services ( database and OAP Services) rather than another listener 8.0.6.
Thanks a lot !

Tom Kyte
July 30, 2003 - 2:24 pm UTC

yes, you should be able to as far as I know. I don't have an environment set up to test it out however. But you should be able to merge the two tnsnames into one and use just one. I don't know if APPS has any special requirements in this area.

Database Link and tnsnames.ora response

LHollister Sallwasser, July 30, 2003 - 5:02 pm UTC

Thank you for the explanation and the test case. This also clarified other tns issues I've experienced. We will configure as recommended, with the 9i listener serving the 8i databases, as soon as possible. One observation regarding the review posted by Haratsaris: given Tom's response regarding environments that are determined by the listener, you may want to keep the 8.0.6 listener working for the admin and middle tiers. There are library files that exist only in the old 8.0.6 home, and you may find that certain concurrent requests or external interfaces fail if these files can't be found by user apps. I run 11.5.8 ERP and CRM.

Tom Kyte
July 30, 2003 - 7:33 pm UTC

it'll set the oracle-home for you...

Interesting behavior...

Mark Wooldridge, July 30, 2003 - 10:15 pm UTC

As always, your knowledge of Oracle seems to be endless.

Sorry for asking a question in a review, but the a previous reviewers comment make me think. Would the automatic_ipc parameter affect what environment you would get? I could see where if set to yes and if on the same box the connection of system/manager@tns might get the local environment of the user connected to the database.

Tom Kyte
July 31, 2003 - 7:00 am UTC

automatic-ipc means you used the listener.

ipc is just interprocess communication, it doesn't mean you forked the process off and the only way to inherit an environment is to be the child process. the process would still be the child of the listener.

Database Link and tnsnames.ora response

Haratsaris, July 31, 2003 - 3:32 pm UTC

Ok, So if I use symbolic links from 8.1.7 to 8.0.6 libraries (8.1.7 missing libraries), 8.0.6 services should work with 8.1.7 listener, am I right ?


Tom Kyte
July 31, 2003 - 7:14 pm UTC

no no -- you just put the right oracle-home in the configuration files.

Excerllent! It solves a mystery in our replication environment.

A reader, October 14, 2003 - 6:08 pm UTC


Restart

Justin, March 03, 2005 - 4:39 am UTC

Hi,

I'had the same problem the original poster had:

One listener, for differeet db's, and the tns entry for the link was not in the tnsnames used by the listner.

Since these are all production databases.
What do I have to restart to reflect the changes?
Listner or the DB hosting the link or both?

Thanks for the perfect explanation for what seemed a mystery

Justin

Tom Kyte
March 03, 2005 - 7:52 am UTC

not sure what you are asking -- but if you were missing a tnsnames entry in the tnsnames.ora, you could just edit it, no start is needed for that.

Justin, March 03, 2005 - 6:10 am UTC

Sorry,

for the second part.
It'wasn't a restart thing.

We had put the tns entry in the listners tnsname, but that did not help.

Now, we found out

The listener is running under user1
but the instances were all started under user 2, where normally each instance should have been started with it's own user (that was a mistake in the shell script starting the instances).

Now the link worked, when we put the tns in the user2's tnsnames, not the listener's.

connection was always via user/pw@db

So my question is when is the listners tnsnames used, only when there doesnt exist one for the db?

What ist the order?

Regards,

Justin

PS: This textbox is really small even on a 17" normal screen.

Tom Kyte
March 03, 2005 - 7:54 am UTC

I like it small -- i want small, I want small, concise to the point....


but that aside, the "listeners" environment is used to find the tnsnames.ora file for database links always when you do "u/p@db" -- the TNS_ADMIN can be used to override any of the defaults.

If TNS_ADMIN is not defined.

Kashif, June 11, 2005 - 1:00 pm UTC

Hi Tom -

If the TNS_ADMIN environment variable is not defined on a Unix database server, what is the default search hierarchy when trying to resolve a service name defined in a database link? This is what I found on Metalink, Note 114085.1 (though I am unclear whether this hierarchy applies to both client connections and db link service name resolutions):

Sun Solaris running Oracle 8i or 9i
First: The oracle user's home directory is searched for a hidden '.tnsnames.ora'
Second: The value of the TNS_ADMIN environment variable.
Third: /var/opt/oracle
Fourth: $ORACLE_HOME/network/admin

Does this sound about right? Note that I am trying to figure out the search hiearchy for a db link's service name, not for a SQL Plus connection to the database. Hope this makes sense. Thanks.

Kashif


Tom Kyte
June 11, 2005 - 2:53 pm UTC

this is always talking about a client -- for the file is on the client and if you were on the server, we'd have already found it!


see
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:18064818873846 <code>

that is how I would check to see what it truly is -- what the client searches through to find the tnsnames.ora file. (truss on solaris is like strace)


for a dblink, the CLIENT is the DATABASE, so it'll be using the search path set up by the DATABASES environment. It'll go through the same search pattern as sqlplus does, assuming the environments are the same.

TNS_ADMIN typically "trumps" unless you have that hidden file in $HOME.

Ok...

A reader, June 11, 2005 - 7:38 pm UTC

Thanks Tom. So, to ensure that my database (Oracle) environment uses the TNS_ADMIN variable, I go in as the Oracle user and set the TNS_ADMIN variable, right? Thanks.

Kashif


Tom Kyte
June 11, 2005 - 8:18 pm UTC

before STARTING the database, yes.

Excellent explanation of what spawns dedicated server

Max, November 07, 2005 - 9:05 pm UTC

Hi Tom,

That is an absolutely clear explanation of how server process is started.

How does direct hand off fits the picture here? For example I - start sqlplus session on the same machine as database server and listener
- conn scott/tiger@mydatabase (this should connect sqlplus process to the listener)
- listener spawns a new dedicated server process and hands off (not redirect) the connection

Is this done on the TCP/IP level:
- request listener for TCP/IP connection at port 1521
- listener responds with ask and provides new random generated port (say 2343)
- client process connects to the listener through 2343
- listener passes port 2343 to dedicated server

Or there is other mechanism involved in direct
hand off?

Looking forward to you reply

Tom Kyte
November 08, 2005 - 9:48 pm UTC

it would be that the listener creates new socket on wildcard port, listener forks off dedicated server, listener closes that socket but tells client "if you connect to 2343...." and client connects to dedicated server.

Thank you!

Bob, October 17, 2006 - 2:44 pm UTC

2 hours of db link debugging and I fixed it it 2 minutes after reading your first two paragraphs.

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.