postgresql PGError: 错误: 当前事务被中止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12587807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PGError: ERROR: current transaction is aborted
提问by Christoffer
Using: Rails 3.0.3 and Heroku with Postgresql.
使用:Rails 3.0.3 和 Heroku 与 Postgresql。
I have been receiving numerous Exceptions such as this one:
我收到了许多异常,例如:
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'
occuring althroughout my app but always when I perform as in this case
发生在我的应用程序中,但总是在我像这种情况下那样执行时
calculation_type = CalculationType.find(params[:id])
or similar, super simple, database-requests.
或类似的,超级简单的数据库请求。
My list of gems (from when I uploaded it to Heroku):
我的宝石列表(从我上传到 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)
Facts
事实
- The errors are intermittent and I cannot reproduce them.
- It seems to happen at most of the time when search engine bots try to access the page
- 错误是间歇性的,我无法重现它们。
- 当搜索引擎机器人尝试访问该页面时,似乎大部分时间都会发生这种情况
Questions
问题
Q1. I don't even know where to start trouble shooting this (what other parts of my code would you need?). What should be my first steps?
一季度。我什至不知道从哪里开始解决这个问题(你还需要我代码的哪些其他部分?)。我的第一步应该是什么?
Q2. Are there any known problems with Rails 3.0.3 and Postgresql?
Q2。Rails 3.0.3 和 Postgresql 是否存在任何已知问题?
- What else do you need to help me trouble shoot?
- 你还需要什么来帮助我解决问题?
回答by Travis Glover
I just restarted my server. This cancelled the transaction.
我刚刚重新启动了我的服务器。这取消了交易。
回答by Chris Travers
This error is never your real problem. It occurs because you send a statement in a transaction that has already failed because of an upstream error. If you see a lot of these errors you want to go back in your log to find the first error in the stream, and it will be a different error.
这个错误永远不是你真正的问题。发生这种情况是因为您在已因上游错误而失败的事务中发送语句。如果您看到很多这样的错误,您想返回日志以查找流中的第一个错误,这将是一个不同的错误。
Find this, and fix it. Note that this just means you are continuing transactions after other errors. The other errors are where the problems lie.
找到这个并修复它。请注意,这仅意味着您在发生其他错误后继续交易。其他错误是问题所在。
回答by CezarBastos
Can you perform a CalculationType.all
or CalculationType.first
without errors?
你能执行一个CalculationType.all
或CalculationType.first
没有错误吗?
If you can access some data from this model, then reindexing your table could fix the problem, try this:
如果您可以从这个模型访问一些数据,那么重新索引您的表可以解决这个问题,试试这个:
REINDEX TABLE <table_name>
or in rails console:
或在 Rails 控制台中:
ActiveRecord::Base.connection.execute("reindex table <table_name>")
I had a similar problem a while ago, hope it helps.
前段时间我也遇到过类似的问题,希望能帮到你。