Oracle - 我使用的是什么 TNS 名称文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle - What TNS Names file am I using?
提问by Mark Harrison
Sometimes I get Oracle connection problems because I can't figure out which tnsnames.ora file my database client is using.
有时我会遇到 Oracle 连接问题,因为我无法确定我的数据库客户端正在使用哪个 tnsnames.ora 文件。
What's the best way to figure this out? ++happy for various platform solutions.
解决这个问题的最佳方法是什么?++对各种平台解决方案感到满意。
回答by stjohnroe
Oracle provides a utility called tnsping
:
Oracle 提供了一个名为 的实用程序tnsping
:
R:\>tnsping someconnection
TNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20
08 10:38:07
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\Oracle92\network\ADMIN\sqlnet.ora
C:\Oracle92\network\ADMIN\tnsnames.ora
TNS-03505: Failed to resolve name
R:\>
R:\>tnsping entpr01
TNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20
08 10:39:22
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\Oracle92\network\ADMIN\sqlnet.ora
C:\Oracle92\network\ADMIN\tnsnames.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = **)
(PROTOCOL = TCP) (Host = ****) (Port = 1521))) (CONNECT_DATA = (SID = ENTPR0
1)))
OK (40 msec)
R:\>
This should show what file you're using. The utility sits in the Oracle bin
directory.
这应该显示您正在使用的文件。该实用程序位于 Oraclebin
目录中。
回答by Mark Harrison
For linux:
对于Linux:
$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'open.*tnsnames.ora'
shows something like this:
显示如下:
open("/opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora",O_RDONLY)=7
Changing to
更改为
$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'tnsnames.ora'
will show all the file paths that are failing.
将显示所有失败的文件路径。
回答by Trumpi
There is another place where the TNS location is stored: If you're using Windows, open regedit
and navigate to My HKEY Local Machine/Software/ORACLE/KEY_OraClient10_home1
where KEY_OraClient10_home1
is your Oracle home. If there is a string entry called TNS_ADMIN
, then the value of that entry will point to the TNS file that Oracle is using on your computer.
还有另一个存储 TNS 位置的地方:如果您使用的是 Windows,请打开regedit
并导航到您的 Oracle 家My HKEY Local Machine/Software/ORACLE/KEY_OraClient10_home1
所在的位置KEY_OraClient10_home1
。如果有一个名为 的字符串条目TNS_ADMIN
,则该条目的值将指向 Oracle 在您的计算机上使用的 TNS 文件。
回答by Ishmaeel
For Windows: Filemonfrom SysInternals will show you what files are being accessed.
对于 Windows:来自 SysInternals 的Filemon将显示正在访问哪些文件。
Remember to set your filters so you are not overwhelmed by the chatty file system traffic.
请记住设置过滤器,这样您就不会被繁琐的文件系统流量所淹没。
Added:Filemon does not work with newer Windows versions, so you might have to use Process Monitor.
补充:Filemon 不适用于较新的 Windows 版本,因此您可能必须使用Process Monitor。
回答by Rene
On my development machine I have three different versions of Oracle client software. I manage the tnsnames.ora
file in one of them. In the other two, I have entered in the tnsnames.ora
file:
在我的开发机器上,我有三个不同版本的 Oracle 客户端软件。我tnsnames.ora
在其中之一管理文件。在另外两个中,我已经在tnsnames.ora
文件中输入:
ifile=path_to_tnsnames.ora_file/tnsnames.ora
This way, if for some reason the wrong tnsnames.ora
file is used by a client, it will always end up at the up-to-date version.
这样,如果由于某种原因tnsnames.ora
客户端使用了错误的文件,它最终将始终处于最新版本。
回答by DCookie
Codeslave asks "Shouldn't it always be "$ORACLE_ HOME/network/admin/tnsnames.ora"? The answer is no, it isn't. Consider these two invocations of tnsping on the same machine:
Codeslave 询问“不应该总是“$ORACLE_HOME/network/admin/tnsnames.ora”吗?答案是否定的,不是。考虑在同一台机器上对 tnsping 的这两个调用:
C:\Documents and Settings\me>D:\Oracle.2.0_DB\BIN\tnsping orcl
TNS Ping Utility for 32-bit Windows: Version 10.2.0.4.0 - Production on 09-OCT-2
008 14:30:12
Copyright (c) 1997, 2007, Oracle. All rights reserved.
Used parameter files:
D:\Oracle.2.0_DB\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx
)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))
OK (40 msec)
C:\Documents and Settings\me>tnsping orcl
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 09-OCT-2
008 14:30:21
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
D:\oracle.2.0_Client\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = XXXX)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))
OK (20 msec)
C:\Documents and Settings\me>
Note the two different parameter file locations, that are dependent on which tnsping executable you're running (and perhaps where it's being run from). For tnsnames-based oracle networking, using the TNS_ADMIN variable is the only way to ensure you're getting a consistent tnsnames.ora file. (NOTE: Windows-centric answer)
请注意两个不同的参数文件位置,它们取决于您正在运行的 tnsping 可执行文件(以及它的运行位置)。对于基于 tnsnames 的 oracle 网络,使用 TNS_ADMIN 变量是确保获得一致 tnsnames.ora 文件的唯一方法。(注意:以 Windows 为中心的答案)
回答by DCookie
By default, tnsnames.ora is located in the $ORACLE_HOME/network/admin directory on UNIX operating systems and in the ORACLE_HOME\network\admin directory on Windows operating systems. tnsnames.ora can also be stored the following locations:
默认情况下,tnsnames.ora 在 UNIX 操作系统上位于 $ORACLE_HOME/network/admin 目录中,在 Windows 操作系统上位于 ORACLE_HOME\network\admin 目录中。tnsnames.ora 也可以存储在以下位置:
The directory specified by the TNS_ADMIN environment variable (or registry value)
TNS_ADMIN 环境变量(或注册表值)指定的目录
On UNIX operating systems, the global configuration directory. For example, on the Solaris Operating System, this directory is /var/opt/oracle
在 UNIX 操作系统上,全局配置目录。例如,在 Solaris 操作系统上,此目录为 /var/opt/oracle
If you have multiple ORACLE_HOMES, be aware of which one you are using, as the location of the tnsnames.ora file can vary from one ORACLE_HOME to the next.
如果您有多个 ORACLE_HOME,请注意您使用的是哪一个,因为 tnsnames.ora 文件的位置可能因 ORACLE_HOME 的不同而不同。
For the person who mentioned the TWO_TASK environment variable, that is used to set a default database service name to connect to (which could be a database on another server). The service name you set TWO_TASK to is then looked up in the tnsnames.ora file when you connect.
对于提到 TWO_TASK 环境变量的人,它用于设置要连接的默认数据库服务名称(可能是另一台服务器上的数据库)。连接时,将在 tnsnames.ora 文件中查找您设置为 TWO_TASK 的服务名称。
回答by BIBD
Shouldn't it always be "$ORACLE_ HOME/network/admin/tnsnames.ora"? Then you can just do "echo $oracle_ home" or the *nix equivalent.
不应该总是“$ORACLE_HOME/network/admin/tnsnames.ora”吗?然后你可以只做“echo $oracle_home”或 *nix 等价物。
@Pete Holberton You are entirely correct. Which reminds me, there's another monkey wrench in the works called TWO_ TASK
@Pete Holberton 你是完全正确的。这让我想起了作品中还有一个猴子扳手叫做TWO_TASK
According http://www.orafaq.com/wiki/TNS_ADMIN
TNS_ADMIN is an environment variable that points to the directory where the SQL*Net configuration files (like sqlnet.ora and tnsnames.ora) are located.
根据http://www.orafaq.com/wiki/TNS_ADMIN
TNS_ADMIN 是一个环境变量,指向 SQL*Net 配置文件(如 sqlnet.ora 和 tnsnames.ora)所在的目录。
回答by sri
strace sqlplus -L scott/tiger@orcl
helps to find .tnsnames.ora
file on /home/oracle
to find the file it takes instead of $ORACLE_HOME/network/admin/tnsnames.ora
file. Thanks for the posting.
strace sqlplus -L scott/tiger@orcl
有助于查找.tnsnames.ora
文件/home/oracle
以查找所需的文件而不是$ORACLE_HOME/network/admin/tnsnames.ora
文件。感谢您的发帖。
回答by artybug
Not direct answer to your question, but I've been quite frustrated myself trying find and update all of the tnsnames files, as I had several oracle installs: Client, BI tools, OWB, etc, each of which had its own oracle home. I ended up creating a utility called TNSNamesSync that will update all of the tnsnames in all of the oracle homes. It's under the MIT license, free to use here https://github.com/artybug/TNSNamesSync/releases
不是直接回答您的问题,但我在尝试查找和更新所有 tnsnames 文件时感到非常沮丧,因为我安装了几个 oracle:客户端、BI 工具、OWB 等,每个都有自己的 oracle 主页。我最终创建了一个名为 TNSNamesSync 的实用程序,它将更新所有 Oracle 主目录中的所有 tnsname。它在 MIT 许可下,在这里免费使用https://github.com/artybug/TNSNamesSync/releases
The docs are here: https://github.com/artchik/TNSNamesSync/blob/master/README.md
文档在这里:https: //github.com/artchik/TNSNamesSync/blob/master/README.md
This is for Windows only, though.
不过,这仅适用于 Windows。