heroku pg:psql不能正常工作 [英] heroku pg:psql not working

查看:155
本文介绍了heroku pg:psql不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  psql:无法连接到服务器:连接超时(0x0000274C / 10060)
服务器运行在主机URL.com(IP地址)并且接受
TCP /端口5432上的IP连接?

我也尝试使用 Pgadmin 并得到错误:

 服务器不听。服务器是否在主机URL.com(IP地址)上运行,并在端口5432上接受
TCP / IP连接?

任何人都可以告诉我如何解决这些错误并正确连接到我的数据库。
在此先感谢!

解决方案

当开始暗示已经使用DATABASE_URL时, p>

如果您在Heroku中有多个应用程序,则指定要连接到哪个应用程序的数据库总是很好的选择。如果您有多个数据库来指定数据库名称(如果它不是默认的DATABASE_URL),则同样适用。



一些示例如何连接:

   - 定义您要连接的数据库和应用程序:
heroku pg:psql [小写生成名称] -a myapp
heroku pg:psql [小写生成名称] --app myapp
heroku pg:psql HEROKU_POSTGRESQL_ [大写生成名称] _URL -a myapp

- 这将回退到默认DATABASE_URL部分应用:
heroku pg:psql -a myapp

还要保留在这里说 https://devcenter.heroku.com/articles/heroku-local#copy-heroku-config-vars-to-your-local-env-file


请记住,您部署的生产应用程序可能连接到
不同于本地开发的服务应用程序。例如,您的
部署的生产应用程序可能有一个DATABASE_URL config 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


I tried to connect to the Postgres database for my app on heroku by running the command "heroku pg:psql" and got the following error message:

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?

I also tried to connect using Pgadmin and get the error:

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

Can anyone tell me how to fix these errors and correctly connect to my database. Thanks in advance!

解决方案

As started to hint already using DATABASE_URL there are few more things to consider.

If you have multiple apps in Heroku it is always good to specify to what app you want to connect to where DB is added. Same applies if you have multiple databases to specify DB name (if it is something else than default DATABASE_URL).

Some examples how to connect:

-- 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

Also to keep in mind as said here https://devcenter.heroku.com/articles/heroku-local#copy-heroku-config-vars-to-your-local-env-file:

Keep in mind that your deployed production app may be connecting to different services than your local development app. For example, your deployed production app might have a DATABASE_URL config var that references a Heroku Postgres database, but your local app might have a DATABASE_URL variable in the .env file that references your local installation of Postgres.

Heroku guideline – https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql (but it explains little about multi-database and multi-apps cases).

Heroku guideline for connecting externally - https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku

这篇关于heroku pg:psql不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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