DBConnection.ConnectionError)tcp connect(localhost:5432):连接被拒绝 - :econnrefused
问题描述:
我在Buddy持续集成服务器上运行内部版本,执行mix test
时遇到postgrex/ecto部分:DBConnection.ConnectionError)tcp connect(localhost:5432):连接被拒绝 - :econnrefused
==> postgrex
Compiling 61 files (.ex)
Compiling lib/postgrex/protocol.ex (it's taking more than 10s)
Compiling lib/postgrex/default_types.ex (it's taking more than 10s)
Generated postgrex app
==> ecto
Compiling 69 files (.ex)
Compiling lib/ecto/query/builder/lock.ex (it's taking more than 10s)
Compiling lib/ecto/repo/queryable.ex (it's taking more than 10s)
Compiling lib/ecto/query/inspect.ex (it's taking more than 10s)
Compiling lib/mix/tasks/ecto.drop.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/filter.ex (it's taking more than 10s)
Compiling lib/ecto/repo/preloader.ex (it's taking more than 10s)
Compiling lib/mix/tasks/ecto.gen.repo.ex (it's taking more than 10s)
Compiling lib/ecto/adapters/mysql.ex (it's taking more than 10s)
Compiling lib/ecto/schema.ex (it's taking more than 10s)
Compiling lib/ecto/migration/runner.ex (it's taking more than 10s)
Compiling lib/ecto/repo/schema.ex (it's taking more than 10s)
Compiling lib/ecto/embedded.ex (it's taking more than 10s)
Compiling lib/ecto/migration/schema_migration.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/preload.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/order_by.ex (it's taking more than 10s)
Compiling lib/ecto/uuid.ex (it's taking more than 10s)
Compiling lib/ecto/type.ex (it's taking more than 10s)
Compiling lib/ecto/association.ex (it's taking more than 10s)
Compiling lib/ecto/adapters/postgres/connection.ex (it's taking more than 10s)
Compiling lib/mix/tasks/ecto.gen.migration.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/join.ex (it's taking more than 10s)
Compiling lib/ecto/query/planner.ex (it's taking more than 10s)
Compiling lib/ecto/log_entry.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/select.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/distinct.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/limit_offset.ex (it's taking more than 10s)
Compiling lib/ecto/changeset.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder/group_by.ex (it's taking more than 10s)
Compiling lib/ecto/changeset/relation.ex (it's taking more than 10s)
Compiling lib/ecto/multi.ex (it's taking more than 10s)
Compiling lib/ecto.ex (it's taking more than 10s)
Compiling lib/ecto/query/builder.ex (it's taking more than 10s)
Compiling lib/ecto/adapters/postgres.ex (it's taking more than 10s)
Generated ecto app
==> phoenix_ecto
Compiling 4 files (.ex)
Generated phoenix_ecto app
==> phoenix_chat
Compiling 19 files (.ex)
Generated phoenix_chat app
08:49:48.868 [error] GenServer #PID<0.3296.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
** (Mix) The database for PhoenixChat.Repo couldn't be created: an exception was raised:
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Build failed !!!.
我想这是因为在构建服务器似乎是(localhost:5432)
,我不认为它起到很好凤凰这就通常在端口4000 See this answer for my coming to that conclusion.
如何解决这个?
我改变dev.ex有这样的配置:
config :phoenix_chat, PhoenixChat.Endpoint,
http: [port: {:system, "PORT"}],
那么我的任务设置为PORT=4000 mix test
,但我仍然得到同样的错误。
编辑:它不会出现在我的设置端口工作,因为错误仍然是:
PORT=4000 mix test
09:18:34.884 [error] GenServer #PID<0.183.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
** (Mix) The database for PhoenixChat.Repo couldn't be created: an exception was raised:
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Build failed !!!.
所以我觉得现在的解决方案可能是this。我对添加ssh密钥并不了解很多。
答
我的笔记本电脑崩溃,并在/usr/local/var/postgres
中留下了一个postmaster.pid
文件。
删除后,我的postgres开始工作很好。
如果你想检查postgres是否正常运行,你可以运行pq_ready
来获得输出。您应该得到:/tmp:5432 - accepting connections
- 根据您的配置,您的端口可能会有所不同。
玩得开心!
这对于Phoenix的HTTP端口没有问题。这是因为PostgreSQL没有在CI服务器的localhost:5432上运行。您可能需要在配置项的某处启用它,或者如果他们在另一个端口上运行PostgreSQL,则可以更改配置。 – Dogbert
@Dogbert会改变'dev.exs'的配置为'配置:phoenix_chat,PhoenixChat.Repo, 适配器:Ecto.Adapters.Postgres, 用户名: “Postgres的”, 密码: “Postgres的”, 数据库:“ phoenix_chat_dev“, 主机名:”localhost:5432“, pool_size:10'是否在正确的轨道? (它没有区别 - 同样的错误) - 更改是主机名 – BeniaminoBaggins
这应该是'hostname:“localhost”,port:5432,...'但5432是默认值,错误表示PostgreSQL不能运行在本地主机上:5432。您应该找出主机/端口PostgreSQL在CI服务器上运行,并且如果默认禁用它(例如在Travis中,您必须添加一个配置以启用PostgreSQL:https://docs.travis-ci.com/user/数据库的建立/#PostgreSQL的)。 – Dogbert