Psql refusing connections after restart I began receiving these errors consistently after running a script that collects and stores data in psql:


  Could not connect because of FATAL:  remaining connection slots are
  reserved for non-replication superuser connections


I am running psql on Ubuntu.  So I decided to restart psql with: 

sudo service postgresql restart


Now however, psql has shut down completely

Could not connect because of could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?


I am completely new to maintaining psql on a server and would be grateful for any advice.

Where do I even begin to solve this problem? How can I get psql to start again without losing any data that is in this massive database?
I began receiving these errors consistently after running a script that collects and stores data in psql:


Your max_connections is too low, or that script isn't dying or releasing the connection.

If you're getting Connection refused after you restart, then perhaps you have multiple copies of postgresql installed on the same machine and you mean to connect to a different port (like 5433). If you're using Ubuntu or Debian run pg_lsclusters and paste the output.