I have a quite large PostgreSQL database with up to 300 connected clients from a web application and some background processing.
I'm considering adding PGbouncer as it is my understanding, that postgresql will not continue to scale well with this many connections due to connection overhead.
Background
My web application is a multi tenancy application. E.g. I have German version of my site at www.my-app.de and a US version at www.my-app.com. Data for each country is split into separate SCHEMAS
in postgresql. So per each HTTP request the web app switches between data sets in PostgreSQL by starting the request by setting the search_path
like so: if www.my-app.com then SET search_path = 'us'
. This is really convenient from an application perspective, however, I think this collides with the possibilities of doing connection pooling?
The problem
So in each HTTP request the search_path
is set for the entire request and in the request there might be many queries to the database. It is my understanding, that if I had PGbouncer doing connection pooling, I could risk the first query in a request going to a connection that has search_path set to us
and the next query to a connection that has search_path set to de
.
Question
Is there any way to avoid this behaviour with PGbouncer? Or maybe an alternative pattern I could use for reducing the connection overhead?