Connection refused - :econnrefused

Hi,
I am new to Elixir. I am trying to run the Sample Music application provided by Ecto Programming book. When I am running the “mix ecto.create” command. I am getting the below error.
7:46:12.441 [error] GenServer #PID<0.174.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:87: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Friends.Repo couldn’t be created: killed

Any lead really appreciated. 

Thanks in Advance
Rakesh Jaiswal

1 Like

Hi @jaiswal.rakesh!

The error you posted looks like there is no database running where the config would expect it. Please make sure the database server is available at the configured location (or fix configuration).

1 Like

Hi Nobbz,

Thanks for prompt response!!
I am runing the postgres using docker in the same port 5432. Do I need to do anything else? It would be good if you provide me some reference.

Thanks

In the same container or in another one?

If its another one, are they linked?

Do you have configured the postgres host correctly?

How do you start the docker container/containers?

How does your ecto config look like?

I am simply running the “docker run postges”, which run the postgres in the local host. But it’s not running in same container. Let me check. Thanks for Lead.

~Rakesh

Then its probably not even linked… Docker containers do not magically see each other.

In my opinion the easiest is to start with docker-compose.

4 Likes

Hey!

I actually just ran into this same error and was able to resolve the issue with the following:

  1. Run postgres -D /usr/local/var/postgres
  2. Copy the process number after PID in parenthesis below if you see a similar output:
FATAL:  lock file "postmaster.pid" already exists 
HINT:  Is another postmaster (PID 68449) running in data directory "/usr/local/var/postgres"?
  1. Run kill -9 PID replacing PID with the process number from above

Note that I experienced this issue after my Macbook Pro crashed after I went to bed last night. After running the above commands you should be able to run mix ecto.create afterwards and not experience the same error.