For some reasons, if you get error port 5432 failed. You need to optimize your code so that it closes connection everytime after using that. But in rare cases we need to increase the connection limits. Below are the steps to increase connection limits in postgresql.
1. Check max_connections with current settings: SHOW max_connections;
2. Update max connections: ALTER SYSTEM SET max_connections TO ‘500’;
3. Restart postgresql server: sudo service postgresql restart