繁体   English   中英

PGError:错误:当前事务中止

[英]PGError: ERROR: current transaction is aborted

使用:Rails 3.0.3和Heroku与Postgresql。

我收到了很多这样的例外情况:

A ActiveRecord::StatementInvalid occurred in home#index:

  PGError: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: SELECT "calculation_types".* FROM "calculation_types"
  .bundle/gems/ruby/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'

在我的应用程序中发生,但总是在我执行这种情况时

calculation_type = CalculationType.find(params[:id])

或者类似的,超级简单的数据库请求。

我的宝石列表(从我上传到Heroku时):

   Installing rake (0.9.2.2) 
   Installing abstract (1.0.0) 
   Installing activesupport (3.0.3) 
   Installing builder (2.1.2) 
   Installing i18n (0.6.1) 
   Installing activemodel (3.0.3) 
   Installing erubis (2.6.6) 
   Installing rack (1.2.5) 
   Installing rack-mount (0.6.14) 
   Installing rack-test (0.5.7) 
   Installing tzinfo (0.3.33) 
   Installing actionpack (3.0.3) 
   Installing mime-types (1.19) 
   Installing polyglot (0.3.3) 
   Installing treetop (1.4.10) 
   Installing mail (2.2.19) 
   Installing actionmailer (3.0.3) 
   Installing arel (2.0.10) 
   Installing activerecord (3.0.3) 
   Installing activeresource (3.0.3) 
   Installing acts_as_tree_rails3 (0.1.0) 
   Installing breadcrumbs_on_rails (2.2.0) 
   Installing yamler (0.1.0) 
   Installing configatron (2.9.1) 
   Installing daemons (1.1.9) 
   Installing eventmachine (1.0.0) with native extensions 
   Installing exception_notification (2.4.1) 
   Installing friendly_id (4.0.0.beta12) 
   Installing i18n_routing (0.6.1) 
   Installing thor (0.14.6) 
   Installing railties (3.0.3) 
   Installing jquery-rails (1.0.19) 
   Installing pg (0.14.1) with native extensions 
   Installing postgres-pr (0.6.3) 
   Installing rack-rewrite (1.0.2) 
   Installing rack-timeout (0.0.3) 
   Using bundler (1.0.7) 
   Installing rails (3.0.3) 
   Installing thin (1.5.0) with native extensions 
   Installing time_diff (0.2.2) 

事实

  • 错误是间歇性的,我无法重现它们。
  • 大多数情况下,搜索引擎机器人试图访问该页面时似乎会发生这种情况

问题

Q1。 我甚至不知道从哪里开始解决问题(你需要我的代码的其他部分?)。 我的第一步应该是什么?

Q2。 Rails 3.0.3和Postgresql有任何已知问题吗?

  • 你需要什么来帮助我解决问题?

我刚刚重启了我的服务器。 这取消了交易。

这个错误永远不是你真正的问题。 发生这种情况是因为您在由于上游错误而已经失败的事务中发送语句。 如果您看到很多这些错误,您想要返回到日志中以查找流中的第一个错误,这将是一个不同的错误。

找到这个并修复它。 请注意,这只是意味着您在其他错误之后继续进行交易。 其他错误是问题所在。

您可以无错误地执行CalculationType.allCalculationType.first吗?

如果您可以从此模型访问某些数据,那么重新索引表可以解决问题,请尝试以下方法:

REINDEX TABLE <table_name>

或者在rails控制台中:

ActiveRecord::Base.connection.execute("reindex table <table_name>")

我不久前有类似的问题,希望它有所帮助。

暂无
暂无

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

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