MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 469
- Merge trung bình
- 18 phút
- Pull request đã merge (30 ngày)
- 4
Mô tả
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)?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc xem xét các entry point asyncpg.create_pool, pool.acquire, add_listener và conn.is_closed được mô tả trong báo cáo, cùng với hành vi của PostgreSQL NOTIFY khi máy chủ khởi động lại. Xác định cách các kết nối trong pool và các listener hoạt động lâu dài được kỳ vọng sẽ hoạt động, đồng thời ghi lại cách được hỗ trợ để phát hiện và khôi phục các kết nối listener đã bị đóng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, python
- Lĩnh vực
- backend, databases
- Loại issue
- Tài liệu
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100