PGBouncer 不会重用连接,而是不断创建新的数据库连接,直到用完为止

时间:2021-06-22 06:49:34

标签: postgresql freeradius pgbouncer

我有几个客户端(FreeRadius 服务器)连接到单个中央 Pgbouncer。 当我使用其中一台 FreeRadius 服务器时,我可以看到 Pgbouncer 创建了多个数据库连接。

select *
from pg_stat_activity
where datname = 'master_db';

enter image description here

当我再次使用同一个 freeradius 服务器时,pgbouncer 不会重新使用现有的开放连接,而是不断创建新的连接。一旦我达到 30 多个连接,整个数据库就会停止。

PGbouncer.ini

server_idle_timeout = 10
max_client_conn = 500
default_pool_size = 30

postgresql.conf: (Postgres 13)

max_connections = 150

根据我的研究,Pgbouncer 应该为客户端分配一个数据库连接(从 default_pool_size),然后创建客户端需要的尽可能多的内部连接(最多为 max_client_conn)。

但我在这里观察到的情况正好相反。请问我遗漏了什么?

更新: Laurenz 建议的解决方案有效,但在幕后使用 asyncpg 时会引发此错误:

NOTE: pgbouncer with pool_mode set to "transaction" or "statement" does not support prepared statements properly. You have two options: * if you are using pgbouncer for connection pooling to a single server, switch to the connection pool functionality provided by asyncpg, it is a much better option for this purpose; * if you have no option of avoiding the use of pgbouncer, then you can set statement_cache_size to 0 when creating the asyncpg connection object.

0 个答案:

没有答案
相关问题