Postgresql connection limit issue on AWS RDS

0

Hello team,

We are working on multi-tenant environment where each tenant having dedicated Database but all the tenants DBs are part of single Postgresql server of size db.m6i.2xlarge.

We have approximately 1500 tenant DBs in single AWS RDS Postgresql of db.m6i.2xlarge. As of now we configured 5000 as Max Connections.

  1. is 5000 connections are max for this db.m6i.2xlarge instance? or can we increase? if yes, how do I calculate max-connection possible for this instance?
  2. Apart from that do you suggest any cost optimal solution to increase the number of connections? I am planning to double the connections as soon as possible so kindly suggest the cost optimal approach.

NOTE: We have some limitation issue on Amazon RDS Proxy like Each tenant has its own DB credentials so secret-manger again have some hard limit of 3000 secretes only.

Thanks, Baji Shaik

1 Answer
-1

Max Connections for db.m6i.2xlarge Instance

For a db.m6i.2xlarge instance, the formula for calculating the maximum number of connections is:

max_connections = LEAST({DBInstanceClassMemory / 9531392}, 5000)

Since the db.m6i.2xlarge instance has 32 GiB of RAM (32 * 1024 * 1024 * 1024 bytes), the calculation would be:

max_connections = LEAST((32 * 1024 * 1024 * 1024 / 9531392), 5000) ≈ 3601

This means the instance can support approximately 3601 connections. If you’ve set max_connections to 5000, this exceeds the calculated limit based on memory, which could potentially lead to performance issues if fully utilized.

Increasing Connections Beyond Limits

While you cannot directly increase max_connections beyond what the instance class allows, here are some recommended strategies:

  1. Connection Pooling: Tools like PgBouncer or pgpool-II can manage connections efficiently by reusing a smaller number of database connections. This is usually the most cost-effective solution.

  2. Vertical Scaling: Upgrading to a larger instance class with more memory will allow for more connections. However, this may be less cost-effective unless required for other performance reasons (CPU, storage).

  3. Horizontal Scaling: Consider offloading read-heavy operations by using read replicas, which can help distribute connections.

  4. Sharding by Tenants: For large multi-tenant systems, sharding databases across multiple instances can reduce the connection load on a single instance.

profile picture
answered a month ago
  • Thank you very much @Praveen Muppala. I will get back on this once I tried possible solutions (PGBouncer, etc.)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions