【发布时间】:2016-12-29 16:56:29
【问题描述】:
我正在开始我的 Elixir/Phoenix 之旅,但我的 postgres 连接遇到了一些问题。
当我启动我的服务器时,我得到:
$ mix phoenix.server
[error] Postgrex.Protocol (#PID<0.214.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.217.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.218.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.211.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.215.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.219.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.216.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.213.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.212.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[error] Postgrex.Protocol (#PID<0.210.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
[info] Running Rumbl.Endpoint with Cowboy using http://localhost:4000
[error] Postgrex.Protocol (#PID<0.215.0>) failed to connect: ** (Postgrex.Error) tcp connect: connection refused - :econnrefused
作为 Elixir、Phoenix 和 Ecto 的新手,我不清楚如何调试此问题。任何关于我的问题是什么或如何调试它的建议将不胜感激。
我的应用已设置
我有一个基本的应用程序
mix phoenix.new rumbl
cd rumbl
mix deps.get
mix deps.compile
我的 config/dev.exs 有以下数据库设置
# Configure your database
config :rumbl, Rumbl.Repo,
adapter: Ecto.Adapters.Postgres,
username: "elixir",
database: "rumbl_dev",
hostname: "localhost",
pool_size: 10
当我运行 mix ecto.create 时没有错误,当我在 psql 中运行 \l 时,我可以看到 rumbl_dev。它也归 elixir 用户所有。
运行 mix ecto.migrate 会引发相同的连接错误
我的 pg_hba.conf 文件有以下内容
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
这是我使用 psql 登录时看到的内容
$ psql --dbname=rumbl_dev --username=elixir --host=127.0.0.1 --password
Password for user elixir:
psql (9.4.5)
Type "help" for help.
rumbl_dev=>
【问题讨论】:
-
您可以尝试将密码添加到配置中,看看是否有帮助。
config :rumbl, Rumbl.Repo, adapter: Ecto.Adapters.Postgres, username: "elixir", database: "rumbl_dev", hostname: "localhost", password: "***password***" pool_size: 10 -
我也尝试过,但得到了相同的结果 - 感谢@stephen_m 的建议
-
您可以尝试从终端运行以下命令吗:
psql --dbname=rumbl_dev --username=elixir --host=127.0.0.1 --password -
hostname: "localhost"⇒hostname: "127.0.0.1"可能会有所帮助。 -
@stephen_m 我将结果附加到我的问题中。它让我没有问题。
标签: elixir phoenix-framework ecto boxen