为什么Phoenix(ecto/Postgresx)在dev中无法连接 [英] Why does Phoenix (ecto/Postgresx) fail to Connect in dev

查看:137
本文介绍了为什么Phoenix(ecto/Postgresx)在dev中无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始Elixir/Phoenix之旅,并且我的postgres连接遇到了一些麻烦.

I am beginning my Elixir/Phoenix journey and having some trouble with my postgres connection.

启动服务器时,我得到:

When I start up my server I get:

 $ 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的新手,我不清楚如何调试此问题.关于我的问题是什么或我将如何进行调试的任何建议,将不胜感激.

Being new to Elixir, Phoenix, and Ecto I am unclear how to debug this problem. Any suggestions as to what my problem is or how I might go about debugging it would be much appreciated.

我的应用已设置

我有一个基本的应用程序

I have a basic app

mix phoenix.new rumbl
cd rumbl
mix deps.get
mix deps.compile

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

My config/dev.exs has the following db setup

# 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.它也属于长生不老药用户.

When I run mix ecto.create there are no errors and I can see the rumbl_dev when I run \l in psql. It is owned by the elixir user too.

运行mix ecto.migrate会引发相同的连接错误

Running mix ecto.migrate throws the same connections errors

我的pg_hba.conf文件具有以下内容

My pg_hba.conf file has the following

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登录时看到的内容

Here is what I see when I log in with 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=>

推荐答案

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

Ok, so I figured it out. It is a simple mistake on my part in the end. Though an easy one to make.

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

I am using Boxen on my Mac and it changes the port to 15432 for some reason.

如果mix ecto.create失败,我可能会早点降落.不确定为什么行得通.

I may have landed on this sooner if the mix ecto.create had failed. Not sure why that works.

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

Hopefully this will help others in the future

这篇关于为什么Phoenix(ecto/Postgresx)在dev中无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆