在同一数据库服务器上为多个数据库创建连接池(Spring Boot) [英] create a connection pool for many DBs on the same DB server (Spring Boot)

查看:584
本文介绍了在同一数据库服务器上为多个数据库创建连接池(Spring Boot)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为同一数据库服务器(PostgreSQL Aurora)上的许多数据库创建连接池的方法. 这意味着我需要能够在运行时更改连接的目标数据库. 目前,我在Spring Boot和JHispter堆栈中使用HikariCP进行连接池.

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.

背景:

  • 我们需要使用单个数据库服务器(具体来说,是单个AWS Aurora PostgreSQL实例)部署多租户微服务系统
  • 我们的多租户解决方案是每个租户都有一个数据库,在该数据库中,每个服务都有许多架构.所有数据库都在同一个AWS Aurora实例中.
  • 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.

我们的问题:

  • 在此部署中,我们为每个(租户x微服务实例)都有一个连接池. 这导致了大量的连接.
      即,池的大小为50个连接/池.我们需要:500个租户x 20个微服务实例x 50个连接/池= 500000个连接.
    • 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.

      因此,现在我正在寻找一种扩大池范围的方法,以便许多租户可以共享同一池.由于我们仅使用1个Aurora服务器实例,因此我认为可以创建一个可以在许多租户之间共享的连接池. 有什么方法可以建立一个可以在运行时切换数据库的连接池吗?

      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?

      推荐答案

      除非Aurora对此进行了一些自定义,否则一旦在PostgreSQL中建立了连接数据库就无法更改它.您仍然可以使用池化程序,但是对于每个数据库,它实际上都是一个单独的池.这是非常基本的,您无能为力.

      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.

      这篇关于在同一数据库服务器上为多个数据库创建连接池(Spring Boot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆