MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 469
- 平均マージ
- 18分
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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