How can I increase maximum connections? (PostgreSQL)
Considerations
Section titled “Considerations”- Increased Memory Usage: Raising
max_connectionswill increase memory consumption, which may impact performance. - Better Alternative – Idle Session Timeout: Instead of increasing connections, consider setting an idle session timeout to close inactive connections automatically.
How to change Maximum Connections
Section titled “How to change Maximum Connections”Option 1: Update via Cloudpepper Dashboard
Section titled “Option 1: Update via Cloudpepper Dashboard”- Go to the PostgreSQL tab of your server in My Cloudpepper.
- Locate the max_connections parameter.
- Adjust the value as needed.
- Click Save to apply the changes.
Option 2: Manually Edit PostgreSQL Configuration
Section titled “Option 2: Manually Edit PostgreSQL Configuration”You can also change the max_connections setting directly in the PostgreSQL configuration file via SSH.
Step 1: Locate the Configuration File
Section titled “Step 1: Locate the Configuration File”- For PostgreSQL 12 (Odoo 11–13):
sudo nano /etc/postgresql/12/main/postgresql.conf- For PostgreSQL 14 (Odoo 14–16):
sudo nano /etc/postgresql/14/main/postgresql.confStep 2: Modify ‘max_connections’
Section titled “Step 2: Modify ‘max_connections’”- Find the line:
max_connections = 100- Adjust the value based on your requirements.
- Save the file and exit.
Step 3: Restart PostgreSQL
Section titled “Step 3: Restart PostgreSQL”Restart PostgreSQL after making changes:
sudo systemctl restart postgresqlHow to adjust Idle Session Timeout
Section titled “How to adjust Idle Session Timeout”As increasing the maximum connections can increase memory consumption, consider an idle session timeout to close inactive connections automatically instead.
Example:
idle_session_timeout = 5minThis limits idle connections to 5 minutes, keeping the total connection count stable. Good for high-traffic instances with frequent user activity where inactive connections can rapidly accumulate.
Valid Time Units for idle_session_timeout
Section titled “Valid Time Units for idle_session_timeout”us(microseconds)ms(milliseconds)s(seconds)min(minutes)h(hours)d(days)
By implementing an idle session timeout, you can often avoid the need to increase max_connections.