Too many clients already.
lekiaanonim
PROOP

10 months ago

Hi,

I'm encountering 500 error when accessing the Railway server.

Here is what it logs out:

django.db.utils.OperationalError: connection to server at "gondola.proxy.rlwy.net" (66.33.22.247), port 38445 failed: FATAL: sorry, too many clients already

connection to server at "gondola.proxy.rlwy.net" (66.33.22.247), port 38445 failed: FATAL: sorry, too many clients already

Project ID: 7701f2a0-8e16-4792-bd77-b9c21f0407c6

Closed$10 Bounty

2 Replies

jratienza65
HOBBY

10 months ago

It means that you hit the maximum connection limit of your database.

Consider using a connection pooler (ex. pgbouncer) to prevent this from happening.

Having an application-level connection pooler (psycopg2 has a pooler available https://www.geeksforgeeks.org/python/python-postgresql-connection-pooling-using-psycopg2/) will also lessen the likelihood of this scenario from happening.

To free up the connections manually, you can just either restart the database service or redeploy.


10 months ago

Also, to complement the answer above, you can increase the connection count as a temporary solution.

You can increase it by either:

  1. SSHing into your service and changing the configuration file to allow more connections (property named max_connections)
  2. If you're able to connect to your PostgreSQL service, run the following query to increase it:
ALTER SYSTEM SET max_connections TO '200';
SELECT pg_reload_conf();

Again, it's a temporary solution and the connection pooler is the recommended way.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...