Heroku pg:psql无法使用

7
我尝试通过运行命令“heroku pg:psql”连接我的应用在Heroku上的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?

有人能告诉我如何修复这些错误并正确连接到我的数据库吗?谢谢!


你解决了吗? - Mote Zart
3个回答

2

试试这个:

heroku pg:psql DATABASE_URL

1

这个答案可能有点傻,但我之前遇到过这种情况。我所在的互联网连接封锁了那个端口的连接。


0

如已经开始使用 DATABASE_URL,那么还有一些需要考虑的事情。

如果您在 Heroku 上有多个应用程序,最好指定要连接到哪个应用程序,以及添加了 DB 的位置。如果您有多个数据库,则同样适用于指定数据库名称(如果它不是默认的 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配置变量,该变量引用Heroku Postgres数据库,但是您的本地应用程序可能具有.env文件中引用您本地安装的Postgres的DATABASE_URL变量。

Heroku指南 - https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql(但它很少解释多数据库和多应用程序情况)。

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


对于已经安装并正确设置了PATH变量的任何人,请确保重新打开您的cmd或PowerShell。在您这样做之前,更新后的变量将不会生效。 - ophilbinbriscoe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接