Infinite loop Error when running mix phx.server?

Hey,

my app was working fine a few day ago, I was seeding files in migrations/seeds.exs file. Now when I run mix phx.server I get this error

[error] Postgrex.Protocol (#PID<0.350.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

This same error is stuck in an infinite loop. I check to see if my postgres is ready using the pg_isready command I got the return /tmp:5432?

Your DB is listening on Unix socket and you try to connect to it via TCP. It fails so the application tries to do it again after tha DB connection process is restarted.

How can i fix this? Should I delete my DB and create a new one?

You might want to check the file /etc/postgresql/{your_version}/main/postgresql.conf for the configuration key listen_addresses, in your case it might be empty, making it listen only at the unix socket. change it to:
listen_addresses = 'localhost' or more broadly accepting from all interfaces of the machine listen_addresses = '*', to include more than one, use commas.

BTW, it is a local server for development or production? And are you starting from command line or using systemd service ? Because you can start postgres listening to an address from the start command like postgres -c listen_addresses='*'

Local server for development, and I am starting from the command line

Hey I am beginner developer would you kindly guide me as to where this /etc/postgresql/{your_version}/main/postgresql.conf is?

So you could start it with postgres -c listen_addresses='*'. To make things permanent update your configuration file.

I don’t have postgres installed but this path is from the root / of you drive so you could edit it running from command line:

  • assuming you are on ubuntu/gnome
  • assuming you have postgres 14
sudo gedit /etc/postgresql/14/main/postgresql.conf

it will open a text editor with the contents of the file to edit, write the new listen_addresses value, save and close, restart your postgres

if your version is not 14, change the number at the path to you version, eg:
sudo gedit /etc/postgresql/11/main/postgresql.conf

The gedit command not found, does not exist

replace gedit with your text editor.

Is gedit similar to Visual Studio Code?

yes, if you don’t have gedit you can use any text editor to edit the file, like vscode.

sudo code --user-data-dir=~/root /etc/postgresql/11/main/postgresql.conf

If I get gedit can I just that as my CLI

sure! any one that suits you!

Question: I read that this can also be achieved thru GNU nano?

Yes, the text editor is not important, what’s important is that you make the changes.

1 Like