Hi ,
Thanks for reaching out to Microsoft Q&A.
There is no way today to set CONNECTION LIMIT
on a per-user basis in azure CosmosDB for PostgreSQL. The practical approach is to manage this outside the database using pgBouncer, connection pooling in the application, and good monitoring. The service is managed, and you do not get superuser or CREATEROLE
privileges. Because of that, commands like: ALTER ROLE schema1user CONNECTION LIMIT 10; will not work, and there is no portal or CLI command to do this either. Mcrosoft does not currently expose a way to enforce per-user connection limits at the database level in this platform.
Since you cannot enforce limits inside the db, you need to handle it at the pooling or application layer. Here are your options:
- Use the built-in pgBouncer CosmosDB for PostgreSQL comes with pgBouncer enabled in transaction pooling mode. Tune the pool settings to handle a reasonable number of connections per application. This reduces the risk of 1 tenant using up all available connections.
- Run your own pgBouncer If you need pertenant control, run your own pgBouncer instance for each tenant or for groups of tenants. Limit the pool size for each instance to make sure no single tenant can monopolize connections.
- Control at the middleware or API gateway level If you have a multitenant API, implement rate limiting or concurrency limits at the request layer. This helps you throttle tenants before they overload the db.
- Monitor usage Use
pg_stat_activity
to watch connection usage. Set up alerts so you know when one tenant is opening too many connections. - Scale the cluster Increasing node vCores raises the overall connection limits (300, 500, or 1000 connections per node depending on the size), but this does not isolate tenants. It only delays the problem if one tenant spikes.
Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.