Heroku上的Postgres错误与Resque
我不太了解Postgres了解这条消息。
PG::Error: SSL error: decryption failed or bad record mac : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"users"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
这是来自resque后端的callstack
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `async_exec' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `exec_no_cache' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `block in exec_query' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:662:in `exec_query' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1264:in `column_definitions' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:858:in `columns' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:237:in `columns_hash' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/delegation.rb:7:in `columns_hash' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:330:in `find_one' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:107:in `find' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/querying.rb:5:in `find' /app/app/workers/compute_worker.rb:5:in `perform'
说明:我的worker只对数据库进行一些写操作。 没什么复杂的。 当我第一次执行worker的任务时,它会工作,第二次它会因上面的消息而失败。 如果我重新启动工作程序,它将仅在第一次工作。 我已经跑了
heroku pg:restart heroku db:restart heroku db:migrate
… 没有成功。
在我的本地计算机上(使用mysql)它完美地运行。 任何的想法 ?
感谢“Rails初学者”和“mu太短”的评论,我找到了解决方案。
我已将此添加到初始化程序中,它就可以了!
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
我有同样的问题,但要解决它我的应用程序实际上需要一个before_fork而不是after_fork。 希望这有助于某人。
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
heroku的这篇文章解释了如何正确连接和断开resque的连接:
Resque.before_fork do defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end Resque.after_fork do defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
Resque.before_fork = Proc.new { ActiveRecord::ActiveRecord::Base.verify_active_connections! }
会更好
- 本地postrges工作,但似乎无法推动到RAILS_ENV =生产heroku
- 使用Postgres hstore的竞争条件
- 我可以在Ruby on Rails上编写PostgreSQL函数吗?
- 配置与Heroku PostgreSQL的RubyMine远程连接
- bundle exec rake assets:precompile – 数据库配置没有指定适配器
- 如何使用ActiveRecord访问Postgres列的默认值?
- 准备好的陈述已经存在
- Ruby On Rails – Geocoder – 接近条件
- 无法使用gem“pg”从我的Ruby脚本连接到Postgres(pg)数据库(这不是rails,只是纯粹的ruby)