MagicStack / MagicStack/asyncpg

Prepared Statement connection is active and wait for ClientRead.

未关闭
#1,276 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
468
PR 合并指标
30 天内没有已合并 PR

描述

Hi team,

Right now, asyncpg does prepared statements in two steps.

  1. Parse, Describe, Flush.
  2. Bind, Execute, Sync.

Two coroutines represent these two steps. In a highly concurrent setup, the wall-clock gap between these two steps can be large. Why is it causing a problem for me? Command Flush does not change the connection state, i.e., active. So I observe a lot of queries show up as

 wait_event_type | wait_event | state
-----------------+------------+--------
      Client    | ClientRead  | active

in pg_stat_activity. This causes a lot of unnecessary confusion for our database monitors/observability tools. The connection is essentially idle between these two steps, so I think it is better to report it as wait_event=ClientRead but state=idle? Meanwhile, the command Sync will change the connection state to idle, so after step 2, the connection becomes idle.

My ask is: could we use Sync instead of Flush in step 1?

Moreover, there could be more than one bind step, so the sequence could be

1. Parse, Describe, Flush.
2. Bind, Execute, Sync.
3. Bind, Execute, Sync.
...

In this case, the connection is active only between step 1 and step 2, but idle for all other step gaps. I kind of feel this behavior is inconsistent.
I might have neglected some basic design about PostgreSQL extended query. Hope to hear from you soon!

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中描述的 asyncpg prepared-statement 流程以及 PostgreSQL 的 extended-query 协议文档开始。确定更改 Flush/Sync 的时序是否能在包含多个 Bind/Execute 步骤的情况下保持正确性;完成的标准是 pg_stat_activity 一致地报告连接状态,同时不破坏 prepared statements。

由索引模型根据 Issue 内容生成。

评估

技术栈
postgresql, python
领域
databases
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。