How to change max database connections #27197
TheOtherBrian1
announced in
Troubleshooting
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Changing Max Database Connections:
Each compute instance has a default direct connection and pooler connection settings. You can find the most recent settings in the compute docs:
Configuring Direct Connections Limits
You can configure the maximum amount of connections that Postgres will tolerate with the Supabase CLI.
You can run the following commands:
Then you could run the following SQL in the SQL Editor to see if the changes went through:
Dangers of increasing the direct connection limits
Three factors must be taken into consideration when adjusting the direct connection limit:
Process Schedulers and Postgres Internals:
Allowing too many direct connections in your database can overburden Postgres schedulers and other internal modules. This will result in a noticeable decrease in query throughput, despite having more connections available. EnterpriseDB wrote a wonderful article that outlines some of the considerations.
The default connection values are set based on a solid understanding of Postgres architecture, and straying too far from them is likely to hinder performance. However, with some experimentation, you might discover a value better suited to your specific needs. Still, unless there's a compelling reason to adjust the setting, it's generally advisable to stick with the defaults or change the values judiciously.'
Memory
Each direct connection is a running process that will consume active memory
This is a Grafana Chart of unhealthy memory usage:
The cache in PostgreSQL is important because the database will store frequently accessed data in it for rapid retrieval. If too much active memory is needed, it runs the risk of excessively displacing cache. This will force queries to check disk, which is slow.
Most data in a database is idle. However, when there is little available memory or uncached data is rapidly accessed, thrashing can occur.
To avoid displacing cache or straining system resources, it is advised to not increase your direct connections unless you have a clear excess of unclaimed memory (green).
Postgres will allow you to overcommit memory. You can run the below query to find out the hypothetical max value you could change it to without risking memory failure:
CPU
The below chart is an example of what can occur to the CPU if 100s of connections are inappropriately opened/closed every second or many CPU intensive queries are run in parallel
If you plan on increasing your direct connection numbers, your database should have relatively predictable or low CPU usage, such as what the example displays below:
Beta Was this translation helpful? Give feedback.
All reactions