如何pg_dump RDS Postgres数据库? [英] How to pg_dump an RDS Postgres database?

查看:140
本文介绍了如何pg_dump RDS Postgres数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I connect to my RDS instance using pg_dump?

这是实例的端点:

<long public dns thing>:5432

所以我正在运行以下命令:

So I'm running this command:

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?

这是Amazon的故障排除建议:

This is Amazon's troubleshooting advice:

无法连接到Amazon RDS PostgreSQL数据库实例

Cannot Connect to Amazon RDS PostgreSQL DB Instance

尝试连接到PostgreSQL数据库实例时最常见的问题是分配给该数据库实例的安全组具有错误的访问规则.默认情况下,数据库实例不允许访问.通过安全组授予访问权限.要授予访问权限,您必须创建自己的安全组,并针对您的情况使用特定的入口和出口规则.有关为数据库实例创建安全组的更多信息,请参阅创建安全组.

最常见的错误是无法连接到服务器:连接超时.如果收到此错误,请检查主机名是否是数据库实例端点,以及端口号是否正确.检查分配给数据库实例的安全组是否具有必要的规则,以允许通过本地防火墙进行访问.

是否可以从pg_dump指定我的安全组?如果是这样,我是否必须在ssh'ing时需要一个ssh密钥的方式来获取该本地副本?

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还是执行其他操作?

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?

推荐答案

步骤1:在AWS上创建一个安全组,其中列出了您的计算机IP地址为白色.

Step 1: Create a security group on AWS that has your computer's IP address white listed.

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

Step 2: Add that security group to the database instance you want to connect to.

第3步:运行pg_dump.确保使用-U命令指定您的用户名(感谢@LHWizard).在这种情况下,我的不是"postgres",所以我想通常情况下,您必须查看aws才能找到它.还要确保指定数据库的名称:在某些命令行工具中,有一个-d开关,但是如果您检查pg_dump的用法:

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:

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>

请注意,不必指定端口号-我认为是因为端口5432是Postgres的端口.

Notice that specifying the port number wasn't necessary -- I think because port 5432 is THE port for postgres.

这篇关于如何pg_dump RDS Postgres数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆