Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres - Phoenix/Elixir install errors

I am following this tutorial Elixir blog in 15 minutes using Phoenix framework - Step by Step

But I have a problem, which I have no idea how to fix. I think it has something to do with postgres.

I did:

$ mix ecto.create
$ mix ecto.migrate

    C:\Users\999\Documents\elixir_files\blog>mix ecto.create
** (RuntimeError) could not find executable `psql` in path, please guarantee it is available before running ecto commands
    lib/ecto/adapters/postgres.ex:105: Ecto.Adapters.Postgres.run_with_psql/2
    lib/ecto/adapters/postgres.ex:82: Ecto.Adapters.Postgres.storage_up/1
    lib/mix/tasks/ecto.create.ex:32: Mix.Tasks.Ecto.Create.run/1
    (mix) lib/mix/cli.ex:55: Mix.CLI.run_task/2
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (elixir) lib/code.ex:131: Code.eval_string/3


C:\Users\999\Documents\elixir_files\blog>mix ecto.migrate
[warning] the :size option when configuring Blog.Repo is deprecated, please use :pool_size instead
** (exit) exited in: GenServer.call(#PID<0.139.0>, {:query, "CREATE TABLE IF NOT EXISTS \"schema_migrations\" (\"version\" bigint PRIMARY KEY, \"inserted_at\" timestamp)", []}, :infinity)
    ** (EXIT) %Postgrex.Error{message: "tcp connect: econnrefused", postgres: nil}
    (elixir) lib/gen_server.ex:356: GenServer.call/3
    (postgrex) lib/postgrex/connection.ex:102: Postgrex.Connection.query/4
    (ecto) lib/ecto/adapters/postgres/connection.ex:31: Ecto.Adapters.Postgres.Connection.query/4
    (ecto) lib/ecto/adapters/sql.ex:242: Ecto.Adapters.SQL.query/7
    (ecto) lib/ecto/pool.ex:159: Ecto.Pool.do_run/4
    (ecto) lib/ecto/adapters/sql.ex:230: Ecto.Adapters.SQL.query/6
    (ecto) lib/ecto/adapters/sql.ex:208: Ecto.Adapters.SQL.query/5
    (ecto) lib/ecto/adapters/sql.ex:169: Ecto.Adapters.SQL.query!/5





    [warning] the :size option when configuring Blog.Repo is deprecated, please use :pool_size instead
[info] GET /posts
[debug] Processing by Blog.PostController.index/2
  Parameters: %{"format" => "html"}
  Pipelines: [:browser]
[error] GenServer #PID<0.280.0> terminating
Last message: {:"$gen_cast", :connect}
State: %{backend_key: nil, bootstrap: false, extensions: [{Ecto.Adapters.Postgres.DateTime, []}, {Postgrex.Extensions.JSON, [library: Poison]}, {Postgrex.Extensions.Binary, nil}, {Postgrex.Extensions.Text, nil}], listener_channels: #HashDict<[]>, listeners: #HashDict<[]>, opts: [hostname: "localhost", timeout: 5000, otp_app: :blog, repo: Blog.Repo, adapter: Ecto.Adapters.Postgres, username: "postgres", password: "postgres", database: "blog_dev", extensions: [{Ecto.Adapters.Postgres.DateTime, []}, {Postgrex.Extensions.JSON, [library: Poison]}], port: 5432], parameters: %{}, portal: nil, queue: {[%{command: {:connect, [hostname: "localhost", timeout: 5000, otp_app: :blog, repo: Blog.Repo, adapter: Ecto.Adapters.Postgres, username: "postgres", password: "postgres", database: "blog_dev", extensions: [{Ecto.Adapters.Postgres.DateTime, []}, {Postgrex.Extensions.JSON, [library: Poison]}], port: 5432]}, from: nil, reply: :no_reply}], []}, rows: [], sock: nil, state: :ready, statement: nil, tail: "", types: :types_removed, types_key: {'localhost', 5432, "blog_dev", [{Ecto.Adapters.Postgres.DateTime, []}, {Postgrex.Extensions.JSON, [library: Poison]}]}}
** (exit) %Postgrex.Error{message: "tcp connect: econnrefused", postgres: nil}
[info] Sent 500 in 1149ms
[error] #PID<0.278.0> running Blog.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /posts
** (exit) exited in: GenServer.call(#PID<0.280.0>, {:query, "SELECT p0.\"id\", p0.\"title\", p0.\"body\", p0.\"inserted_at\", p0.\"updated_at\" FROM \"posts\" AS p0", []}, 5000)
    ** (EXIT) %Postgrex.Error{message: "tcp connect: econnrefused", postgres: nil}
like image 236
codedownforwhat Avatar asked Aug 19 '15 07:08

codedownforwhat


2 Answers

You haven't specified what OS You are using, but it looks like the issue is that you don't have psql installed.

You can install it on ubuntu with:

sudo apt-get install postgresql

Or on OS X with:

brew install postgresql

If you are on something else then follow one of the install guides: https://wiki.postgresql.org/wiki/Detailed_installation_guides

The second error is a deprecation warning - in ecto v0.15.0 the :size parameter was changed to :pool_size - you should change this in config/dev.exs, config/test.exs and config/prod.exs:

# Configure your database
config :myapp_admin, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "my_app_test",
  pool_size: 10 # This used to be called size
like image 101
Gazler Avatar answered Oct 24 '22 09:10

Gazler


My simple fix was by installing pgAgent on top of postgre. Then appending the location C:\Program Files (x86)\pgAgent\bin to the variable value of PATH under the Environment Variables. More help here.

like image 38
Elvis Mugabi Avatar answered Oct 24 '22 07:10

Elvis Mugabi