The database for Library.Repo couldn't be created: killed

09:31:48.015 [error] GenServer #PID<0.229.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 Library.Repo couldn’t be created: killed

This means that you probbaly gave in the wrong url, or perhaps forgot a port?

Could also be that the port on the server is being blocked by a firewall. Can you connect with another client?

Hard to know exactly with so little info.

Are you starting your application when this happens? Or do you issue a mix task?

Have you checked if postgres is actually running and listening on port 5432 at localhost? Many linux distributions disable IP connections by default and only allow connections via a unix-domain socket. Though as far as I know, ecto can’t connect through it currently. So you probably need to adjust your postgresql setting.

The output of sudo ss -lnpt | grep 5432 will tell you if there is something listening on the correct port. If its local address is not *, 127.0.0.1 or ::1, you need to adjust your applications configuration to connect to the correct IP.

If you are completely new to elixir as I am, then the answer to this error is (by @Nobbz)

Have you checked if postgres is actually running and listening on port 5432 at localhost?

In my case, I had messed up my postgres install also.
So to fix it:-

  1. Remove any broken installation apt purge postgres
  2. Install postgres properly sudo apt-get install postgresql postgresql-contrib
  3. Create the database, and user with the permissions to the database (steps 6 - 9, 11)
  4. And then mix ecto.create

How can I see the error message when it doesn’t print anything out?

I have config :logger, level: :debug.

Compiling 17 files (.ex)
Generated my_app app
** (Mix) The database for MyApp.Repo couldn't be created: killed