postgresql - 如何使用 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 实例?
- 我确定我有正确的用户名和密码。
- 我相信楼主是对的。
- 我不确定是否应该包括端口。
- 我不确定我是否应该输入数据库名称,因为在我的数据库的 RDS 管理控制台中的“配置”选项卡下,它说
DB instance ID: my-db-name, Engine version: 13.3, DB name: -
,我不确定这-
是我实际的 postgres 数据库名称还是my-db-name
... .
我用数据库名称尝试了这个,它仍然挂起:
$ psql postgresql://myuser:mypass@myawshost.rds.amazonaws.com:5432/-
- 我编辑了链接在https://console.aws.amazon.com/rds/home选项卡
VPC security groups
部分下的安全组,因此它允许所有传入连接。我还尝试将我的 IP 地址限制为传入连接。Connectivity & security
任何帮助将不胜感激,谢谢。不知道为什么它会挂起来。我已经很好地使用了本地版本的 postgres,但是无法连接到 postgres RDS。
在我刚刚注意到的部分下面Connectivity and Security > Security
它说Public accessibility: No
。我必须启用其他功能吗?还有一个VPC,一个子网组,几个子网,我不太了解,是不是要在那里做点什么?
最后,“状态”Available
以绿灯表示,所以那里的情况似乎很好。
解决方案
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:
Verify that your VPC has an internet gateway attached to it. Make sure that the inbound rules for the security group allow connections.
Open the Amazon RDS console.
Choose Databases from the navigation pane, and then select the DB instance.
Choose Modify.
Under Connectivity, extend the Additional configuration section, and then choose Publicly accessible.
Choose Continue.
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/
推荐阅读
- python - 在numpy数组中集体删除非三行
- python - 向 SQLAlchemy 数据库添加条目会触发`sqlite InterfaceError: Error binding parameter 0 - 可能是不受支持的类型`
- firebird - Firebird 3 迁移后 Firebird 连接字符串不起作用
- swift - 链接 Combine.Publisher 并在完成时调用完成
- excel - 如何用范围替换单个单元格引用
- python - Python:简单的 GET 请求超时
- sql - 过滤同一列中的结果
- reactjs - react-select typescript 问题-通用类型'ValueType'需要2个类型参数.ts(2314)
- c - 即使我尝试在 C 中创建文件也找不到文件时出现分段错误
- c# - JArrary 从键中查找值