5

I'm running a build on a Buddy continuous integration server and it is bailing out with errors when executing mix test when it gets to the postgrex/ecto portion:

    ==> 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 !!!.

I think it's because the build server seems to be (localhost:5432) and I don't think it plays well with Phoenix which is usally on port 4000. See this answer for my coming to that conclusion.

What is the solution to this?

I changed dev.ex to have this config:

config :phoenix_chat, PhoenixChat.Endpoint,
  http: [port: {:system, "PORT"}],

then I set the task to PORT=4000 mix test but I still get the same errors.

EDIT: It doesn't appear my setting the port worked because the error is still:

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

So I now think the solution may be this. I don't know a lot about adding an ssh key.

Community
  • 1
  • 1
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
  • This is not a problem with the HTTP port for Phoenix. It's because PostgreSQL is not running on localhost:5432 in the CI server. You probably need to enable it somewhere in the CI or change the config if they run PostgreSQL on a different port. – Dogbert Feb 04 '17 at 09:17
  • @Dogbert Would changing the config in `dev.exs` to `config :phoenix_chat, PhoenixChat.Repo, adapter: Ecto.Adapters.Postgres, username: "postgres", password: "postgres", database: "phoenix_chat_dev", hostname: "localhost:5432", pool_size: 10` be on the right track? (It didn't make a difference - same error) - the change was the hostname – BeniaminoBaggins Feb 04 '17 at 09:43
  • That should be `hostname: "localhost", port: 5432, ...` but 5432 is the default and the error says PostgreSQL is _not_ running on localhost:5432. You should find out the host/port PostgreSQL is running on the CI server and if it's disabled by default (e.g. in Travis, you have to add a config to enable PostgreSQL: https://docs.travis-ci.com/user/database-setup/#PostgreSQL). – Dogbert Feb 04 '17 at 09:49

4 Answers4

15

My laptop crashed and left a postmaster.pid file lying in /usr/local/var/postgres.

After deleting this my postgres started working again nicely.

If you want to check if Postgres is running properly, you can run pg_isready to get the output. You should get: /tmp:5432 - accepting connections - your port may vary depending on your config.

Have fun!

dev
  • 413
  • 3
  • 18
Apie
  • 6,371
  • 7
  • 27
  • 25
4

Also try brew services stop postgres then brew services start postgres. It solved my issue

1

You might be seeing a conflict of libssl/libcrypto versions.

brew services start postgres logs gave me nada, but manually starting pg_ctl -D /usr/local/var/postgres start pointed at:

missing definition _RAND_cleanup in /.../openssl/lib/libcrypto.1.0.0.dylib

Have a shot at:

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
fkotsian
  • 194
  • 1
  • 6
1

Stop current running Postgres with:

pg_ctl stop

Restart Postgres with:

pg_ctl start
AR Rose
  • 361
  • 4
  • 17