首页 > 解决方案 > 如何使用 psql 连接到 RDS Postgres 实例

问题描述

我是 RDS 的新手,大部分情况下只通过 Rails 和/或 Heroku 使用过 postgres,所以对数据库管理没有那么深入。我要做的就是验证我可以连接到我刚刚在 AWS 上创建的 RDS 实例,但它正在挂起,psql在挂起大约 30 秒或几分钟后报告这个我猜:

$ psql postgresql://myuser:mypass@myawshost.rds.amazonaws.com:5432/my-db-name
psql: error: could not connect to server: Operation timed out
  Is the server running on host "myawshost.rds.amazonaws.com" (<the ip address>) and accepting
  TCP/IP connections on port 5432?

如何从 localhost 连接到我的 AWS RDS 实例?

我用数据库名称尝试了这个,它仍然挂起:

$ psql postgresql://myuser:mypass@myawshost.rds.amazonaws.com:5432/-

任何帮助将不胜感激,谢谢。不知道为什么它会挂起来。我已经很好地使用了本地版本的 postgres,但是无法连接到 postgres RDS。

在我刚刚注意到的部分下面Connectivity and Security > Security它说Public accessibility: No。我必须启用其他功能吗?还有一个VPC,一个子网组,几个子网,我不太了解,是不是要在那里做点什么?

最后,“状态”Available以绿灯表示,所以那里的情况似乎很好。

标签: postgresqlamazon-web-servicesamazon-rdspsql

解决方案


I found a useful link in AWS knowledge center, I hope this will help you. Btw if your RDS is deployed in a public subnet, yes you need to enable if you want to access RDS over the internet.

My DB instance is in a public subnet, and I can't connect to it over the internet from my local computer This issue can occur when the Publicly Accessible property of the DB instance is set to No. To check whether a DB instance is publicly accessible, you can use the Amazon RDS Console or the AWS CLI.

To change the Publicly Accessible property of the Amazon RDS instance to Yes:

  1. Verify that your VPC has an internet gateway attached to it. Make sure that the inbound rules for the security group allow connections.

  2. Open the Amazon RDS console.

  3. Choose Databases from the navigation pane, and then select the DB instance.

  4. Choose Modify.

  5. Under Connectivity, extend the Additional configuration section, and then choose Publicly accessible.

  6. Choose Continue.

  7. Choose Modify DB Instance.

Note: You don't need to choose Apply Immediately. For more information about how Apply Immediately can affect downtime, see Using the Apply Immediately parameter.

https://aws.amazon.com/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/


推荐阅读