MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 469
- 平均合并
- 18 分钟
- 30 天内合并 PR
- 4
描述
Hi guys,
We are using asyncpg in a web application.
Upon starting the web server, we do the following two things:
db = asyncpg.create_poolto create the connection pool for the application's DB connections.conn = await db.pool.acquire(); await conn.add_listener('foo', _callback)to register long-lived listeners to catch and handleNOTIFYevents from the DB.
Recently I restarted the Postgres server and noticed something interesting. First, connections to the DB using the db pool object saw no interruption and were still able to connect to the DB server despite it having a new PID (since the process had been restarted).
However, the conn the application relied on to receive async notifications from the server was dead/closed and so the application logic dependent upon receiving those notifications was not functioning. (This is how I reproduced this issue and discovered the cause to have been a PG server restart.)
- Why is the pool unaffected by restart? It makes sense the connection instance is dead since the socket is closed after restarting the server, but I'm a bit surprised the pool is not affected.
- I suppose the best strategy for checking for dead DB connections would be to simply check
conn.is_closedperiodically - or, is there some "on connection close" callback I can define to retry/reopen a connection (since obtaining new connections from the pool still works after restart)?
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看报告中描述的 asyncpg.create_pool、pool.acquire、add_listener 和 conn.is_closed 入口点,以及服务器重启期间 PostgreSQL NOTIFY 的行为。确定池化连接和长期运行的监听器应如何运行,并记录检测和恢复已关闭监听器连接的受支持方式。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- backend, databases
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100