簡體   English   中英

DBConnection.ConnectionError)tcp 連接(本地主機:5432):連接被拒絕-:econnrefused

[英]DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

我正在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 上的 Phoenix 配合得不好。請參閱此答案以得出該結論。

解決方案是什么?

我將 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 !!!.

所以我現在認為解決方案可能是這樣的。 我不太了解添加 ssh 密鑰。

我的筆記本電腦崩潰了,並在/usr/local/var/postgres留下了一個postmaster.pid文件。

刪除后,我的 postgres 又開始正常工作了。

如果你想檢查 Postgres 是否正常運行,你可以運行pg_isready來獲取輸出。 您應該得到: /tmp:5432 - accepting connections - 您的端口可能因您的配置而異。

玩得開心!

也嘗試brew services stop postgres然后brew services start postgres 它解決了我的問題

您可能會看到 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

停止當前正在運行的Postgres

pg_ctl stop

使用以下命令重新啟動Postgres

pg_ctl start

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM