NodeJS Postgres错误getaddrinfo ENOTFOUND [英] NodeJS Postgres error getaddrinfo ENOTFOUND

查看:340
本文介绍了NodeJS Postgres错误getaddrinfo ENOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pg:// user:pass @ localhost:port / table 连接到我的AWS数据库。当我使用localhost时,该应用程序运行良好,但是当我尝试连接AWS服务器时,它就会崩溃。

I use pg://user:pass@localhost:port/table for connecting to my AWS database. When I use localhost, the app works fine, but when I try to connect the AWS server it falls apart.

一个简单的连接代码也给我这个错误。
数据库名称为people,它在端口8080上运行,但是即使我在conString中声明了正确的端口号,该错误也会显示5432。

Even a simple connection code gives me this error. The database name is people and it's running on port 8080 but in this error it's showing 5432 even if I declare the correct port number in the conString.


错误:getaddrinfo ENOTFOUND人们:5432
在errnoException(dns.js:26:10)
在GetAddrInfoReqWrap.onlookup [作为未完成](dns.js:77:26)

Error: getaddrinfo ENOTFOUND people people:5432 at errnoException (dns.js:26:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

到目前为止,这是我的代码:

This is my code so far:

var pg = require("pg");

var conString = "pg://someuser:pass@db-endpoint:8080/postgres";
var client = new pg.Client(conString);
client.connect();


推荐答案

如果您确定连接字符串已经正确如描述的一个gnerkus一样,您需要检查的最后一件事是您的密码。如果其中包含非字母数字字符,则可能是导致此问题的原因。似乎是Node.js或JavaScript本身的工作方式引起了这一点(我不太确定,因为pg-admin可以使用我的初始密码进行连接就可以了)。

If you're sure your connection string is already well-formed like the one gnerkus described, the last thing you need to check is your password. If it's contain non alphanumeric characters, maybe that's the one who cause the issue. It seems either the Node.js or the way javascript work itself causing this (I'm not really sure since pg-admin can connect using my initial password just fine).

我的密码包含'+''/'(通过创建一个充满乱码的长json,然后将其散列为base64字符串),我肯定会收到与您相同的错误。一旦我摆脱了它(从我的连接字符串并更新了数据库的密码),它就可以正常工作。

My password was contain '+' and '/' (acquired by creating a long json filled with gibberish and then hash it resulting base64 string) and I sure does receiving the same error like yours. Once I get rid of it (from my connection string and updating my database's password), it's working fine.

哦,还有... ' ='被接受。因为似乎问题出在数据库侧的url解码过程。当我发送’+’时,我认为它被’’代替,这将导致密码错误。 ’/’导致网址格式错误,这是我们错误的根本原因(表示未找到)。看看这个例子。

Oh, and ... '=' is accepted though. Because it seems the problem is with url decoding process at the database side. When I sent '+', I think it replaced by ' ' which will cause incorrect password. And the '/' was causing malformed url which is the root cause of our error (which says not found). Take a look at this example.

postgres://username:sdkadady88da8+8ahdajd/ashdi==@localhost/database

我确定您会意识到还有额外的'/'会导致错误的URL分解。因此,协议://用户:pass @ host /数据库更改为协议:// [格式错误的用户:pass @ host] / [格式错误的数据库名称] / [有些乱码] ,因为有多余的'/'

I'm sure you'll realize that there are extra '/' which will cause wrong url break down. So, protocol:// user:pass@host / database changed into protocol:// [malformed user:pass@host] / [malformed database name] / [some gibberish] because of that extra '/'.

如果使用JSF访问它的同事可以编辑其连接字符串,我建议将密码更新为双方都接受的密码。如果不能,那么您需要创建另一个具有相同访问权限但可以从Node.js使用的密码的用户/角色。

If your colleague who access it using JSF can edit their connection string, I suggest to update the password to one which accepted by both. If they can't, then you need to create another user/role with same access right but different password that can be used from Node.js.

编辑:
或者更好,根据讨论在这里,尝试对连接字符串的密码部分进行编码。他们说这有效。因为我已经更改了密码,所以我没有麻烦尝试。由于您仍然遇到此问题,因此在执行上述两个建议之一之前,您可能需要先尝试一下。

Or better yet, according to discussion here, try encode the password part of your connection string. They say it works. I didn't bother to try it since I already change my password. Since you still has this issue, you might want to try it first before doing one of my two suggestions above.

这篇关于NodeJS Postgres错误getaddrinfo ENOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆