MagicStack / MagicStack/asyncpg

How are Postgres server restarts handled?

Đang mở
#421 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

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:

  1. db = asyncpg.create_pool to create the connection pool for the application's DB connections.
  2. 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)?

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.