Postgrex.Error - (#PID<0.220.0>)

I have this error in my phoenix application when i try to start my server. I think its something on my DB but i dont know exactally what it is. Can someone help me?

[error] Postgrex.Protocol (#PID<0.220.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused

Can you please provider further details? Where is your DB? What is your OS and postgrex version?

The #PID<0.220.0> part of the message, is more or less random, it can change over subsequent tries. It is just a stringrepresentation of the name that BEAM uses for the particular process trying to connect to the database (PID = process ID).

Without knowing anything about your configuration and setup, all I can do is to guess.

Your posted message says that the connections gets refused by the server. This may be because of a firewall rule, or by configuring the postgres to dissallow tcp-connections and only accept pipes or socket-files as connections.

So if this is not helping you, please provide more context.

1 Like

First things first, make sure your Postgresql is running, and you have configured correct host and port. There would be different message if it was problem with credentials.

It’s possible this is related to an open issue: https://github.com/elixir-ecto/postgrex/issues/210. Unfortunately have not been able to discover why this occurs.

this is exactally the same massege that I have

Could you add your environment information to that issue please?

Make sure you can connect to your postgresql instance from the same place as elixir using the same login information directly too.

I have exactly the same issue,

I just set up a server(debian7) with posgres-9.6 and a phoenix project.
It might be a postgres configuration issue (I’m not an expert at all in sysops stuff) but I tried a lot of solutions and none of them worked.

I continue to investigate but if I don’t find anything, I’ll gladly share a root access to that server to someone of the Core team for further investigation.
100% sure the problem is stupid, but it drives me crazy :smiley:

Heh, know how that goes. :slight_smile:

First questions:

  • Are you able to pgsql into your database from the server that phoenix is on?
  • What server name and port did you use?
  • Is that exact same server name and port in the phoenix config?

I reinstalled everything from scratch and it worked like a charm :ok_hand:.

I had issue when installing postgres the first time (had 2 different version at the same time, messed up with pg_hba.conf and the list goes on…), I guess my error came from here.

1 Like

Just remove the “postmaster.pid” file

I’m not sure how this is related, can you elaborate?

  1. When the server crashes or is killed like that, you have to remove this file before you can restart the server. Make sure that the database process is definitely not runnnig anymore, otherwise your data directory will be corrupted.
    /usr/local/var/postgres then delete the postmaster.pid file

  2. Sometimes this error occurs when there is a “missing / corrupted database’s role”. for exple: “postgres”

Nothing in this thread mentions postgresql beeing crashed. We tried to figure out if it is even installed locally or remote and if the command line client is able to connect using TCP connection and same credentials, but the questioners didn’t came back and it was very silent here for 10 months. According to what we know so far, a pid file has nothing to do with it.

the first one mentions it.

It doesn’t it shows simply a log message from PostGrex, which tells us that the TCP connection it tried to establish has been refused.

yes and I think that’s the reason why the connection isn’t established.

There are many reasons possible (not running, remote in other network, wrong configuration of the client, etc) that was what we tried to discover before we simply tell him to randomly delete stuff.

Anyway, the topic was dead for nearly a year, and I do not think, that one of both questioners will re-read this.

1 Like

The PID in first message is not a pid file, it’s only an Erlang Process ID number, for short PID.

1 Like