Elixir 为什么Phoenix(Exto/Postgresx)在开发中无法连接
我正在开始我的长生不老药/凤凰之旅,我的博士后连接有一些问题 当我启动服务器时,我得到:Elixir 为什么Phoenix(Exto/Postgresx)在开发中无法连接,elixir,phoenix-framework,ecto,boxen,Elixir,Phoenix Framework,Ecto,Boxen,我正在开始我的长生不老药/凤凰之旅,我的博士后连接有一些问题 当我启动服务器时,我得到: $ 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>
$ 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
My config/dev.exs具有以下数据库设置
# Configure your database
config :rumbl, Rumbl.Repo,
adapter: Ecto.Adapters.Postgres,
username: "elixir",
database: "rumbl_dev",
hostname: "localhost",
pool_size: 10
当我在psql中运行\l
时,运行mix-exto.create
时没有错误,我可以看到rumbl\u dev
。它也属于elixir用户
运行mix-exto.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=>
您需要在配置块中包含数据库用户的密码
config :rumbl, Rumbl.Repo,
adapter: Ecto.Adapters.Postgres,
username: "elixir",
password: "???",
database: "rumbl_dev",
hostname: "localhost",
pool_size: 10
- 删除postgresql中的数据库
,重新开始rumbl\u dev
- 如果愿意,您可以在本地主机上通过向pg_hba.conf添加以下行来尝试对dev版本进行md5身份验证 注意:有关设置和更改设置的详细信息,请参见此处
- 将带有密码的完整设置添加到
:dev.exs
config :rumbl, Rumbl.Repo, adapter: Ecto.Adapters.Postgres, username: "elixir", database: "rumbl_dev", hostname: "localhost", password: "***password***", pool_size: 10
- 试着运行
,看看效果如何mix do-exto.create、exto.migrate
希望这有帮助,如果没有,我已经没有主意了 好吧,我想出来了。最后这是我的一个简单错误。虽然制作起来很容易 我在Mac上使用Boxen,出于某种原因,它将端口更改为
15432
如果mixe-exto.create
失败,我可能会更快地到达这里。不知道为什么会这样
希望这能在将来帮助其他人每次在调用
mix phoenix.server
之前不启动Postgres时,我都会遇到同样的问题。在macOS崩溃后,我曾经两次遇到过这种情况
最近我使用了:
修正1
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-9PID
用流程#代替PID
以前对我有效的方法是: 修正2
你能试着将密码添加到配置中,看看是否有帮助<代码>配置:rumbl,rumbl.Repo,适配器:exto.Adapters.Postgres,用户名:“elixir”,数据库:“rumbl_dev”,主机名:“localhost”,密码:***密码***”pool_size:10我也尝试过,但得到了相同的结果-感谢您的建议@stephen\u mcan您可以尝试从终端运行以下命令:
psql--dbname=rumbl\u dev--username=elixir--host=127.0.0.1--password
主机名:“localhost”⇒ <代码>主机名:“127.0.0.1”可能会有帮助。@stephen\m我把结果附在我的问题后面。这让我没问题。恐怕也会有同样的结果:(很高兴它成功了。我不知道为什么mix-exto.create
部分可以工作。你也可以在控制台上检查端口psql--dbname=rumbl\u-dev--username=elixir--host=127.0.0.1--port=5432--password
@stephen\u-m-它在端口=5432的控制台上不工作。这很奇怪。太好了!非常感谢,我正在使用它。)g boxen也是。在config.dev.ex
s上指定port:15432
解决了这个问题。修复1对我有效(在macOS崩溃后)。谢谢。这里也一样。我的macOS崩溃了。似乎是最近发生的。回到postgres给出了同样的问题,这个修复1为我解决了它。接受的答案似乎是另一个问题。
config :rumbl, Rumbl.Repo,
adapter: Ecto.Adapters.Postgres,
username: "elixir",
database: "rumbl_dev",
hostname: "localhost",
password: "***password***",
pool_size: 10
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
brew update
brew upgrade
brew postgresql-upgrade-database