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

Wil*_*ill 11 elixir boxen ecto phoenix-framework

我正在开始我的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
Run Code Online (Sandbox Code Playgroud)

作为Elixir,Phoenix和Ecto的新手,我不清楚如何调试这个问题.任何关于我的问题是什么或如何调试它的建议将非常感激.

我的应用设置了

我有一个基本的应用程序

mix phoenix.new rumbl
cd rumbl
mix deps.get
mix deps.compile
Run Code Online (Sandbox Code Playgroud)

我的config/dev.exs具有以下数据库设置

# Configure your database
config :rumbl, Rumbl.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "elixir",
  database: "rumbl_dev",
  hostname: "localhost",
  pool_size: 10
Run Code Online (Sandbox Code Playgroud)

当我运行mix ecto.create时没有错误,我可以看到rumbl_dev\l在psql中运行的时间.它也由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
Run Code Online (Sandbox Code Playgroud)

这是我用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=>
Run Code Online (Sandbox Code Playgroud)

Nel*_*elu 14

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"?
    
    Run Code Online (Sandbox Code Playgroud)
  3. kill -9 PID用进程 # 代替PID.


以前对我有用的步骤

修复 2

brew update
brew upgrade
brew postgresql-upgrade-database
Run Code Online (Sandbox Code Playgroud)

  • 修复 1 对我有用(macOS 崩溃后)。谢谢。 (2认同)

Wil*_*ill 5

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

我在Mac上使用Boxen,15432由于某种原因它改变了端口.

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

希望这将有助于其他人