简体   繁体   中英

Rails PgBouncer client_idle_timeout


my problem is a pgbouncer which is dropping connections. Sysadmin set the client_idle_timeout to 60 seconds. Is there any solve on rails side for this? I mean, is there a possibility (a gem, or settings) to connect and drop connection (reconnection) to database every query we want to send ?

ruby 2.0.0
rails 4.2.3
pg 0.17.1

Im getting following error when connection is longer than x seconds (for example when I open rails console, wait x seconds and then run some ActiveRecord query to db):

ERROR: client_idle_timeout
Contract Load (0.5ms) SELECT "contracts".* FROM "contracts" ORDER BY "contracts"."id" ASC LIMIT 1
PG::ConnectionBad: PQconsumeInput() SSL connection has been closed unexpectedly :
SELECT "contracts".* FROM "contracts" ORDER BY "contracts"."id" ASC LIMIT 1
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() SSL connection has been closed unexpectedly :
SELECT "contracts".* FROM "contracts" ORDER BY "contracts"."id" ASC LIMIT 1

Calling ActiveRecord::Base.clear_active_connections! will return the stale connections back into the thread pool and check out fresh connections so you don't have to restart your console/server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM