2017-02-04 189 views
2

我在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密鑰並不瞭解很多。

+0

這對於Phoenix的HTTP端口沒有問題。這是因爲PostgreSQL沒有在CI服務器的localhost:5432上運行。您可能需要在配置項的某處啓用它,或者如果他們在另一個端口上運行PostgreSQL,則可以更改配置。 – Dogbert

+0

@Dogbert會改變'dev.exs'的配置爲'配置:phoenix_chat,PhoenixChat.Repo, 適配器:Ecto.Adapters.Postgres, 用戶名: 「Postgres的」, 密碼: 「Postgres的」, 數據庫:「 phoenix_chat_dev「, 主機名:」localhost:5432「, pool_size:10'是否在正確的軌道? (它沒有區別 - 同樣的錯誤) - 更改是主機名 – BeniaminoBaggins

+0

這應該是'hostname:「localhost」,port:5432,...'但5432是默認值,錯誤表示PostgreSQL不能運行在本地主機上:5432。您應該找出主機/端口PostgreSQL在CI服務器上運行,並且如果默認禁用它(例如在Travis中,您必須添加一個配置以啓用PostgreSQL:https://docs.travis-ci.com/user/數據庫的建立/#PostgreSQL的)。 – Dogbert

回答

0

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

刪除後,我的postgres開始工作很好。

如果你想檢查postgres是否正常運行,你可以運行pq_ready來獲得輸出。您應該得到:/tmp:5432 - accepting connections - 根據您的配置,您的端口可能會有所不同。

玩得開心!

相關問題