【问题标题】:PGError: ERROR: current transaction is abortedPGError:错误:当前事务被中止
【发布时间】:2012-09-25 17:07:03
【问题描述】:

使用: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) 

事实

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

问题

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

第二季度。 Rails 3.0.3 和 Postgresql 是否存在任何已知问题?

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

【问题讨论】:

标签: ruby-on-rails postgresql


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    找到并修复它。请注意,这仅意味着您在出现其他错误后继续交易。其他错误是问题所在。

    【讨论】:

    • 我需要运行 rake db:test:prepare 来解决我的问题。我希望这对某人有所帮助。
    • 我知道原因。但是如何通过呢?如何告诉交易停止并退出?我不需要寻找原因。退出它的状态。
    【解决方案3】:

    你能正确执行CalculationType.allCalculationType.first 吗?

    如果您可以访问此模型中的某些数据,那么重新索引您的表可以解决问题,试试这个:

    REINDEX TABLE <table_name>
    

    或在 Rails 控制台中:

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

    前段时间我也遇到过类似的问题,希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 2013-04-12
      • 2011-01-13
      • 2013-08-04
      相关资源
      最近更新 更多