How to fix PG::DuplicatePstatement: ERROR?
Asked Answered
O

3

14

I would like to know how to prevent this type of error. So far I tried disabling prepared statements via the database configuration at AWS Opsworks:

Eg:

Database Configuration

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

Error Log

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 `'

Thanks in advance.

Orland answered 1/10, 2014 at 16:49 Comment(0)
O
-1

Solution

Add an initializer with the following code:

# 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
Orland answered 7/10, 2014 at 1:23 Comment(5)
can you add a little description about what this does? Looks to disable prepared statements...Sawhorse
@BlairAnderson - while this answer will solve the problem it provides no insight into what happened and why. The solution here is to simply stop ActiveRecord & Postgres automatically creating prepared statements. Unfortunately it's hard to say precisely what cause the problem. However, there are a number of cases similar to this which are caused by Heroku's Rack-Timeout gem. There is an extended discussion here github.com/rails/rails/pull/17607Congruous
I'm having the same problem and added the initializer. Are you supposed to call it somehow or just add that block of code with your file?Hoofbeat
Although this is a solution, it shouldn't be called a solution without explaining the disadvantages. Prepared statements are very important for speeding up your rails applications. It means that once you do a query, it "compiles" it, and in the next time you execute a similar one, it won't need to compile again. Not sure how much does it cost to disable prepared statements, and this should be more explicit on the answer.Treva
Agree with @GustavoLobo: the consequences of adding this code in a production app are not clearly explained. I think adding it could even worsen your problems if performances is a big deal to you...Blinkers
S
4

Are you using Rack::Timeout? If a timeout exception is raised unexpectedly, the potential exists to lose state. (https://github.com/heroku/rack-timeout/blob/master/doc/risks.md).

The incrementing of the prepared statement number may be caught in a loop, creating the duplicate statement error, and can't be recovered without restarting the process. Suggest implementing https://github.com/ankane/slowpoke to kill/restart the process when a Timeout occurs.

Read more about this issue:

Sublunary answered 16/8, 2018 at 14:13 Comment(0)
C
3

I got the same issue on rails 4.2 fixed it by

For Rails > 4.1

1) Add PG bouncer buildpack of heroku

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

2) Add PGBOUNCER_PREPARED_STATEMENTS to false in heroku environment variable.

there are another solution is

Another option is to use `Thread.handle_interrupt` to prevent exceptions from being raised inside critical sections 
Crossed answered 26/3, 2017 at 7:14 Comment(0)
O
-1

Solution

Add an initializer with the following code:

# 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
Orland answered 7/10, 2014 at 1:23 Comment(5)
can you add a little description about what this does? Looks to disable prepared statements...Sawhorse
@BlairAnderson - while this answer will solve the problem it provides no insight into what happened and why. The solution here is to simply stop ActiveRecord & Postgres automatically creating prepared statements. Unfortunately it's hard to say precisely what cause the problem. However, there are a number of cases similar to this which are caused by Heroku's Rack-Timeout gem. There is an extended discussion here github.com/rails/rails/pull/17607Congruous
I'm having the same problem and added the initializer. Are you supposed to call it somehow or just add that block of code with your file?Hoofbeat
Although this is a solution, it shouldn't be called a solution without explaining the disadvantages. Prepared statements are very important for speeding up your rails applications. It means that once you do a query, it "compiles" it, and in the next time you execute a similar one, it won't need to compile again. Not sure how much does it cost to disable prepared statements, and this should be more explicit on the answer.Treva
Agree with @GustavoLobo: the consequences of adding this code in a production app are not clearly explained. I think adding it could even worsen your problems if performances is a big deal to you...Blinkers

© 2022 - 2024 — McMap. All rights reserved.