簡體   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