DBConnection.ConnectionError)tcp connect(localhost:5432):连接被拒绝 - :econnrefused

时间:2017-02-04 09:12:56

标签: postgresql phoenix-framework ecto

我在Buddy持续集成服务器上运行构建,当它到达postgrex / ecto部分时执行mix test时出现错误。

    ==> 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密钥。

3 个答案:

答案 0 :(得分:2)

我的笔记本电脑崩溃,并在postmaster.pid内留下/usr/local/var/postgres个文件。

删除后,我的postgres开始很好地工作了。

如果要检查postgres是否正常运行,可以运行pq_ready来获取输出。您应该得到:/tmp:5432 - accepting connections - 您的端口可能会因您的配置而异。

玩得开心!

答案 1 :(得分:0)

您可能会看到libssl / libcrypto版本的冲突。

brew services start postgres日志给了我nada,但手动启动pg_ctl -D /usr/local/var/postgres start指向:

/.../openssl/lib/libcrypto.1.0.0.dylib中缺少定义_RAND_cleanup

拍摄地点:

brew tap-new $USER/old-openssl
brew extract --version=1.0.2t openssl $USER/old-openssl
brew install openssl@1.0.2t

# and then either brew link openssl@1.0.2t or symlink the required files to current openssl
ln -s /usr/local/Cellar/openssl/openssl@1.0.2t/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/Cellar/openssl/openssl@1.0.2t/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

答案 2 :(得分:0)

也试试 brew services stop postgres 然后 brew services start postgres。它解决了我的问题