ruby-on-rails - Heroku:PG::ConnectionBad:无法连接到服务器:没有这样的文件或目录

标签 ruby-on-rails postgresql heroku

我在我的两个 Heroku 应用程序之间共享 postgres 数据库时遇到了一些问题。

我想让应用程序A的数据库与应用程序B共享,所以我将应用程序A的postgres附加到应用程序B,然后我删除了应用程序B的原始数据库。

但是,尝试从 App B 连接到数据库会导致此消息:

PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我已经尝试重新启动测功机等,但仍然没有成功。有没有人知道如何解决这个问题?

最佳答案

您所要做的就是将 app_a 和 app_b 的 DATABASE_URL 配置变量设置为相同的值。首先,获取您的 app_a 的 DATABASE_URL:

$ heroku config | grep DATABASE_URL  --app app_name_a DATABASE_URL => postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx

然后,将 app_b 的 DATABASE_URL 设置为此值:

$ heroku config:add DATABASE_URL=postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx --app app_name_b
Adding config vars: DATABASE_URL => postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx Restarting app... done, v99. 

就是这样

希望对你有帮助

关于ruby-on-rails - Heroku:PG::ConnectionBad:无法连接到服务器:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35115123/

相关文章:

ruby-on-rails - 在 Posts 模型中保存的用户 ID,如何呈现该用户?

ruby-on-rails - rails 3 : What is the correct Rails way of doing custom types?

sql - 如何在 Go 中将 SQL 数组扫描到 []int64?

django - '可疑操作: Attempted access to "" denied' while loading static files

ruby-on-rails - 自动对焦在 rails 中不起作用

ruby-on-rails - Ruby on Rails 3 教程 : Entering commands in console issue

NHibernate ISessionFactory.OpenSession() 不打开数据库连接

sql - 为什么未使用的 FROM 表会使语句变慢

php - codeigniter 应用程序未在 heroku 上运行

node.js - 当版本与父模块相同时, Node 不会安装子模块依赖项