-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share connections from a pool with different databases in the same PG server #368
Comments
Maybe we need just to change
If dbname is passed to |
The solution is to use multiple pools, one per database. You can wrap them with a context manager object that accepts the database name and picks the correct pool. |
Maybe I did not express my problem correctly... I have thousands of databases per server and I don't want to keep that same number of TLS connections opened for each database. What I want is to have a max of 100 TLS connections opened to the server and be able to run queries to different databases. |
The PostgreSQL protocol doesn't work like that. You always connect to a specific database. If you need a different database, you have to make a new connection. |
It would be great if PG protocol support reusabilty of TLS connections and enable clients to switch the database for an established connection. The lack of this imposes a big penalty in servers running multi-tenant apps. For databases deployed in cloud (like AWS) it is even worse, because we cannot proxy the connections from the database server. Do you have recommendations on how to serve thousands of queries coming to different databases running in the same server without killing the performance? (keeping a high number of connections opened in server side costs OS resources) |
It's not just the protocol, it's the entire execution model. The "backend" process in PostgreSQL always represents a connection to a specific database.
I don't think there exists a simple solution to this problem. You might want to look at postgres_fdw as a way to dispatch queries to multiple databases via a single database. |
When we are using TLS connections to a PG server the cost to keep opened multiple connections to different databases is high. So I'd like to implement database switching to share the connections from a pool with different databases.
Is it feasible with asyncpg?
The text was updated successfully, but these errors were encountered: