heroku pg:psql无法正常工作

时间:2013-01-22 18:44:06

标签: heroku

我尝试通过运行命令“heroku pg:psql”连接到我的应用程序的Postgres数据库,并收到以下错误消息:

psql: could not connect to server: Connection timed out (0x0000274C/10060)
    Is the server running on host "URL.com"(IP address)  and accepting
    TCP/IP connections on port 5432?

我还尝试使用Pgadmin进行连接并收到错误:

Server doesn't listen. Is the server running on host "URL.com" (IP address) and accepting
    TCP/IP connections on port 5432?

任何人都可以告诉我如何修复这些错误并正确连接到我的数据库。 提前谢谢!

3 个答案:

答案 0 :(得分:2)

试试这个:

heroku pg:psql DATABASE_URL

答案 1 :(得分:0)

由于已经开始使用DATABASE_URL进行提示,因此还需要考虑更多的事情。

如果您在Heroku中有多个应用程序,那么最好指定要连接到哪个应用程序添加数据库的位置。如果您有多个数据库来指定数据库名称(如果它不是默认的DATABASE_URL),则同样适用。

如何连接的一些示例:

-- Defining to what DB and app you want to connect to:
heroku pg:psql [lower case generated name] -a myapp
heroku pg:psql [lower case generated name] --app myapp
heroku pg:psql HEROKU_POSTGRESQL_[upper case generated name]_URL -a myapp

-- This will fall back to default DATABASE_URL part of your app:
heroku pg:psql -a myapp

另请注意这里所说的https://devcenter.heroku.com/articles/heroku-local#copy-heroku-config-vars-to-your-local-env-file

  

请注意,您部署的生产应用可能正在连接到   与本地开发应用程序不同的服务。例如,你的   部署的生产应用程序可能具有DATABASE_URL配置var   引用了Heroku Postgres数据库,但您的本地应用程序可能有一个   .env文件中引用本地的DATABASE_URL变量   安装Postgres。

Heroku指南 - https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql(但它对多数据库和多应用案例的解释不多)。

外部连接的Heroku指南 - https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku

答案 2 :(得分:0)

这个答案可能很愚蠢,但它以前发生在我身上。我所在的互联网连接阻止了该端口的连接。

相关问题