如何解决PG :: DuplicatePstatement:ERROR?

14

我想知道如何防止这种类型的错误。到目前为止,我尝试通过在AWS Opsworks上的数据库配置中禁用预处理语句:

例如:

数据库配置

},
"deploy": {
    "app_name": {
        "database": {
            "adapter": "postgresql",
            "prepared_statements": false,
            "username": "username",
            "database": "db_name_production",
            "host": "cool_host.com",
            "password": "easy"
        },

错误日志

PG::DuplicatePstatement: ERROR: prepared statement "a6" already exists : INSERT INTO "polls" ("answer_type", "auto_enable", "can_have_correct_answer", "created_at", "de", "en", "es", "event_id", "game_card_length", "game_card_start", "id_language_code", "is_custom_question", "ja", "language_id", "points_award", "poll_upload_id", "pop_up_length", "pop_up_start", "pop_up_trigger_type", "pt", "question", "question_identifier", "question_tag", "question_translation", "question_type", "scorecard_presentation", "show_at_minute", "show_n_seconds", "template_type", "th", "trigger_restriction", "updated_at", "vi", "vizrt_show_name", "vizrt_template_name", "vote_options", "vote_options_translation") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37) RETURNING "id"

URL: http://app.domain.com/admin/polls

BACKTRACE:
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `prepare'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `prepare_statement'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1168:in `exec_cache'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `block in exec_query'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/instrumentation/active_record.rb:46:in `block in log_with_newrelic_instrumentation'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/method_tracer.rb:235:in `trace_execution_scoped'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/instrumentation/active_record.rb:43:in `log_with_newrelic_instrumentation'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:659:in `exec_query'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/relation.rb:66:in `insert'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/persistence.rb:367:in `create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/timestamp.rb:58:in `create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/callbacks.rb:268:in `block in create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:403:in `_run__355353764622945659__create__4467585814663071278__callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/callbacks.rb:268:in `create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/persistence.rb:348:in `create_or_update'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/callbacks.rb:264:in `block in create_or_update'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:447:in `_run__355353764622945659__save__4467585814663071278__callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/callbacks.rb:264:in `create_or_update'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/persistence.rb:84:in `save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/validations.rb:50:in `save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:259:in `block (2 levels) in save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:208:in `transaction'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/method_tracer.rb:497:in `block in transaction_with_trace_ActiveRecord_self_name_transaction'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/method_tracer.rb:235:in `trace_execution_scoped'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/method_tracer.rb:493:in `transaction_with_trace_ActiveRecord_self_name_transaction'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:259:in `block in save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/transactions.rb:258:in `save'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/resource_controller/data_access.rb:163:in `block in save_resource'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/callbacks.rb:78:in `run_save_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/resource_controller/data_access.rb:162:in `save_resource'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/resource_controller/data_access.rb:152:in `block in create_resource'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/callbacks.rb:78:in `run_create_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/resource_controller/data_access.rb:151:in `create_resource'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/inherited_resources-1.4.1/lib/inherited_resources/actions.rb:33:in `create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/lib/active_admin/resource_controller/actions.rb:48:in `create'
/srv/www/app_pro/releases/20140930174854/app/admin/polls.rb:13:in `create'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/abstract_controller/base.rb:167:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:480:in `_run__674118340747155841__process_action__4403365755486731848__callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/notifications.rb:123:in `block in instrument'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/notifications.rb:123:in `instrument'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38:in `block in process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:357:in `perform_action_with_newrelic_trace'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37:in `process_action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/abstract_controller/base.rb:121:in `process'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/abstract_controller/rendering.rb:45:in `process'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal.rb:203:in `dispatch'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_controller/metal.rb:246:in `block in action'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:73:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:36:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/routing/route_set.rb:608:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/builder.rb:59:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/rack/error_collector.rb:55:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/rack/agent_hooks.rb:32:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/newrelic_rpm-3.8.1.221/lib/new_relic/rack/browser_monitoring.rb:27:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/deflater.rb:13:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb:35:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/flash.rb:242:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/cookies.rb:341:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/query_cache.rb:64:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `_run__1037584046338014875__call__4467585814663071278__callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/rack/logger.rb:32:in `call_app'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/rack/logger.rb:16:in `block in call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/tagged_logging.rb:22:in `tagged'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/rack/logger.rb:16:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/actionpack-3.2.19/lib/action_dispatch/middleware/static.rb:63:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:155:in `invalidate'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-timeout-0.0.4/lib/rack/timeout.rb:16:in `block in call'
/usr/local/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/rack-timeout-0.0.4/lib/rack/timeout.rb:16:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/engine.rb:484:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/application.rb:231:in `call'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/railties-3.2.19/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:576:in `process_client'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670:in `worker_loop'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start'
/home/deploy/.bundler/app_pro/ruby/1.9.1/gems/unicorn-4.8.3/bin/unicorn_rails:209:in `'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bin/unicorn_rails:23:in `load'
/home/deploy/.bundler/app_pro/ruby/1.9.1/bin/unicorn_rails:23:in `'

提前感谢。

3个回答

4

您是否使用 Rack::Timeout?如果出现意外超时异常,可能会丢失状态 (https://github.com/heroku/rack-timeout/blob/master/doc/risks.md)。

准备语句编号的增加可能会在循环中被捕获,从而导致重复语句错误,并且无法在不重新启动进程的情况下恢复。建议实现https://github.com/ankane/slowpoke以在超时发生时杀死/重启进程。

了解更多信息,请访问以下链接:


3

我在Rails 4.2上遇到了同样的问题,解决方法如下:

适用于Rails > 4.1

1)在heroku上添加PG bouncer buildpack

heroku buildpacks:add https://github.com/heroku/heroku-buildpack-pgbouncer

2) 在Heroku环境变量中将PGBOUNCER_PREPARED_STATEMENTS设置为false

还有另一种解决方案是

Another option is to use `Thread.handle_interrupt` to prevent exceptions from being raised inside critical sections 

-1

解决方案

添加一个初始化器,包含以下代码:

# gist: https://gist.github.com/catsby/0b676949b6cd414357df
# source https://github.com/gregburek/heroku-buildpack-pgbouncer#disable-prepared-statements

require "active_record/connection_adapters/postgresql_adapter"

class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  alias initialize_without_config_boolean_coercion initialize
  def initialize(connection, logger, connection_parameters, config)        
    config = config.merge(prepared_statements: false)        
    initialize_without_config_boolean_coercion(connection, logger, connection_parameters, config)
  end
end

1
你能否添加一点关于这个功能的描述?看起来是禁用预处理语句... - Blair Anderson
7
@BlairAnderson - 这个回答虽然解决了问题,但没有提供出现问题的原因和原因分析。解决方法是停止ActiveRecord和Postgres自动创建预处理语句。不幸的是,很难确定造成问题的确切原因。然而,有许多类似情况是由于Heroku的Rack-Timeout宝石引起的。这里有一个扩展讨论 https://github.com/rails/rails/pull/17607 - ocodo
我遇到了同样的问题并添加了初始化器。你需要以某种方式调用它还是只需将该代码块添加到文件中? - user2974739
1
虽然这是一种解决方案,但如果不说明缺点,则不应称其为解决方案。预处理语句对于加速Rails应用程序非常重要。这意味着一旦您执行一个查询,它就会“编译”它,下次执行类似的查询时,它就不再需要重新编译。我不确定禁用预处理语句的成本有多少,这应该在答案中更明确地说明。 - Gustavo Semião-Lobo
同意@GustavoLobo的说法:在生产应用程序中添加此代码的后果并没有得到明确的解释。如果性能对您很重要,我认为添加它甚至可能会加剧您的问题... - Mathiou

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接