简体   繁体   English

我无法使用 Postgres 连接到 AWS RDS

[英]I cant connect to AWS RDS using Postgres

Ive created an instance/database on aws and when I try to connect to it through my terminal, by running the code below, I get an error.我在 aws 上创建了一个实例/数据库,当我尝试通过终端连接到它时,通过运行下面的代码,出现错误。

The line I run in the terminal is:我在终端运行的线路是:

psql --host=testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=testdb psql --host=testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=testdb

And the error it returns is:它返回的错误是:

psql: error: could not connect to server: could not translate host name "testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com" 
to address: nodename nor servname provided, or not known. 

Ive spent the last 3 days reading the relevant documentation and trying to get this to work but I don't know where im going wrong.我花了最后 3 天阅读相关文档并试图让它工作,但我不知道我哪里出错了。

Also when I run:当我跑步时:

nslookup testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com nslookup testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com

It returns:它返回:

Non-authoritative answer:
*** Can't find testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com: No answer

I come from a statistics background and I've done a fair bit of coding in R and python but Im relatively new to using the terminal etc!我来自统计背景,我在 R 和 python 中进行了相当多的编码,但我对使用终端等相对较新!

Thanks for any guidance or help as this is making me want to punch my laptop.感谢您提供任何指导或帮助,因为这让我想打我的笔记本电脑。

Seems like its a DNS resolution issue.似乎是 DNS 分辨率问题。 I was able to resolve it using DIG .我能够使用DIG解决它。

In the VPC make sure that both of the following options are enabled on the VPC:在 VPC 中,确保在 VPC 上启用以下两个 选项

  • enableDnsHostnames enableDns主机名
  • enableDnsSupport enableDnsSupport

If the RDS instance is not hosted in the VPC but is instead accessed across a VPC peer then DNS resolution might need enabling on the VPC peer如果 RDS 实例未托管在 VPC 中,而是通过 VPC 对等方访问,则可能需要在 VPC 对等方上启用DNS 解析

On running dig command: dig testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com在运行 dig 命令时: dig testdb.c7hgibdbsgjm.eu-west-2.rds.amazonaws.com

It returned a private IP: 172.31.23.42 .它返回了一个私有 IP: 172.31.23.42

It seems you are running RDS instance as private or internal, ie it won't be accessible from the internet.看来您正在以私有或内部方式运行 RDS 实例,即无法从 Internet 访问它。

You need to access it from the VPC itself or need to use a VPN.您需要从 VPC 本身访问它或需要使用 VPN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM