elixir - 无法运行 ecto.create,无法创建数据库:连接不可用并且请求已从队列中删除
问题描述
我正在按照此处设置 Phoenix 的指南进行操作
这是我的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".
解决方案
我的猜测是,通过指定“主机名”,您正在尝试通过 TCP/IP 进行连接,而在成功的连接示例中,您正在通过 UNIX 套接字进行连接。我认为您应该指定:
config :api, Api.Repo,
socket_dir: "/var/run/postgresql",
...
在 ecto 中通过 UNIX 套接字设置连接。
推荐阅读
- c - qsort 比较函数中的 const 限定符
- imagemagick - Magickick.NET-Q8-x64 版本 7.2.4.0 正在构建的处理器项目“MSIL”和处理器参考 Magick.NET-Q8-x64.dl、AMD64 之间不匹配
- angular - 如何使用可选整数 ngx-mask 屏蔽小数
- gzip - 如何用非常旧的 zlib 为 gzip 充气?
- ios - Swift & SwiftUI - 共享/操作扩展,将图像和视频保存到应用程序文档目录
- .net - 您可以创建的远程文件系统观察程序(.NET 库)实例的数量是否有限制?
- android - 如何在 React Native 中接收来自 Firebase 云消息传递的通知
- snowflake-cloud-data-platform - 如何从雪花中的json对象数组中选择数据
- flutter - 如何使用 Riverpod 减少复制的代码
- c# - 访问 Linq 的 Select 中的上一个项目