2014-11-21 85 views
0

如何从另一个运行在不同云服务上的web应用程序连接到heroku postgres。来自另一个ec2实例的Heroku Postgres连接

我有一个heroku postgres。我有另一个在EC2上运行的web应用程序。当我在ec2上的webapp尝试连接到heroku应用程序时,它失败。

我尝试telnet从ec2实例到端口5432上的heroku postgres,它失败。

任何人都可以提供一个指针吗?

回答

0

您可以使用heroku pg:credentials命令获取数据库的凭据。例如:

$ heroku pg:credentials DATABASE_URL 
Connection info string: 
    "dbname=abcdefghijklmn host=ec2-1-2-3-4.compute-1.amazonaws.com port=5432 user=abcdefghijklmn password=abcdefghijklmnopqrstuvwxyz sslmode=require" 
Connection URL: 
    postgres://abcdefghijklmn:[email protected]:5432/abcdefghijklmn 

然后,您可以使用连接URL或分解凭据在你的其他应用程序。请注意0​​。连接到Heroku Postgres需要使用SSL,这是一些PostgreSQL客户端(例如Navicat)中的“高级”选项。例如:

$ psql postgres://abcdefghijklmn:[email protected]:5432/abcdefghijklmn 

点击此处了解详情:https://devcenter.heroku.com/articles/heroku-postgresql#external-connections-ingress