Search code examples
ruby-on-railspostgresqlpgbouncer

PG::UnableToSend: no connection to the server in Rails 5


I have 2 servers(A, B). I am running rails app in A and db in B. In server B, I have pgbouncer and postgresql running.

When I run 200 threads in A, I am getting that issue even though I increased pgbouncer max client connection to 500. And pgbouncer pool_mode is session. Postgresql pool is 100.

I also increased db pool to 500 in server A.

How can I avoid this issue and run 200 threads without any issue?

Later, I've updated code. Dropped pgbouncer and use postgresql directly. Created 2 new threads which do db operation and other threads don't do db operation anymore. And while threads run, I was monitoring active connections. It keeps 3 active. But at the end of threads, I got this issue. I showed connections pool status using ActiveRecord::Base.connection_pool.stat

{:size=>500, :connections=>4, :busy=>3, :dead=>0, :idle=>1, :waiting=>0, :checkout_timeout=>5}
rake aborted!
ActiveRecord::StatementInvalid: PG::UnableToSend: no connection to the server

Is there anyone who can help me with this issue?


Solution

  • I merged db instance and app instance. That works. I am still not sure if it's db version issue or postgresql remote access issue. In my opinion, it's remote access issue.