为什么Phoenix(ecto / Postgresx)无法在开发中连接

问题描述 投票:10回答:5

我正在开始我的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中运行rumbl_dev时,我可以看到\l。它也由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=>
elixir phoenix-framework ecto boxen
5个回答
5
投票

好的,所以我明白了。最后我这是一个简单的错误。虽然很容易制作。

我在Mac上使用Boxen,由于某种原因它将端口更改为15432

如果mix ecto.create失败,我可能会更早地降落。不知道为什么会有效。

希望这将有助于其他人


2
投票
  • 删除postgresql中的数据库rumbl_dev以重新开始。
  • 如果您愿意,可以通过在pg_hba.conf中添加以下行,在localhost上为dev版本尝试md5 auth # host DATABASE USER ADDRESS METHOD host rumbl_dev elixir localhost md5 注意:有关设置/etc/postsgresql/9.4/pg_hba.conf的更多信息,请参阅此处并根据需要更改设置。
  • 使用密码添加完整设置到dev.exsconfig :rumbl, Rumbl.Repo, adapter: Ecto.Adapters.Postgres, username: "elixir", database: "rumbl_dev", hostname: "localhost", password: "***password***", pool_size: 10
  • 尝试运行mix do ecto.create, ecto.migrate,看看它是怎么回事。

希望这有帮助,如果没有,我在这里没有想法。


2
投票

在macOS崩溃之后,这发生在我身上两次。

最近我使用this

Fix 1

  1. 运行postgres -D /usr/local/var/postgres
  2. 如果您看到类似这样的内容,请在PID之后复制该数字: FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
  3. kill -9 PID用#进程代替PID

以前为我工作的steps

Fix 2

brew update
brew upgrade
brew postgresql-upgrade-database

0
投票

您需要在配置块中包含数据库用户的密码。

config :rumbl, Rumbl.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "elixir",
  password: "???",
  database: "rumbl_dev",
  hostname: "localhost",
  pool_size: 10

0
投票

每次我在调用mix phoenix.server之前没有启动Postgres时我都有同样的问题。我用https://postgresapp.com开始吧。

© www.soinside.com 2019 - 2024. All rights reserved.