Help Connecting Postgres to App

I trying to get an old Phoenix/Elixir app (version 1.13.2-otp-24) to run locally. For some reason it won’t connect to the database when running mix ecto.create.

I’ve changed apps/db/config/config.exs like so:

  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  port: "5432"

I’ve started the database like so:
sudo systemctl start postgresql

I’ve checked that the database exists and the postgres username: postgres exists.

When running mix ecto.create I get this error:

12:25:40.934 [error] GenServer #PID<0.808.0> terminating
** (DBConnection.ConnectionError) tcp connect (127.0.0.1:5432): connection refused - :econnrefused
    (db_connection 2.2.0) lib/db_connection/connection.ex:87: DBConnection.Connection.connect/2
    (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for DB.Repo couldn't be created: killed

I’ve tried changing the password to the postgres default “password”.
I’ve tried different ports, and without the port. Still no luck.
Any ideas?

Edit:
Downgraded the postgres to version 13. The error changed to ^^^.

Edit:
Problem ended up being a postgres version discrepancy + a missing password.

Fixed now.

:crypto.hmac/3 was removed in OTP 24

Maybe you need to update postgrex.

Someone had a similar issue with plug:

Can you connect with psql?

1 Like

Got it working.
Was postgres version discrepancy + missing password on the local install.

3 Likes