MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 468
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Hi guys,
We are using asyncpg in a web application.
Upon starting the web server, we do the following two things:
1. `db = asyncpg.create_pool` to create the connection pool for the application's DB connections.
1. `conn = await db.pool.acquire(); await conn.add_listener('foo', _callback)` to register long-lived listeners to catch and handle `NOTIFY` events 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_closed` periodically - 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)?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando gli entry point asyncpg.create_pool, pool.acquire, add_listener e conn.is_closed descritti nel report, insieme al comportamento di PostgreSQL NOTIFY durante il riavvio di un server. Determina come dovrebbero comportarsi le connessioni del pool e i listener di lunga durata, quindi documenta il modo supportato per rilevare e recuperare le connessioni dei listener chiuse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- postgresql, python
- Ambito
- backend, databases
- Tipo di issue
- Documentazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100