Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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.

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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
811 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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

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 '/'.

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.

EDIT: 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...