Error when I run mix ecto.create

Hello,
I’m decided to write Elixir with Phoenix Framework.
I’m French, sorry for my bad English.

Operating System : Linux Manjaro
Elixir : ASDF Elixir 1.13.4
Erlang : ASD Erlang 24

So, I created a Phoenix project, my first command was :

mix ecto.create

The project compiling and then I have this error :

17:17:42.652 [error] GenServer #PID<0.5040.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

17:17:42.658 [error] GenServer #PID<0.5044.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
    (db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for HelloPhx.Repo couldn't be created: killed

Also, when I run

mix phx.server

[error] Postgrex.Protocol (#PID<0.401.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.395.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.403.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.398.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.397.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.402.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.394.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.400.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.399.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.396.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
[info] Running HelloPhxWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http)
[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.29.tgz
[info] Access HelloPhxWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
[error] Postgrex.Protocol (#PID<0.396.0>) failed t

Someone can help me ?

Thanks a lot
Timothé

Hey welcome!

This means that it cannot connect to the Postgres database. Do you have postgres installed? Is it running?

1 Like

Yes I’ve of course Postgres installed.

But when I run postgres
It returns :

You must either specify the --config-file option, specify the -D option, or initialize the PGDATA environment variable.

It’s the latest version of postgresql

Maybe this will help: How To Install PostgreSQL on Manjaro 20 - idroot

Basically, you need to figure out how to run postgres on your particular operating system. Then the Ecto / Elixir stuff will work.

1 Like

Ok, this work
I’m 15 and I start coding 4 years ago with PHP and MySQL and I never use Postgres :smile:

Postgres doesn’t start when my PC start.
So sudo systemctl start postgresql.service
Work for me !

I enable Postgres

sudo systemctl enable postgresql.service 

Thanks !

I know it’s resolved for OP, but for anyone else experiencing this you can just edit:

C:\ -your mix phx.new project path- \config\dev.exs

Open dev.exs in a text editor and look at the top of the file for:
username: “postgres”,
password: “postgres”,

These are both default values set when you create your project with mix phx.new.
You need to change the value of ‘password’ in the dev.exs file to match the password you set PGAdmin(Postgres) up with.

In the same congif folder there is also a text.exs file that has the password set to ‘postgres’ that you will need to change at some point.