0

我在我的电脑上安装了 pgbouncer 1.5.4,这样我就可以以某种方式解决 postgre 问题中使用过多连接的问题。

我需要能够让很多人运行一个网页,该网页上有一个从 postgresql 数据库读取的地图应用程序,我注意到由于与 postgres 的默认连接有限,我需要 pgbouncer 来管理连接,但对于一些原因我不认为 pgbouncer 可以正常工作。

我在 pgbouncer.ini 文件中放入了我的数据库详细信息:manifold = host=127.0.0.1 port=6432 dbname=manifold user=postgrest password=password

我将我的 postgres 端口从 5432 更改为 6432,并将我的 pgbouncer 端口号更改为 5432。

似乎当我在 postgres 中检查连接活动时,连接一直在上升,而不是像我认为使用 pgbouncer 时应该下降的那样。

如果它达到 100 或超过 100 个连接,那么我的 web 地图应用程序开始出现粉红色的瓷砖,如果有人下车,那么地图就会显示出来。

任何帮助都会很好地尝试解决我遇到的这个问题。我已经为这个问题苦苦挣扎了好几个星期了。

当我在 pgbouncer admin 中键入 show config 时,这些设置是您要查找的设置,然后我得到了这个:

pgbouncer=# show config;
 key  |                value                                    | changeable
 job_name          | pgbouncer                                  | no
 service_name      | pgbouncer                                  | no
 conffile  | C:\ProgramFiles\PostgreSQL\share\pgbouncer.ini     | yes
 logfile   | C:\ProgramFiles\PostgreSQL\log\pgbouncer.log       | yes
 pidfile   | C:\ProgramFiles\PostgreSQL\log\pgbouncer.pid       | no
 listen_addr               | *                                  | no
 listen_port               | 5432                               | no
 listen_backlog            | 128                                | no
 auth_type                 | md5                                | yes
 auth_file | C:\ProgramFiles\PostgreSQL\etc\userlist.txt        | yes
 pool_mode                 | transaction                        | yes
 max_client_conn           | 400                                | yes
 default_pool_size         | 100                                | yes
 min_pool_size             | 0                                  | yes
 reserve_pool_size         | 0                                  | yes
 reserve_pool_timeout      | 5                                  | yes
 syslog                    | 0                                  | yes
 syslog_facility           | daemon                             | yes
 syslog_ident              | pgbouncer                          | yes
 autodb_idle_timeout       | 3600                               | yes
 server_reset_query        | DISCARD ALL                        | yes
 server_check_query        | select 1                           | yes
 server_check_delay        | 30                                 | yes
 query_timeout             | 0                                  | yes
 query_wait_timeout        | 0                                  | yes
 client_idle_timeout       | 0                                  | yes
 client_login_timeout      | 60                                 | yes
 idle_transaction_timeout  | 0                                  | yes
 server_lifetime           | 1200                               | yes
 server_idle_timeout       | 60                                 | yes
 server_connect_timeout    | 15                                 | yes
 server_login_retry        | 15                                 | yes
 server_round_robin        | 0                                  | yes
 suspend_timeout           | 10                                 | yes
 ignore_startup_parameters | application_name,extra_float_digits|yes
 disable_pqexec            | 0                                  | no
 dns_max_ttl               | 15                                 | yes
 dns_zone_check_period     | 0                                  | yes
 max_packet_size           | 2147483647                         | yes
 pkt_buf                   | 2048                               | no
 sbuf_loopcnt              | 5                                  | yes
 tcp_defer_accept          | 0                                  | yes
 tcp_socket_buffer         | 0                                  | yes
 tcp_keepalive             | 1                                  | yes
 tcp_keepcnt               | 0                                  | yes
 tcp_keepidle              | 0                                  | yes
 tcp_keepintvl             | 0                                  | yes
 verbose                   | 0                                  | yes
 admin_users               | postgres                           | yes
 stats_users               | postgres                           | yes
 stats_period              | 60                                 | yes
 log_connections           | 1                                  | yes
 log_disconnections        | 1                                  | yes
 log_pooler_errors         | 1                                  | yes
(54 rows)
4

1 回答 1

0

我猜 pgbouncer 不是您需要的解决方案,而是您的应用程序中存在连接泄漏。pgbouncer 将无法为您解决该问题,因此您需要在程序中修复它。我进一步打赌你会在没有 pgbouncer 的情况下看到完全相同的行为。

在这种情况下,无论有没有连接池,您都会用完连接。问题很可能是您的应用程序未按预期关闭连接。

于 2013-12-06T07:13:32.290 回答