Postgres - Phoenix / Elixir安装错误

时间:2015-08-19 07:27:13

标签: elixir phoenix-framework

我正在关注本教程Elixir blog in 15 minutes using Phoenix framework - Step by Step

但我有一个问题,我不知道如何解决。我认为它与postgres有关。

我做了:

$ 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}

2 个答案:

答案 0 :(得分:8)

您尚未指定正在使用的操作系统,但问题是您没有安装psql

您可以使用以下命令在ubuntu上安装它:

sudo apt-get install postgresql

或在OS X上使用:

brew install postgresql

如果您使用其他内容,请按照其中一个安装指南进行操作:https://wiki.postgresql.org/wiki/Detailed_installation_guides

第二个错误是弃用警告 - 在ecto v0.15.0 :size参数已更改为:pool_size - 您应该在config/dev.exsconfig/test.exs中更改此问题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

答案 1 :(得分:1)

我的简单修复方法是在pgAgent之上安装postgre。然后将位置{{1}}附加到环境变量下的PATH的变量值。更多帮助here