postgres_fdw 无法连接到 Amazon RDS 上的服务器

postgres_fdw cannot connect to server on Amazon RDS

我在 RDS 中有两个 Postgres 9.3.5 实例,都在一个安全组中,允许来自安全组内的所有入站流量和所有出站流量。我正在尝试设置一个数据库,以便能够通过 postgres_fdw.

从另一个 table 中获取 select

我已经创建了服务器 -

create server master 
foreign data wrapper postgres_fdw 
OPTIONS (dbname 'main', 
         host 'myinstance.xxxxx.amazonaws.com');

以及必要的用户映射和外部 table -

create foreign table condition_fdw (
    cond_id integer,
    cond_name text
) server master options(table_name 'condition', schema_name 'data');

然而,一个简单的select count(*) from condition_fdw给了我

ERROR:  could not connect to server "master"
DETAIL:  could not connect to server: Connection timed out
        Is the server running on host "myinstance.xxxxxx.amazonaws.com" (xx.xx.xx.xx) and accepting
        TCP/IP connections on port 5432?

我可以通过 psql 从 EC2 实例连接到两个数据库。我知道直到最近 RDS 才支持 postgres_fdw,但我 运行 是支持的较新版本。

在创建服务器语句中,我尝试用它解析到的 IP 地址替换 "myinstance.xxxxxx.amazonaws.com",但没有成功。

有什么想法吗?

进一步测试

我在具有相同安全组的 ec2 实例上安装了 postgres,外部 table 到主服务器的行为符合预期。

postgres_fdw 同一 RDS 实例上的数据库之间有效。

这一切让我认为我的 Postgres RDS 实例上来自 postgres_fdw 的传出连接一定有问题。

Amazon 似乎不允许来自 RDS 实例的传出连接,因此在此之前使用 postgres_fdw 跨 RDS 实例进行更改是不可能的。我必须 运行 一个 ec2 实例作为我的 postgres 服务器,以便使用外部 table 到另一台服务器上的数据库。

http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html

我遇到了类似的问题,发现 postgres_fdw 只能在 EU-WEST-1 RDS 区域工作,当主实例和远程实例在同一个可用区并且在 9.3.5 上,如果你越过 AZs 它不会连接。我的安全组只有 5432 TCP 入站和所有出站。

如果你在同一个可用区,没有理由不工作。

要让 postgres_fdw 在 AWS RDS(使用 VPC)中的两个实例之间工作,我必须:

  1. 启用custom_dns_resolutionhttps://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.html#Appendix.PostgreSQL.CommonDBATasks.CustomDNS
  2. 在安全组的入站规则中添加查询数据库的public IP 或添加RDS 实例的内部IP 作为服务器主机。 https://forums.aws.amazon.com/thread.jspa?threadID=235154

第一个记录得很好,但我无法让它工作,直到绊倒了第二个。