Heroku ActiveRecord::StatementInvalid: PGError: ERROR: 上的 Sinatra 应用程序
场景:
我目前在 Heroku 上有一个应用程序,即 Sinatra Application + ActiveRecord。目前有效的方法:
• 我能够查看我网站的静态页面
• 我能够运行迁移
• 我能够将本地开发数据库推送到 Heroku 数据库 (heroku db:push postgres://localhost/dev)
• 我能够从 Heroku DB 拉取到本地主机数据库 (heroku db:pull postgres://localhost/dev)
错误:
当我导航到一个进行简单查询的页面时,例如:
@pics = Picture.find(:all)
我在日志文件中收到此错误
DEBUG -- : NoMethodError: undefined method `values' for #<PGresult:0x00000002844098>: SHOW client_min_messages
DEBUG -- : PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
ActiveRecord::StatementInvalid - PGError: ERROR: invalid value for parameter "client_min_messages": ""
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
此时我不确定出了什么问题,所以我决定登录 < code>heroku console 并运行此命令来查看我的表是否在数据库中
> heroku console
> ActiveRecord::Base.connection.tables
,并且我收到类似的错误
ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in execute'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
然后我决定在控制台中尝试此操作...
> ActiveRecord::Base.assessment_connection
> ActiveRecord::AdapterNotSpecified: ActiveRecord::AdapterNotSpecified
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:54:in `establish_connection'
/home/heroku_rack/lib/console.rb:158:in `block (2 levels) in <top (required)>'
/home/heroku_rack/lib/console.rb:148:in `eval'
/home/heroku_rack/lib/console.rb:148:in `_eval'
此时,我似乎没有表和适配器连接,但是当我能够运行迁移并从 Heroku DB 进行推送和拉取时,怎么会出现这种情况呢?
更新 1 - 没有更进一步,但有更多的洞察力
所以我决定从头开始,再做一次。我似乎取得了一些进展,但我陷入了困境。重新运行我上面提到的场景并成功。所以我的数据库、迁移和数据都在DB中。但我的应用程序仍然无法连接到数据库。但奇怪的是我的控制台交互。
> heroku console
> ActiveRecord::Base.connection_config
> {:adapter=>"postgresql", :database=>"1e2e12e21e", :username=>"1e2e12e21e", :password=>"i2j3i23joo12", :host=>"1e2-12e-2e1212-e2e2e1.compute-1.amazonaws.com", :port=>5432, :encoding=>"unicode"}
注意:我用这些假的东西替换了真实的细节只是为了说明
> ActiveRecord::Base.connection_handler
> #<ActiveRecord::ConnectionAdapters::ConnectionHandler:0x00000002f8a578 @connection_pools={"….
注意:这是一个非常长的字符串,但它有内容
> ActiveRecord::Base.connected?
> false
此时我真的不明白吗?我不明白如何继续运行数据库迁移,保持推送和拉取数据,登录 Heroku 控制台查看我的 connection_config
详细信息,但是当我运行应用程序时出现内部服务器错误。当我在 heroku console
中运行 ActiveRecord::Base.connection.tables
时,我得到 ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages" :“”
对我可能做错了什么有什么想法吗?
最终更新
这是问题所在: Heroku 支持人员善意地向我指出了 activerecord 3.1.3 的一个已知问题。这是一个应该在未来的更新中修复的错误: https://github.com/rails/rails/commit/92a3c487bb0d125c437e53a7f45c31fcca97f2d9
问题解决方法: 我决定在我的 gemfile gem "activerecord", "~> 3.0.9
中使用低得多版本的 activerecord,并且我的网站到目前为止已启动并运行,没有任何问题。
为什么我从未尝试过这个在我不知道之前,我希望这篇文章能被其他人看到。
SCENARIO:
I currently have anapplication on Heroku that is Sinatra Application + ActiveRecord. What currently works:
• I am able to view static pages of my site
• I am able to run migrations
• I am able to push my local development db to my Heroku DB (heroku db:push postgres://localhost/dev)
• I am able to pull from the Heroku DB down to my localhost DB (heroku db:pull postgres://localhost/dev)
THE ERROR:
When I navigate to a page that makes a simple query like:
@pics = Picture.find(:all)
I get this error in my log file
DEBUG -- : NoMethodError: undefined method `values' for #<PGresult:0x00000002844098>: SHOW client_min_messages
DEBUG -- : PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
ActiveRecord::StatementInvalid - PGError: ERROR: invalid value for parameter "client_min_messages": ""
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
At this point I'm not sure what is wrong so I decided to log onto the heroku console
and run this command to see if my tables are in the DB
> heroku console
> ActiveRecord::Base.connection.tables
AND I get a similar errors
ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in execute'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
Then I decided to try this in the console...
> ActiveRecord::Base.establish_connection
> ActiveRecord::AdapterNotSpecified: ActiveRecord::AdapterNotSpecified
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:54:in `establish_connection'
/home/heroku_rack/lib/console.rb:158:in `block (2 levels) in <top (required)>'
/home/heroku_rack/lib/console.rb:148:in `eval'
/home/heroku_rack/lib/console.rb:148:in `_eval'
At this point it would seem that I have no tables and adapter connection but how can that be when I'm able to run migrations and push and pull from the Heroku DB?
UPDATE 1 - NOT MUCH FURTHER ALONG BUT MORE INSIGHT
So I decided to start from scratch and do this over again. I seem to have made some progress but I'm stuck. At re-ran my scenario I mentioned above and succeed. So my database, migration and data are all in the DB. But my app still cannot connect to the DB. BUT what's weird is my console interaction.
> heroku console
> ActiveRecord::Base.connection_config
> {:adapter=>"postgresql", :database=>"1e2e12e21e", :username=>"1e2e12e21e", :password=>"i2j3i23joo12", :host=>"1e2-12e-2e1212-e2e2e1.compute-1.amazonaws.com", :port=>5432, :encoding=>"unicode"}
NOTE: I replaced the real details with this fake stuff just to illustrate
> ActiveRecord::Base.connection_handler
> #<ActiveRecord::ConnectionAdapters::ConnectionHandler:0x00000002f8a578 @connection_pools={"….
NOTE: This a really long string but it has content
> ActiveRecord::Base.connected?
> false
At this point I really don't get it? I don't get how I can keep running db migrations, keeping push and pulling data, log into Heroku Console see my connection_config
details, BUT when I run my app internal server error. AND when I run ActiveRecord::Base.connection.tables
in heroku console
I get ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""
Any thoughts on what I could be doing wrong?
FINAL UPDATE
Here is what the problem is:
Heroku support kindly pointed to me to a known issue with activerecord 3.1.3. It's a bug that should be fixed in future updates: https://github.com/rails/rails/commit/92a3c487bb0d125c437e53a7f45c31fcca97f2d9
How to solve the problem:
I decided to use a much lower version of activerecord in my gemfile gem "activerecord", "~> 3.0.9
and my site is up and running with no problems so far.
Why I never tried this out before I don't know. I hope this post anyone else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个问题困扰了我很长时间,让我抓狂。我在任何地方都找不到解决方案(并且许多 Rails 更新都没有解决“问题”),所以我决定自己解决这个问题。事实证明这是一个简单的修复。只需添加一个额外的键值对:
:min_messages => “警告”
(或任何您想要的消息级别)到配置块中的 ActiveRecord 设置。这是我现在在 Sinatra 应用程序中使用的内容,使用 Sinatra 1.3.2 和 ActiveRecord 3.2.2:希望这可以帮助您和任何其他遇到这些问题的人!
I had this problem for a long time and it was driving me nuts. I couldn't find a solution anywhere (and many rails updates passed by not solving the "problem"), so i decided to just hunt down the issue myself. It turned out to be an easy fix. Just add an additional key, value pair:
:min_messages => "warn"
(or whatever message level you want) to the ActiveRecord setup in your configure block. here's what I'm using in my Sinatra app's right now, using Sinatra 1.3.2 and ActiveRecord 3.2.2:hope this helps you and any other people having these issues!
其他建议都不适合我。我最终通过切换到 Heroku cedar 堆栈解决了这个问题:
heroku create your app --stack cedar
None of the other suggestions worked for me. I ultimately fixed this by switching to the Heroku cedar stack:
heroku create your app --stack cedar
我在bamboo-ree-1.8.7 和bamboo-mri-1.9.2 堆栈上都遇到了这个问题。该应用程序在 localhost 上运行良好,并在 heroku 上迁移正常,但读取 heroku Web 堆栈内的数据库失败,并出现 client_min_messages 投诉。
将 :min_messages (如另一个答案中所建议的)设置为“警告”或“警告”会产生不同的错误。
强制我的 ActiveRecord 降到 3.0.11(从 3.2.3)解决了这个问题。 (并不是说我在 AR 中看到任何内容来解释这一点。我推测这与不同的 postgres 版本有关......我使用的是 9.0.3,怀疑共享的 heroku bare 是 8.4)
I had this problem on both bamboo-ree-1.8.7 and bamboo-mri-1.9.2 stacks. The application worked fine on localhost, and migrated OK on heroku, but reading the database inside the heroku web stack failed with a client_min_messages complaint.
Setting the :min_messages (as suggested in another answer) to either "warn" or "warning" produced different errors.
Forcing my ActiveRecord down to 3.0.11 (from 3.2.3) resolved the issue. (Not that I see anything in AR to explain this. I speculate it's related to differing postgres versions ... I'm using 9.0.3, suspect the heroku bamboo shared is 8.4)
将其推入我的 gem 文件对我有用。
Pushing this up in my gem file worked for me.