我正在开始我的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=>
好的,所以我明白了。最后我这是一个简单的错误。虽然很容易制作。
我在Mac上使用Boxen,由于某种原因它将端口更改为15432
。
如果mix ecto.create
失败,我可能会更早地降落。不知道为什么会有效。
希望这将有助于其他人
rumbl_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
,看看它是怎么回事。希望这有帮助,如果没有,我在这里没有想法。
在macOS崩溃之后,这发生在我身上两次。
最近我使用this:
postgres -D /usr/local/var/postgres
PID
之后复制该数字:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
kill -9 PID
用#进程代替PID
。以前为我工作的steps:
brew update
brew upgrade
brew postgresql-upgrade-database
您需要在配置块中包含数据库用户的密码。
config :rumbl, Rumbl.Repo,
adapter: Ecto.Adapters.Postgres,
username: "elixir",
password: "???",
database: "rumbl_dev",
hostname: "localhost",
pool_size: 10
每次我在调用mix phoenix.server
之前没有启动Postgres时我都有同样的问题。我用https://postgresapp.com开始吧。