Windows 10 Windows上带有poolboy示例的Elixir postgrex在';模块DBConnection.Poolboy不可用';
我正在探索使用Elixir进行混合类型(CSV、JSON)的快速Postgres数据导入。作为Elixir的新手,我遵循youtube视频“使用Elixir和Postgrex快速导入和导出-Elixir Hex软件包展示”(Fast Import and Export with Elixir and Postgrex-Elixir Hex package showcase)中给出的示例。基本混合应用程序一直工作到引入Poolboy,即Postgrex使用单个连接成功地将记录加载到数据库中 当我尝试遵循Poolboy配置并通过运行 FastIoWithPostgrex.import(“./data\u with\u id.txt”) 在iex或命令行中,我遇到以下错误,我无法确定原因(用户名和密码已删除): 我在Windows 10上运行这个,通过本地SSH隧道连接到PostgreSQL 10.x服务器。以下是lib/fast\u io\u with\u postgrex.ex文件:Windows 10 Windows上带有poolboy示例的Elixir postgrex在';模块DBConnection.Poolboy不可用';,windows-10,elixir,postgrex,Windows 10,Elixir,Postgrex,我正在探索使用Elixir进行混合类型(CSV、JSON)的快速Postgres数据导入。作为Elixir的新手,我遵循youtube视频“使用Elixir和Postgrex快速导入和导出-Elixir Hex软件包展示”(Fast Import and Export with Elixir and Postgrex-Elixir Hex package showcase)中给出的示例。基本混合应用程序一直工作到引入Poolboy,即Postgrex使用单个连接成功地将记录加载到数据库中 当我尝
defmodule FastIoWithPostgrex do
@moduledoc """
Documentation for FastIoWithPostgrex.
"""
def import(filepath) do
{:ok, pid} = Postgrex.start_link(name: :pg,
pool: DBConnection.Poolboy,
pool_size: 4,
hostname: "localhost",
port: 9000,
username: "XXXX", password: "XXXX", database: "ASDDataAnalytics-DEV")
File.stream!(filepath)
|> Stream.map(fn line ->
[id_str, word] = line |> String.trim |> String.split("\t", trim: true, parts: 2)
{id, ""} = Integer.parse(id_str)
[id, word]
end)
|> Stream.chunk_every(10_000, 10_000, [])
|> Task.async_stream(fn word_rows ->
Enum.each(word_rows, fn word_sql_params ->
Postgrex.transaction(:pg, fn conn ->
IO.inspect Postgrex.query!(conn, "INSERT INTO asdda_dataload.words (id, word) VALUES ($1, $2)", word_sql_params)
# IO.inspect Postgrex.query!(pid, "INSERT INTO asdda_dataload.words (id, word) VALUES ($1, $2)", word_sql_params)
end , pool: DBConnection.Poolboy, pool_timeout: :infinity, timeout: :infinity)
end)
end, timeout: :infinity)
|> Stream.run
end # def import(file)
end
以下是mix.exs文件:
defmodule FastIoWithPostgrex.MixProject do
use Mix.Project
def project do
[
app: :fast_io_with_postgrex,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :poolboy, :connection]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git",
tag: "0.1.0"},
{:postgrex, "~>0.14.1"},
{:poolboy, "~>1.5.1"}
]
end
end
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
config :fast_io_with_postgrex, :postgrex,
database: "ASDDataAnalytics-DEV",
username: "XXXX",
password: "XXXX",
name: :pg,
pool: DBConnection.Poolboy,
pool_size: 4
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
#
# config :fast_io_with_postgrex, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:fast_io_with_postgrex, :key)
#
# You can also configure a 3rd-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
以下是config/config.exs文件:
defmodule FastIoWithPostgrex.MixProject do
use Mix.Project
def project do
[
app: :fast_io_with_postgrex,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :poolboy, :connection]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git",
tag: "0.1.0"},
{:postgrex, "~>0.14.1"},
{:poolboy, "~>1.5.1"}
]
end
end
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
config :fast_io_with_postgrex, :postgrex,
database: "ASDDataAnalytics-DEV",
username: "XXXX",
password: "XXXX",
name: :pg,
pool: DBConnection.Poolboy,
pool_size: 4
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
#
# config :fast_io_with_postgrex, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:fast_io_with_postgrex, :key)
#
# You can also configure a 3rd-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
如果您能协助查找此错误的原因,我们将不胜感激 我不想深入探讨这是如何不起作用的,但是这个例子有点老了,而且
poolboy 1.5.1
你用deps.get
拉的是。。这个例子使用了Elixir1.4
此外,如果您看到Postgrex的mix.exs
deps,您会注意到新安装的lib(1.14)依赖于elixir\u-exto/db\u连接
2.x
使用Postgres 1.13.x,这取决于{:db\u连接,“~>1.1”}
。所以我认为不兼容
我会使用您在示例代码mix.lock
文件中看到的libs版本,如果我想看到它工作的话,可以使用elixir版本
可能会先尝试将Postgrex版本降低到大约那个时间(可能介于0.12.2和示例的锁定版本之间)
此外,长生不老药的版本可能有一些发挥在这里,检查
你好
- 玩得开心
DBConnection.ConnectionPool
代替poolboy,使用最新的postgrex
和elixir版本,不确定性能差异,但您可以进行比较,只需执行以下操作:
在config/config.exs上(检查是否需要密码等)
在lib/fast\u io_中,用…..ex替换Postgrex.start\u链接(…
行,替换为:
{:ok, pid} = Application.get_env(:fast_io_with_postgrex, :postgrex)
|> Postgrex.start_link
这给了我:
mix run -e 'FastIoWithPostgrex.import("./data_with_ids.txt")'
1.76s user 0.69s system 106% cpu 2.294 total
在Postgrex 0.14.1和Elixir 1.7.3上,谢谢您,根据您的建议,我通过降低mix.exs文件中的依赖项版本并将依赖项添加到早期版本的db_connection中,获得了原始示例:
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
{:postgrex, "0.13.5"},
{:db_connection, "1.1.3"},
{:poolboy, "~>1.5.1"}
]
end
我还将尝试您的建议,在db_connection的更高版本中,更改代码以使用新的池管理器替换Poolboy,看看这是否也有效
我敢肯定,在架构更改方面有很多想法,但是我必须说,关于Poolboy为什么曾经如此流行的原因,几乎没有什么想法,但是在最新版本的db_connection中,它甚至不被支持作为连接类型