Oracle 上下文中的 TNS:listener 是什么?

发布于 2024-08-18 17:41:59 字数 1024 浏览 13 评论 0原文

边界服务器故障问题,但我想我会先在这里尝试,因为我过去在 Oracle 问题上很幸运。

我尝试从 PHP 连接到 Oracle 数据库,但出现以下错误。

ORA-12505: TNS:listener does not currently know of SID given in connect descriptor

这是PHP 报告的错误,也是Oracle 的listener.log 中显示的错误。

我当前的问题是修复这个错误。我想回答的更大问题是 Oracle 连接模型如何工作?

这是在我的本地 Windows 计算机上运行的开发环境中,并且一直运行到现在。不幸的是,环境被交给了我(我没有设置它),而设置它的人无法帮助我调试它。

如果我在 MySQL 或 PostgreSQL(我更熟悉的两个系统)中遇到类似的错误,我会检查以确保数据库进程正在运行,然后尝试使用用户名/密码/手动连接到数据库连接字符串。不幸的是,我不熟悉 Windows 上的 Oracle 工具(除了 SQL Developer),并且我不知道 Oracle 上下文中的 TNS:listener 或 SID 是什么(我有模糊的想法,但模糊的想法很少有帮助)你正在调试这样的东西)

任何一般性的建议将不胜感激。

每条评论的更新

我的 tnsnames.ora 文件中有很多完整的内容,相关条目是

OBS2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = steel-ae39650)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = OBS2)
    )
  )

当我运行时,这不会反映在实例列表中

    LSNRCTL> services

所以我想我的下一个问题是,我该如何做尝试手动启动OBS2实例?

Borderline ServerFault question, but figured I'd try here first since I've had luck with Oracle questions in the past.

I'm trying to connect to an oracle database from PHP, and I'm getting the following error.

ORA-12505: TNS:listener does not currently know of SID given in connect descriptor

This is the error that PHP reports, and the error that shows up in Oracle's listener.log.

My immediate problem is fixing this error. The larger question I'd like answered is how does Oracle connection model work?

This is in a development environment that's running on my local windows machine and has been working up until now. Unfortunately, the environment was handed to me (I didn't set it up) and the people who did set it up are unavailable to help me debug it.

If I was getting a similar error with MySQL or PostgreSQL (two systems I'm more familiar with), I'd check to ensure that a database process was running, and then attempt to connect manually to the database using the username/password/connection string. Unfortunately, I'm not familiar with the Oracle tools on windows (other than SQL Developer) and I don't know what a TNS:listener or SID are in the context of Oracle (I have vague ideas, but vague ideas rarely help when you're debugging something like this)

Any general advice would be appreciated.

Updates per Comments:

There's a number of entires in my tnsnames.ora file, the relevant entry being

OBS2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = steel-ae39650)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = OBS2)
    )
  )

This is not reflected in the list of instances when I run

    LSNRCTL> services

So I think my next question is, how do I attempt to manually start up the OBS2 instance?

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

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

发布评论

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

评论(3

绮烟 2024-08-25 17:41:59

TNS 名称就像服务实例的别名。在这方面,TNS 侦听器服务充当您的一种查找服务。如果您尝试通过 TNS 名称连接的实际服务无效,它将失败并显示该错误消息。

然后,您可以使用命令行工具测试 TNS 侦听器是否正确地看到该服务:

%>lsnrctl services

应该输出类似以下内容:

Service "myservice" has 1 instance(s).
  Instance "myinstance", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1002 state:ready
         DISPATCHER <machine: LOCALHOST, pid: 12345>
         (ADDRESS=(PROTOCOL=tcp)(HOST=LOCALHOST)(PORT=6789))

您能否发布相关的 TNS 条目(在 tnsnames.ora 中)文件)?它位于 ORAHOME\client 或 db\ADMIN\NETWORK 中。如果您同时拥有客户端和服务器,为了安全起见,请确保 tnsnames.ora 文件的两个副本都具有正确的值。

以下是 tnsnames.ora 中名为“mydb”的正确 TNS 名称定义示例:

myDbAlias =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 12345)(QUEUESIZE = 100))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = myservice)
    )
  )

A TNS name is like an alias to your service instance. The TNS listener service acts as a sort of lookup service for you in this regard. It will fail with that error message if the actual service you're trying to connect to via a TNS name isn't valid.

You can then test out to see if the TNS listener sees the service correctly using the command line tool:

%>lsnrctl services

Which should output something like the following:

Service "myservice" has 1 instance(s).
  Instance "myinstance", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1002 state:ready
         DISPATCHER <machine: LOCALHOST, pid: 12345>
         (ADDRESS=(PROTOCOL=tcp)(HOST=LOCALHOST)(PORT=6789))

Can you please post the relevant TNS entry (in the tnsnames.ora file)? It is located in ORAHOME\client or db\ADMIN\NETWORK. If you have both client and server, make sure both copies of the tnsnames.ora file have correct values, just to be safe.

Here's an example of a proper TNS name definition in tnsnames.ora called 'mydb':

myDbAlias =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 12345)(QUEUESIZE = 100))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = myservice)
    )
  )
落花浅忆 2024-08-25 17:41:59

只是想补充一点,因为我最近遇到了类似的连接问题,这让我抓狂,直到我弄清楚发生了什么。

首先,关键字SID和SERVICE_NAME并不完全相同。这是我的第一个错误假设。在许多环境中,您可以互换 SID 和 SERVICE_NAME,但并非总是如此,这取决于情况。

也就是说,您的错误暴露了问题:您在连接字符串中指定 SID,而不是 tnsnames 成功使用的 SERVICE_NAME

因此,如果您在代码中指定连接字符串,请尝试在连接字符串中使用 SERVICE_NAME 关键字(*或者,如果您已使用 SERVICE_NAME 并且无法连接,请尝试使用 SID 关键字*)。

我知道答案过于简单,但很容易尝试,可能会帮别人省去一些麻烦。

希望有帮助。

Just wanted to add to this, as I recently had a similar connection issue that drove me nuts until I figured out what was happening.

First, the keywords SID and SERVICE_NAME are not exactly the same. This was my first wrong assumption. In many environments you can interchange SID and SERVICE_NAME, but not always, it depends.

That said, your error gives away the problem: you're specifying SID in a connection string instead of the SERVICE_NAME that tnsnames successfully uses.

So, if you are specifying the connect string in your code, try using SERVICE_NAME keyword in the connect string (*or, if you've already using SERVICE_NAME and cannot connect, try using SID keyword*).

Overly simplistic answer I know, but easy to try and may save someone some headaches.

Hope that helps.

羁绊已千年 2024-08-25 17:41:59

连接到没有已发布 tnsname 的 10g(或更高版本)数据库。

Mike Atlas 的答案相当全面,但请注意,您可以使用 [//]host_name[:port][/service_name] HTH

C

Mike Atlas' answer is fairly comprehensive, but note that you can connect to 10g (or later) DBs which don't have a published tnsname using [//]host_name[:port][/service_name]

HTH

C.

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