我将通过bundle exec pumactl -F config/puma.rb phased-restart what works fine重新启动8名彪马工人.现在我发现越来越多的博士后错误:

PG::TRDeadlockDetected: ERROR:  deadlock detected

我发现大约有50个空闲的postgres进程正在运行:

postgres: myapp myapp_production 127.0.0.1(59950) idle
postgres: myapp myapp_production 127.0.0.1(60141) idle
...

当我跑bundle exec pumactl -F config/puma.rb stop的时候,它们就消失了.

如何更好地管理这些流程?谢谢你的帮助!


Update

我的美洲狮.rb:

environment 'production'
daemonize true

pidfile 'tmp/pids/puma.pid'
state_path 'tmp/pids/puma.state'

threads 0, 1
bind 'tcp://0.0.0.0:3010'

workers 8

quiet

推荐答案

I might have found a solution to my question:我在控制器(定制中间件)之外遇到了一些问题,这似乎是问题的根源.

如果在控制器之外有查询(ActiveMailer也可能导致此问题),请将代码放入ActiveRecord::Base.connection_pool.with_connection块中:

ActiveRecord::Base.connection_pool.with_connection do
  # code
end

ActiveRecord的with_connection方法生成从其池到块的数据库连接.当阻塞完成时,连接会自动判断回池中,避免连接泄漏.

我希望这对你们中的一些人有所帮助!

Postgresql相关问答推荐

PostgreSQL中btree_gist索引涉及integer和tstzrange属性查询计划的问题

计算两个子查询之间的差异

Haskell仆人发布FormUrlEncode for(向量字符串)字段

如何在PostgreSQL中正确删除数据库

Pogresql性能中的枚举与文本数据类型

为什么我的应用程序接收的是空值而不是布尔值?

在rust中,有什么方法可以从sqlx::query_with中返回rows_infected以及行本身?

PL/pgSQL中的IP递增函数

空表上的 Postgres 意外行为

EF Core添加迁移目标postgreeSQL返回无法加载类型'Microsoft.EntityFrameworkCore.Storage.IRelationalValueBufferFactoryFactory

MERGE 语句的锁定级别

postgresql 更新错误ERROR: invalid input syntax for type boolean:

OpenShift:如何从我的 PC 连接到 postgresql

Select 日期最高的行

datagrip 无法应用更改 此表是只读的

如何在 PostgreSQL 中插入多行

在 postgresql 中将 bool 转换为 int

PostgreSQL:将结果数据从 SQL 查询导出到 Excel/CSV

错误:ERROR: table name specified more than once

如何使用 postgresql 按计数排序?