I have a rails application (with puma) and few postgresql databases. As a
DB driver gem Sequel is used. Here is the code for multiple DB connections
when application starting:
require "sequel"
module MyApp
class Databases
class << self
attr_accessor :first_db, :second_db
def start_connections
@first_db = Sequel.connect(ENV.fetch("FIRST_DB_CREDENTIONALS"))
@second_db = Sequel.connect(ENV.fetch("SECOND_DB_CREDENTIONALS"))
end
def disconnect_all
first_db.disconnect
second_db.disconnect
end
end
end
end
MyApp::Databases.start_connections
But, from time to time, some requests (which fetches records from first or
second DB) to application fails with error: "PG::ConnectionBad:
PQconsumeInput() server closed the connection unexpectedly. This probably
means the server terminated abnormally before or while processing the
request: ..."
How to fix this error? Is there a problem with connection timeout settings
or what?
After lookup at documentation, I found this moment
<https://github.com/jeremyevans/sequel/blob/2392145025c60d3c127bc1b921130598409f249c/doc/fork_safety.rdoc#puma->
and
add following code to my puma config:
before_fork do
MyApp::Databases.disconnect_all
end
But problem still persists. Also tried to close connection manually on end
of each request, but the error, mentioned above, raises from time to time.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/d754a747-2bfb-47d4-965d-5fd9db280cd9n%40googlegroups.com.