问题
I'm looking for a way to create a connection pool for many DBs on the same DB server (PostgreSQL Aurora). This means that I need the ability of changing the target DB of a connection at run time. Currently I'm using HikariCP for connection pooling, in a stack of Spring Boot and JHispter.
Background:
- we need to deploy a multi-tenancy micro-service system with a single DB server (to be specific, a single AWS Aurora PostgreSQL instance)
- our solution of multi-tenancy is that each tenant has a DB, in that DB we have many schema for each service. All the DBs are in the same AWS Aurora instance.
Our problem:
- with this deployment, we have a connection pool for each (tenant x micro-service instance).
This leads to a huge number of connections.
- Ie: with the pool size of 50 connections/pool. We need: 500 tenants x 20 micro-service instances x 50 connections/pool = 500000 connections.
- The maximum connections allowed on any Aurora DB is 16000, and actually by default the "max_connections" parameter is typically set to something lower.
So now I'm looking for a way to make our pooling scope larger, so that many tenants can share the same pool. Since we use only 1 Aurora server instance, I think it's possible to create a connection pool that can be shared between many tenants. Is there any way to have a connection pool that can switch the DB at run time?
回答1:
Unless Aurora has done some customization on this, you cannot change the database of a connection once it is established in PostgreSQL. You can still use a pooler, but it will effectively be a separate pool for each database. This is pretty fundamental, there is nothing you can do about it.
来源:https://stackoverflow.com/questions/60880495/create-a-connection-pool-for-many-dbs-on-the-same-db-server-spring-boot