Problem I have a rails application that starts several hundred sidekiq side processes. They all connect to the PostgreSQL database, which is not entirely happy with providing 250 connections - it can, but if all the side processes accidentally send queries to db, it crashes.
Option 1 I was thinking about adding pgBouncer in front of db, however I can’t use it in transaction mode right now, since I am very dependent on setting search_path
at the beginning of each job processing to determine which "country" (PostgreSQL schema) should work (flat- pearl). In this case, I would have to use session-based pooling mode. However, as far as I know, this will require me to disconnect the connections after each processing of the work, in order to free the connections back to the pool, and this will be a very expensive work, right? Did I miss something?
Option 2 , using an application-level connection pool, is also an option, but I'm not quite sure how I can do this for PostgreSQL with sidekiq?
Option 3 , what I did not think about?
source share