ruby on rails - PG::TRDeadlockDetected: ERROR: deadlock detected -



ruby on rails - PG::TRDeadlockDetected: ERROR: deadlock detected -

i restarting 8 puma workers via bundle exec pumactl -f config/puma.rb phased-restart works fine. getting more , more postgres errors:

pg::trdeadlockdetected: error: deadlock detected

i found 50 of idle postgres processes running:

postgres: myapp myapp_production 127.0.0.1(59950) idle postgres: myapp myapp_production 127.0.0.1(60141) idle ...

they disappear when running bundle exec pumactl -f config/puma.rb stop. after starting app bundle exec pumactl -f config/puma.rb start, 16 idle processes. (eight many in opinion.)

how can manage these processes better? help!

update

my puma.rb:

environment 'production' daemonize true pidfile 'tmp/pids/puma.pid' state_path 'tmp/pids/puma.state' threads 0, 1 bind 'tcp://0.0.0.0:3010' workers 8 quiet

i might have found solution question: had queries outside of controllers (custom middleware), seem have caused problem.

if have queries outside of controllers (activemailer cause problem), set code in activerecord::base.connection_pool.with_connection block:

activerecord::base.connection_pool.with_connection # code end

activerecord’s with_connection method yields database connection pool block. when block finishes, connection automatically checked pool, avoiding connection leaks.

i hope helps of you!

ruby-on-rails ruby postgresql puma idle-processing

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -