如何停止Postgrex进程及其TypeServer进程?

问题描述 投票:0回答:1

我有数千个数据库。我想一个接一个地连接到每个连接,然后发出查询。我通过为每个人启动这样的Postgrex进程来做到这一点。

  {:ok, pid} =
    Postgrex.start_link(
      port: database.port,
      hostname: database.host,
      username: database.username,
      password: database.password,
      database: database.database_name
    )   

然后我发出Postgrex.query,然后像这样停止它

  :ok = GenServer.stop(pid, :normal)

一切似乎都工作正常,除了我最终以成千上万的Postgrex.TypeServer进程吞噬了似乎在相当长一段时间内未清理的内存。

是否有更好的方法来清理Postgrex进程,以便同时停止TypeServer

我在使用Postgrex 0.13.3。

编辑:

为了澄清一点,我想在每个Postgrex进程停止后清理TypeServer。在整个Enum.map完成之后清理所有TypeServer对我来说并不是那么有用,因为它会导致内存缓慢增长,然后急剧下降,而不是一条平坦的线。

Enum.map(databases, fn database ->
  {:ok, pid} = Postgrex.start_link(port: database.port, hostname: database.host, username: database.username, password: database.password, database: database.database_name)   
  Postgrex.query!(pid, "some query", [])
  :ok = GenServer.stop(pid, :normal)
  # something here to clean up the TypeServer
end)
postgresql elixir ecto postgrex
1个回答
0
投票

我直到最底层才开始挖掘它,但是Postgrex.TypeServerare managed by动态Postgrex.TypeSupervisor,也就是started with a hard-coded name

所以我的疯狂猜测是应该做的以下事情:

DynamicSupervisor.stop(Postgrex.TypeSupervisor)

此外,关闭Postgrex.App也应有帮助

Postgrex.App
© www.soinside.com 2019 - 2024. All rights reserved.