如何使用pg_dump连接到我的RDS实例?

这是实例的端点:

<long public dns thing>:5432

所以我运行这个命令:

pg_dump -h <long public dns thing> -p 5432 -f dump.sql

并得到这样的结论:

pg_dump: [archiver (db)] connection to database "brendan" failed:
could not connect to server: Connection refused
Is the server running on host "<long public dns thing>"
(<IP address>) and accepting TCP/IP connections on port 5432?

以下是亚马逊的故障排除建议:

Cannot Connect to Amazon RDS PostgreSQL DB Instance

The most common problem when attempting to connect to a PostgreSQL DB instance is that the security group assigned to the DB instance has incorrect access rules. By default, DB instances do not allow access; access is granted through a security group. To grant access, you must create your own security group with specific ingress and egress rules for your situation. For more information about creating a security group for your DB instance, see Create a Security Group.

The most common error is could not connect to server: Connection timed out. If you receive this error, check that the host name is the DB instance endpoint and that the port number is correct. Check that the security group assigned to the DB instance has the necessary rules to allow access through your local firewall.

有没有办法从pg_dump指定我的安全组?如果是这样,我是否必须像ssh‘ing时需要ssh密钥那样获取该文件的本地副本?

甚至try 远程使用pg_dump都是错误的吗?我应该只try ssh到实例上,还是做一些完全不同的事情呢?

推荐答案

步骤1:在AWS上创建一个将您的计算机的IP地址白列出来的安全组.

步骤2:将安全组添加到要连接数据库实例.

步骤3:运行pg_dump.确保使用-U命令指定您的用户名(感谢@LHWizard).在这种情况下,我的不是‘postgres’,所以我猜通常你必须在AWS中查找才能找到它.还要确保指定数据库的名称:在一些命令行工具中有一个-dswitch ,但是如果您判断pg_dump的用法:

Usage:
  pg_dump [OPTION]... [DBNAME]

你可以看到这是一场正式的争论. 因此,整个命令(在我的例子中)是:

pg_dump -h <public dns> -U <my username> -f dump.sql <name of my database>

请注意,没有必要指定端口号——我认为是因为5432端口是postgres的端口.

Database相关问答推荐

为什么postgres枚举需要4个字节?

postgres 索引扫描的启动成本(postgresql 书的内部 struct )

如何使用用户定义的字符串索引数据框?

即使使用列入白名单的 IP,也无法连接到 Azure SQL 数据库

SQL Server - 使用计数函数与相交

通过删除执行计划中的排序运算符来优化 SQL 查询

matlab 数据文件到 pandas DataFrame

SQLite 中内存数据库的优势

单向和双向关系关系的区别

Joomla 数据库设置

用 Python 永久存储字典的优雅方式?

如何通过 PHP 和 Linux 使用 pdo 连接到 mssql?

SQL Server 自动备份

如何将 DECIMAL 插入 MySQL 数据库

数据库模式与数据库表空间?

将一行连接到另一个表中的多行

Phonegap 离线数据库

MySQL:为什么使用 VARCHAR(20) 而不是 VARCHAR(255)?

带数据库的Electron 应用程序

在 Django 中,如何从数据库中 Select 100 条随机记录?