16

我正在开始我的 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=>
4

5 回答 5

17

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

最近我用这个

修复 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.


以前对我有用的步骤:

修复 2

brew update
brew upgrade
brew postgresql-upgrade-database
于 2019-04-04T03:55:22.157 回答
5

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

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

mix ecto.create如果失败了,我可能会早点登陆。不知道为什么会这样。

希望这将在未来对其他人有所帮助

于 2016-08-24T02:47:37.943 回答
2
  • 删除rumbl_devpostgresql 中的数据库以重新开始。
  • 如果你喜欢,你可以在pg_hba.conf中添加以下行,在 localhost 上尝试 md5 auth 的 dev 版本

    # host DATABASE USER ADDRESS METHOD
    
    host rumbl_dev elixir localhost md5
    

    注意:有关设置/etc/postsgresql/9.4/pg_hba.conf的更多信息,请参阅此处,并根据需要更改设置。

  • 将带有密码的完整设置添加到dev.exs

    config :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,看看情况如何。

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

于 2016-08-23T21:20:25.723 回答
0

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

config :rumbl, Rumbl.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "elixir",
  password: "???",
  database: "rumbl_dev",
  hostname: "localhost",
  pool_size: 10
于 2016-08-23T19:24:13.250 回答
0

每次我在调用之前不启动 Postgres 时都会遇到同样的问题mix phoenix.server。我使用https://postgresapp.com来启动它。

于 2018-07-07T12:57:26.103 回答