简体   繁体   English

Ruby应用程序不再能够访问远程Heroku Postgres-在本地安装Postgres.app之后

[英]Ruby app no longer able to access remote Heroku Postgres - AFTER installing Postgres.app locally

For months now, a ruby (sinatra) app "foo.rb" on my dev't Mac has been using a remote Heroku-hosted Postgres database. 几个月以来,我的开发人员Mac上的ruby(sinatra)应用程序“ foo.rb”一直在使用远程Heroku托管的Postgres数据库。

The app does not use ANY local database, neither in development nor production. 该应用程序在开发或生产中均不使用任何本地数据库。

For another project, I installed Postgress.app from Heroku, first removing a very OLD version as recommended, using brew remove postgresql 对于另一个项目,我从Heroku安装了Postgress.app,首先按照建议使用brew remove postgresql删除了一个非常旧的版本。

The next time I ran foo.rb, and tried at access the (remote) database with SomeModel.count, I get the error: 下次我运行foo.rb并尝试使用SomeModel.count访问(远程)数据库时,出现错误:

PG::ConnectionBad: FATAL: no pg_hba.conf entry for host , user , database , SSL off PG :: ConnectionBad:严重:主机,用户,数据库和SSL均未提供pg_hba.conf条目

I'm confused why the error shows my devt machine address when the database connection config points to a remote postgres url, and why it says SSL off. 我很困惑为什么当数据库连接配置指向远程postgres url时错误显示我的devt机器地址,以及为什么说SSL关闭。

Any thoughts how to get rid of the error? 有什么想法如何摆脱错误? Is there any way to see the PATH to the pg_hba.conf it is complaining about, so I can verify it contains the correct host entries? 有什么办法可以查看它抱怨的pg_hba.conf的路径,因此我可以验证它是否包含正确的主机条目?

(I wonder if the pg gem has its own copy squirreled away somewhere.) (我想知道pg宝石是否有自己的副本被藏在某个地方。)

The copies of pg_hba.conf that I can find (in /Library/Application Support/XXXX for both the old and new Postgress.app versions) have the correct (and unchanged) host entries. 我可以找到的pg_hba.conf副本(在旧的和新的Postgress.app版本的/ Library / Application Support / XXXX中)都具有正确的(且未更改)主机条目。

It looks like your script is trying to connect somewhere that is not properly configured 看来您的脚本正在尝试连接未正确配置的地方

Things to check in that case: 在这种情况下要检查的事情:

  1. your database.yml or connection string, DATABASE_URL matches your localhost from postgres.app 您的database.yml或连接字符串,DATABASE_URL匹配postgres.app中的本地主机

  2. is your postgres.app is running and have a db server running (check the elephant icon on the top bar of your osx) 是您的postgres.app正在运行并且正在运行db服务器(请检查osx顶部栏中的大象图标)

  3. You installed and configured properly the postgres app you need to set the path, you can check by typing psql in a new terminal window, if it runs is ok to go. 您已正确安装和配置了设置路径所需的postgres应用程序,可以在新的终端窗口中键入psql进行检查(如果可以运行)。

Configure your $PATH to use the included command line tools (optional): 配置$ PATH以使用随附的命令行工具(可选):

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
  1. post your file or part of it in the question, it helps a lot to debug :) 在问题中发布您的文件或文件的一部分,它对调试很有帮助:)

The answer turned out to be: 答案是:

  1. comment out pg in Gemfile 在Gemfile中注释掉pg
  2. bundle install
  3. replace pg 替换pg
  4. bundle install

I suspect when the gem pg is installed, it dynamically establishes some link to postgresql, so if you move postgresql (as I did when I installed Postgres.app) you need to remove the pg gem then re-add it. 我怀疑在安装gem pg时,它会动态建立到postgresql的链接,因此,如果您移动 postgresql(就像我在安装Postgres.app时所做的那样),则需要删除pg gem,然后重新添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM