How can I connect to my RDS instance using pg_dump?
如何使用pg_dump连接到RDS实例?
This is the instance's endpoint:
这是实例的端点:
<long public dns thing>:5432
So I'm running this command:
我运行这个命令:
pg_dump -h <long public dns thing> -p 5432 -f dump.sql
And getting this:
并获得:
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?
This is Amazon's troubleshooting advice:
以下是Amazon的故障排除建议:
Cannot Connect to Amazon RDS PostgreSQL DB Instance
无法连接到Amazon RDS PostgreSQL DB实例
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.
当尝试连接到PostgreSQL DB实例时,最常见的问题是分配给DB实例的安全组具有不正确的访问规则。默认情况下,DB实例不允许访问;通过安全组授予访问权限。要授予访问权限,您必须创建您自己的安全组,并为您的情况设置特定的入口和出口规则。有关为DB实例创建安全组的更多信息,请参见创建安全组。
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.
最常见的错误是无法连接到服务器:连接超时。如果您收到此错误,请检查主机名是DB实例端点,并且端口号是正确的。检查分配给DB实例的安全组是否具有允许通过本地防火墙进行访问的必要规则。
Is there a way to specify my security group from pg_dump? If so, do I have to get a local copy of that the way that I need an ssh key when ssh'ing?
有办法从pg_dump指定我的安全组吗?如果有,我是否必须获得本地副本,就像我在ssh时需要ssh密钥一样?
Is it a mistake to even try to use pg_dump remotely? Should I be trying to just ssh onto the instance instead, or doing something else entirely?
甚至尝试远程使用pg_dump都是错误的吗?我应该尝试在实例上使用ssh,还是完全做其他事情?
1 个解决方案
#1
41
Step 1: Create a security group on AWS that has your computer's IP address white listed.
步骤1:在AWS上创建一个安全组,其中列出了您的计算机的IP地址。
Step 2: Add that security group to the database instance you want to connect to.
步骤2:将该安全组添加到要连接的数据库实例中。
Step 3: Run pg_dump. Make sure to specify your user name (thanks @LHWizard) with the -U command. In this case mine wasn't 'postgres', so I guess generally you'll have to look in aws to find it. Also make sure to specify your database's name: in some command line tools there's a -d switch for that, but if you check pg_dump's usage:
步骤3:pg_dump运行。确保使用-U命令指定用户名(感谢@LHWizard)。在这种情况下,我的邮箱不是“postgres”,所以我猜你通常得找aws才能找到它。还要确保指定数据库的名称:在一些命令行工具中,有一个-d切换,但是如果检查pg_dump的使用情况:
Usage:
pg_dump [OPTION]... [DBNAME]
you can see that it's a formal argument. So the whole command (in my case) was:
你可以看到这是一个正式的论点。所以整个命令(就我而言)是:
pg_dump -h <public dns> -U <my username> -f dump.sql <name of my database>
Notice that specifying the port number wasn't necessary -- I think because port 5432 is THE port for postgres.
注意,没有必要指定端口号——我认为是因为端口5432是postgres的端口。
#1
41
Step 1: Create a security group on AWS that has your computer's IP address white listed.
步骤1:在AWS上创建一个安全组,其中列出了您的计算机的IP地址。
Step 2: Add that security group to the database instance you want to connect to.
步骤2:将该安全组添加到要连接的数据库实例中。
Step 3: Run pg_dump. Make sure to specify your user name (thanks @LHWizard) with the -U command. In this case mine wasn't 'postgres', so I guess generally you'll have to look in aws to find it. Also make sure to specify your database's name: in some command line tools there's a -d switch for that, but if you check pg_dump's usage:
步骤3:pg_dump运行。确保使用-U命令指定用户名(感谢@LHWizard)。在这种情况下,我的邮箱不是“postgres”,所以我猜你通常得找aws才能找到它。还要确保指定数据库的名称:在一些命令行工具中,有一个-d切换,但是如果检查pg_dump的使用情况:
Usage:
pg_dump [OPTION]... [DBNAME]
you can see that it's a formal argument. So the whole command (in my case) was:
你可以看到这是一个正式的论点。所以整个命令(就我而言)是:
pg_dump -h <public dns> -U <my username> -f dump.sql <name of my database>
Notice that specifying the port number wasn't necessary -- I think because port 5432 is THE port for postgres.
注意,没有必要指定端口号——我认为是因为端口5432是postgres的端口。