首页 > 解决方案 > 调整 pgBouncer 配置设置的推荐公式是什么

问题描述

被抛入 DBA 的深处,我正试图绕着 pgBouncer 和 PostgreSQL 绕一圈。对于一些上下文,我们在 Google Cloud 上部署了一个带有 PostgreSQL 的 Moodle LMS。VM(16VCPU,64GB RAM)和数据库(8VCPU,32GB RAM)是分开的,到目前为止,我们已经能够为超过 5000 名学生提供服务而没有问题。

最近我们一直在平台上运行实时测验,我们开始收到这个错误:

[1-1] db=moodledb,user=postgres FATAL:  remaining connection slots are reserved for non-replication superuser connections"

我注意到我们的最大数据库连接已超过 Cloud SQL 默认的 600。是时候将应用程序置于维护模式了。经过一番挖掘,我意识到测验(100 个问题,10 页,每页 10 个问题)同时容纳 600 名学生。他们都同时登录系统,基本上导致系统崩溃。高峰在几秒钟内从 43 个连接增加到 600 个。

由于我们还有更多的考试要参加,最大的测验有最多 867 名学生,我很清楚我需要为此做准备。我们已经讨论了分散测验开始时间的可能性,以便在测验开始时我们的负载更少,但我需要为任何事情做好准备,因为我需要挽回面子。

因此,鉴于 PostgreSQL 如何产生新连接的性质,许多论坛都指向 pgBouncer 来管理连接池。我继续在 Moodle 和 PostgreSQL 之间设置一个实例。经过一些测试和配置测试,我能够停止max_connections上面的错误,但是 pgBouncer 给了我一组新的问题。ini以下是我文件中一些重要设置的摘录:

;; When server connection is released back to pool:
;;   session      - after client disconnects (default)
;;   transaction  - after transaction finishes
;;   statement    - after statement finishes
pool_mode = session

;; Total number of clients that can connect
;; We don't expect more than this number at any one time
max_client_conn = 5000

;; Default pool size.  20 is good number when transaction pooling
;; is in use, in session pooling it needs to be the number of
;; max clients you want to handle at any moment
;; And since Moodle LMS uses session as the pool type
;; I thought this value is the same as the postgresql max_connections
default_pool_size = 600

;; Minimum number of server connections to keep in pool.
;min_pool_size = 0

; how many additional connection to allow in case of trouble
;reserve_pool_size = 0

;; If a clients needs to wait more than this many seconds, use reserve
;; pool.
;reserve_pool_timeout = 5

;; How many total connections to a single database to allow from all
;; pools
;max_db_connections = 0
;max_user_connections = 0

;; If off, then server connections are reused in LIFO manner
;server_round_robin = 0

使用此配置,我在下面得到另一组错误:

ERROR accept() failed: Too many open files
closing because: client close request (age=160s)
closing because: client close request (age=90s)
WARNING C-0x55c61cc57780: (nodb)/(nouser)...pooler error: no more connections allowed (max_client_conn)
closing because: no more connections allowed (max_client_conn) (age=0s)

这些错误填满了日志。所以这就是问题所在。不幸的是,我对数据库管理很陌生,但我可以很容易地找到自己的方法。在我的配置中我需要查看什么可以让事情运行得更顺畅一些吗?我是否需要增加任何资源,例如数据库规范?是否有为 pgBouncer 提供这些配置值的公式?我将不胜感激任何帮助和指导。谢谢!

标签: databasepostgresqlgcloudpgbouncer

解决方案


推荐阅读