无法运行ecto.create,无法创建数据库:连接不可用,请求已从队列中删除

时间:2019-07-02 06:42:43

标签: elixir ecto phoenix

我正在遵循设置Phoenix here

的指南

这是我的dev.exs文件:

use Mix.Config

# Configure your database
config :api, Api.Repo,
  username: <username>,
  password: <password>,
  database: <dbname>,
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10,
  timeout: 120_000,
  queue_target: 5000,
  queue_interval: 100_000

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :api, ApiWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

我跑步时

ecto.create

我收到以下错误:

The database for Api.Repo couldn't be created: connection not available and request was dropped from queue after 2994ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information

据我所知,我已经在使用queue_target和queue_interval。我在做什么错了?

我的数据库正在运行。我可以跑步

psql -U <username>

并访问psql控制台。

postgres-# \conninfo
You are connected to database postgres as user <username> via socket in "/var/run/postgresql" at port "5432".

1 个答案:

答案 0 :(得分:0)

我的猜测是,通过指定“主机名”,您试图通过TCP / IP进行连接,而在成功的连接示例中,您是通过UNIX套接字进行连接。我认为您应该指定:

config :api, Api.Repo,
  socket_dir: "/var/run/postgresql",
  ...

通过ecto中的UNIX套接字设置连接。