运行 mix ecto.setup 命令时连接被拒绝,包与 asdf 一起安装

Connection refused when running mix ecto.setup command, packages installed with asdf

我正在尝试关注 GraphQL tutorial

我习惯了asdf to install the erlang, elixir and postgres。我用的是 macbook。

当我到达 运行 mix ecto.setup 的步骤时,出现以下错误:

20:44:47.318 [error] GenServer #PID<0.1605.0> terminating ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused (db_connection) lib/db_connection/connection.ex:163: 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 Community.Repo couldn't be created: an exception was raised: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused (db_connection) lib/db_connection/connection.ex:163: 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

它可能是什么?

你必须启动postgres,根据asdf-postgree docs你必须:

pg_ctl start

并且为了 运行 命令 mix ecto.createmix ecto.setup 你必须 创建一个用户 postgres 和密码 postgres,并且postgres 用户必须同时拥有 LOGINCREATEDB 的权限,然后您可以:

创建默认数据库:

createdb default

登录到该数据库,使用:

psql -d default

并创建具有以下权限的用户:

# CREATE ROLE postgres LOGIN CREATEDB PASSWORD 'postgres';