Oracle - 我使用什么 TNS 名称文件?

发布于 2024-07-05 02:58:42 字数 107 浏览 10 评论 0原文

有时我会遇到 Oracle 连接问题,因为我无法确定数据库客户端正在使用哪个 tnsnames.ora 文件。

解决这个问题的最佳方法是什么? ++对各种平台解决方案感到满意。

Sometimes I get Oracle connection problems because I can't figure out which tnsnames.ora file my database client is using.

What's the best way to figure this out? ++happy for various platform solutions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

夜唯美灬不弃 2024-07-12 02:58:42

最简单的方法可能是检查连接到数据库的进程的 PATH 环境变量。 tnsnames.ora 文件很可能位于路径 ..\network\admin 中的第一个 Oracle bin 目录中。 TNS_ADMIN 环境变量或注册表中的值(对于当前 Oracle 主目录)可能会覆盖此值。

像其他人建议的那样使用 filemon 也可以达到目的。

The easiest way is probably to check the PATH environment variable of the process that is connecting to the database. Most likely the tnsnames.ora file is in first Oracle bin directory in path..\network\admin. TNS_ADMIN environment variable or value in registry (for the current Oracle home) may override this.

Using filemon like suggested by others will also do the trick.

塔塔猫 2024-07-12 02:58:42

不是直接回答你的问题,但我自己在尝试查找和更新所有 tnsnames 文件时感到非常沮丧,因为我安装了多个 Oracle:客户端、BI 工具、OWB 等,每个都有自己的 Oracle 主目录。 我最终创建了一个名为 TNSNamesSync 的实用程序,它将更新所有 Oracle 主目录中的所有 tnsname。 它受 MIT 许可,可在此处免费使用 https://github.com/artybug/TNSNamesSync/releases

文档在这里:
https://github.com/artchik/TNSNamesSync/blob/master/README.md

不过,这仅适用于 Windows。

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

The docs are here:
https://github.com/artchik/TNSNamesSync/blob/master/README.md

This is for Windows only, though.

撩发小公举 2024-07-12 02:58:42

strace sqlplus -L scott/tiger@orcl 帮助在 /home/oracle 上查找 .tnsnames.ora 文件,以找到它所需要的文件$ORACLE_HOME/network/admin/tnsnames.ora 文件。 感谢您的发帖。

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.

眼前雾蒙蒙 2024-07-12 02:58:42

它不应该总是“$ORACLE_HOME/network/admin/tnsnames.ora”吗?
然后您可以执行“echo $oracle_ home”或 *nix 等效操作。

@皮特霍尔伯顿
你是完全正确的。 这让我想起,还有另一个活动扳手正在开发中,名为 TWO_ TASK

根据 http://www.orafaq.com /wiki/TNS_ADMIN
TNS_ADMIN 是一个环境变量,它指向 SQL*Net 配置文件(如 sqlnet.ora 和 tnsnames.ora)所在的目录。

Shouldn't it always be "$ORACLE_ HOME/network/admin/tnsnames.ora"?
Then you can just do "echo $oracle_ home" or the *nix equivalent.

@Pete Holberton
You are entirely correct. Which reminds me, there's another monkey wrench in the works called 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.

忱杏 2024-07-12 02:58:42

默认情况下,tnsnames.ora 位于 UNIX 操作系统上的 $ORACLE_HOME/network/admin 目录中,以及 Windows 操作系统上的 ORACLE_HOME\network\admin 目录中。 tnsnames.ora 还可以存储在以下位置:

TNS_ADMIN 环境变量(或注册表值)指定的目录

在 UNIX 操作系统上,全局配置目录。 例如,在 Solaris 操作系统上,此目录为 /var/opt/oracle

如果您有多个 ORACLE_HOME,请注意您使用的是哪一个,因为 tnsnames.ora 文件的位置可能因 ORACLE_HOME 和下一个 ORACLE_HOME 而异。

对于提到 TWO_TASK 环境变量的人来说,它用于设置要连接的默认数据库服务名称(可能是另一台服务器上的数据库)。 连接时,系统会在 tnsnames.ora 文件中查找您设置的 TWO_TASK 服务名称。

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:

The directory specified by the TNS_ADMIN environment variable (or registry value)

On UNIX operating systems, the global configuration directory. For example, on the Solaris Operating System, this directory is /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.

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.

故事灯 2024-07-12 02:58:42

对于 Windows:SysInternals 中的 Filemon 将显示正在访问哪些文件。

请记住设置过滤器,这样您就不会被繁琐的文件系统流量淹没。

过滤器对话框

添加: Filemon 不适用于较新的 Windows 版本,因此您可能必须使用进程监视器

For Windows: Filemon from SysInternals will show you what files are being accessed.

Remember to set your filters so you are not overwhelmed by the chatty file system traffic.

Filter Dialog

Added: Filemon does not work with newer Windows versions, so you might have to use Process Monitor.

本宫微胖 2024-07-12 02:58:42

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:\>

它应该显示您正在使用的文件。 该实用程序位于 Oracle bin 目录中。

Oracle provides a utility called 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.

岁月打碎记忆 2024-07-12 02:58:42

对于 Linux:

$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'open.*tnsnames.ora'

显示如下内容:

open("/opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora",O_RDONLY)=7

更改为

$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'tnsnames.ora'

将显示所有失败的文件路径。

For 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.

笔落惊风雨 2024-07-12 02:58:42

还有另一个位置存储 TNS 位置:如果您使用的是 Windows,请打开 regedit 并导航到 My HKEY Local Machine/Software/ORACLE/KEY_OraClient10_home1,其中 >KEY_OraClient10_home1 是您的 Oracle 主目录。 如果有一个名为 TNS_ADMIN 的字符串条目,则该条目的值将指向 Oracle 在您的计算机上使用的 TNS 文件。

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.

寻梦旅人 2024-07-12 02:58:42

在我的开发机器上,我有三个不同版本的 Oracle 客户端软件。 我在其中之一管理 tnsnames.ora 文件。 在另外两个中,我输入了 tnsnames.ora 文件:

ifile=path_to_tnsnames.ora_file/tnsnames.ora

这样,如果由于某种原因客户端使用了错误的 tnsnames.ora 文件,它将始终以最新版本结束。

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:

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.

涙—继续流 2024-07-12 02:58:42

Codeslave 询问“难道不应该总是“$ORACLE_HOME/network/admin/tnsnames.ora”吗?答案是否定的,不是。考虑在同一台机器上对 tnsping 的这两个调用:

C:\Documents and Settings\me>D:\Oracle\10.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\10.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\10.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>

注意两个不同的参数文件位置,这取决于您正在运行的 tnsping 可执行文件(可能还取决于运行它的位置)。对于基于 tnsnames 的 oracle 网络,使用 TNS_ADMIN 变量是确保获得一致的 tnsnames.ora 文件的唯一方法。 (注意:以 Windows 为中心的答案)

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:

C:\Documents and Settings\me>D:\Oracle\10.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\10.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\10.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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文