简体   繁体   English

使用postgresql max_connections的Django CONN_MAX_AGE失败

[英]Django CONN_MAX_AGE failures with postgresql max_connections

Since I'm using CONN_MAX_AGE: 300 on my Django servers, request fail with errors because PostgreSQL exceeds the max_connections limit (which is 100 by default). 由于我在我的Django服务器上使用CONN_MAX_AGE: 300 ,因为PostgreSQL超出了max_connections限制(默认为100),因此请求失败并显示错误。

What is the best strategy to solve this? 解决这个问题的最佳策略是什么? I've tried using pgpool2, but this didn't solve the problem at all. 我尝试过使用pgpool2,但这根本没有解决问题。 Now the connections were queued by pgpool 2 (letting the sites wait forever, and cause a gateway timeout in the end). 现在连接被pgpool 2排队(让站点永远等待,并最终导致网关超时)。

I expected that using pgpool would reduce the number of idle connections going to PostgreSQL, not cause the same issue again. 我预计使用pgpool会减少转发到PostgreSQL的空闲连接数,不会再次导致同样的问题。

These are the settings I've used: 这些是我用过的设置:

pgpool2: pgpool2:

num_init_children = 32 # are so many workers needed? max_pool = 10 # default is 4

postgres: Postgres的:

max_connections = 400 # upgraded from default 100

uWSGI/Django: uWSGI / Django的:

  • all workers have 20 threads. 所有工人都有20个线程。
  • there are 10 workers in total with all sites combined. 共有10名工人,所有工地合计。

The VPS is an 8core Linode @ 2.27GHz with 2GB ram. VPS是8核Linode @ 2.27GHz,2GB内存。

I know this was a year ago, but were you using Gunicorn? 我知道这是一年前的事,但你使用的是Gunicorn吗? This pull request explains that asynchronous workers will not reuse connections and the issue you were/are having seemed to be solved by switching to sync workers. 这个拉取请求解释了异步工作者不会重用连接,并且您已经/正在遇到的问题似乎通过切换到同步工作者来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM